From cf4fe50dd970eb9edc4a4abb4225a7f28ef14cc8 Mon Sep 17 00:00:00 2001 From: ZL114514 Date: Sat, 4 Oct 2025 11:51:10 +0800 Subject: [PATCH] feat-add freeform support --- .../xiaomi/push/sdk/MyPushMessageHandler.java | 16 +++- .../com/xiaomi/xmsf/utils/ConfigCenter.java | 6 +- .../main/AdvancedSettingsPage.kt | 7 ++ push/src/main/res/values-zh/strings.xml | 6 +- push/src/main/res/values/strings.xml | 86 ++++++++++++++----- .../main/res/xml/fragmented_preferences.xml | 8 +- 6 files changed, 100 insertions(+), 29 deletions(-) diff --git a/push/src/main/java/com/xiaomi/push/sdk/MyPushMessageHandler.java b/push/src/main/java/com/xiaomi/push/sdk/MyPushMessageHandler.java index 26803245..adaf8c93 100644 --- a/push/src/main/java/com/xiaomi/push/sdk/MyPushMessageHandler.java +++ b/push/src/main/java/com/xiaomi/push/sdk/MyPushMessageHandler.java @@ -3,6 +3,7 @@ import static android.os.Build.VERSION.SDK_INT; import static android.os.Build.VERSION_CODES.P; +import android.app.ActivityOptions; import android.app.IntentService; import android.content.ComponentName; import android.content.Context; @@ -226,8 +227,12 @@ private static long pullUpApp(Context context, String targetPackage, XmPushActio throw new RuntimeException("can not get default activity for " + targetPackage); } else { intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); - - context.startActivity(intent); + ActivityOptions activityOptions = ActivityOptions.makeBasic(); + Bundle startBundle = activityOptions.toBundle(); + if (ConfigCenter.getInstance().isViaFreeform(context)) { + startBundle.putInt("android.activity.windowingMode", 5); + } + context.startActivity(intent, startBundle); logger.d(packageInfo(targetPackage, "start activity")); } @@ -244,7 +249,12 @@ private static long pullUpApp(Context context, String targetPackage, XmPushActio if (i == (APP_CHECK_FRONT_MAX_RETRY / 2)) { intent = getJumpIntentFromPkg(context, targetPackage); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); - context.startActivity(intent); + ActivityOptions activityOptions = ActivityOptions.makeBasic(); + Bundle startBundle = activityOptions.toBundle(); + if (ConfigCenter.getInstance().isViaFreeform(context)) { + startBundle.putInt("android.activity.windowingMode", 5); + } + context.startActivity(intent, startBundle); } } diff --git a/push/src/main/java/com/xiaomi/xmsf/utils/ConfigCenter.java b/push/src/main/java/com/xiaomi/xmsf/utils/ConfigCenter.java index e485f327..1b0012c6 100644 --- a/push/src/main/java/com/xiaomi/xmsf/utils/ConfigCenter.java +++ b/push/src/main/java/com/xiaomi/xmsf/utils/ConfigCenter.java @@ -40,7 +40,11 @@ public ConfigCenter() { public static SharedPreferences getSharedPreferences(Context context) { return context.getSharedPreferences(BuildConfig.APPLICATION_ID + "_preferences", Context.MODE_MULTI_PROCESS); } - + + public boolean isViaFreeform(Context ctx) { + return getSharedPreferences(ctx).getBoolean("ViaFreeform", false); + } + public boolean isNotificationOnRegister(Context ctx) { return getSharedPreferences(ctx).getBoolean("NotificationOnRegister", false); } diff --git a/push/src/main/java/top/trumeet/mipushframework/main/AdvancedSettingsPage.kt b/push/src/main/java/top/trumeet/mipushframework/main/AdvancedSettingsPage.kt index 8319ba8b..69b0612f 100644 --- a/push/src/main/java/top/trumeet/mipushframework/main/AdvancedSettingsPage.kt +++ b/push/src/main/java/top/trumeet/mipushframework/main/AdvancedSettingsPage.kt @@ -152,6 +152,13 @@ private fun ExperimentalBlock() { iceBoxGranted = !iceBoxGranted setIceBoxSupported(context, iceBoxGranted) } + + SettingsItem( + title = stringResource(R.string.settings_via_freeform), + summary = stringResource(R.string.settings_via_freeform_summary), + key = "ViaFreeform", + defaultValue = false, + ) } } diff --git a/push/src/main/res/values-zh/strings.xml b/push/src/main/res/values-zh/strings.xml index e2e3ee59..2a2944cb 100644 --- a/push/src/main/res/values-zh/strings.xml +++ b/push/src/main/res/values-zh/strings.xml @@ -88,7 +88,11 @@ 点击通知栏时自动解冻冻结的App。 需要安装的冰箱版本号 >= 3.6.0 - + + 以自由形式 (小窗) 打开通知 + 暂时只支持系统级小窗( AOSP原生、桌面模式、Sun OS或Rising OS) 米窗及其 forks 由于是以广播形式打开,暂不支持 + + 已赋权冰箱自动解冻 未赋权冰箱自动解冻 diff --git a/push/src/main/res/values/strings.xml b/push/src/main/res/values/strings.xml index c6876317..fdacea56 100644 --- a/push/src/main/res/values/strings.xml +++ b/push/src/main/res/values/strings.xml @@ -8,7 +8,7 @@ Reject - + Push service failed. Please try to disable the wake-up interception for the manager application, turn off some optimization feature of ROMs. No logs yet. Cannot share logs:%1$s @@ -71,10 +71,14 @@ IceBox not installed Auto enable app by IceBox Auto enable app by IceBox SDK. - require IceBox( version > 3.6.0) installed + require IceBox( version > 3.6.0) installed IceBox permission granted IceBox permission not granted + Open Notifications via Freeform + Only support framework freeform (like AOSP original Freeform, AOSP desktop mode, Sun OS, Rising OS etc. ). + MiFreeform with its forks won\'t work due to it\'s board cast mode. + Simulate received a message Tap to send a simulated test message. @@ -90,7 +94,6 @@ show a foreground notification to keep alive, you can hide it by disable notification channel - MiPush Framework Enable @@ -110,7 +113,9 @@ About - MiPushFramework]]> + + MiPushFramework]]> + Connecting @@ -118,10 +123,14 @@ You have disabled the Push service to run in the background, it will not be able to push in the background, you %1$s, then tap Next button. Need to use Root access to solve. (we will handle it automatically) - App Ops tool, and grant the Run in the background or wake up permissions ]]> - + App Ops tool, and grant the Run in the background or wake up permissions ]]> + + + Run in the background or wake up permissions. - ]]> + ]]> + Usage stats You need to grant \"Usage stats\" permission or you will not be able to receive notifications. @@ -234,12 +243,32 @@ Please grant the Run in the background or wake up permissions. not registered %1$s apps without MiPush SDK - 应用程式注册问题解决方案 and [帮助] 应用注册问题. - ]]> - Magisk global-level module or Magisk apps-level module to increase success. See also: 应用程式注册问题解决方案 and [帮助] 应用注册问题. - ]]> + + +应用程式注册问题解决方案 + and +[帮助] 应用注册问题 +. + ]]> + + + +Magisk global-level module + or +Magisk apps-level module + to increase success. See also: +应用程式注册问题解决方案 + and +[帮助] 应用注册问题 +. + ]]> + Unregistered Group all notifications for the same session @@ -249,23 +278,34 @@ Registration is determined and initiated by the application and generally begins Feedback Join Telegram group Join QQ channel - + + + Contact us Frequently asked questions Abnormal registration - [帮助] 注册异常. - ]]> - - - + + +[帮助] 注册异常 +. + ]]> + + + + 0 2 3 - + help_article_can_not_receive_push|can_not_receive_push help_article_register_error|register_error help_article_no_register|no_register @@ -280,9 +320,9 @@ This could be the application doing a reverse registration, or the registration clear all notifications of session when the notification of session was clicked show \"pass through\" message as notification Search - last receive: + last receive: Services Not Found Try to force register all applications - \ No newline at end of file + diff --git a/push/src/main/res/xml/fragmented_preferences.xml b/push/src/main/res/xml/fragmented_preferences.xml index eba3152f..0b4629d2 100644 --- a/push/src/main/res/xml/fragmented_preferences.xml +++ b/push/src/main/res/xml/fragmented_preferences.xml @@ -31,7 +31,13 @@ android:key="IceboxSupported" android:title="@string/settings_icebox_permission" android:summary="@string/settings_icebox_permission_summary" /> - + + +