From 6c991fec07234052ef4a8ad94ea6b072fbe7b7f8 Mon Sep 17 00:00:00 2001 From: Tornaco Date: Sun, 16 Jun 2024 11:28:29 +0800 Subject: [PATCH] Integrate shizuku[3] --- .../main/res/values-zh-rCN/app_strings.xml | 4 + .../res/src/main/res/values/app_strings.xml | 4 + android/app/src/main/AndroidManifest.xml | 7 +- .../fortuitous/thanos/main/ChooserActivity.kt | 104 ++++++++++++++++ .../now/fortuitous/thanos/main/NavActivity.kt | 101 +++++++++++++++- .../now/fortuitous/thanos/main/NavScreen.kt | 2 +- .../fortuitous/thanos/main/ShortcutInit.kt | 112 ++++++++++++++++++ .../fortuitous/thanos/pref/AppPreference.java | 17 ++- android/app/src/main/res/xml/shortcuts.xml | 30 ----- android/app/src/row/res/xml/shortcuts.xml | 30 ----- android/internal/Thanox-Internal | 2 +- 11 files changed, 337 insertions(+), 76 deletions(-) create mode 100644 android/android_framework/res/src/main/res/values-zh-rCN/app_strings.xml create mode 100644 android/android_framework/res/src/main/res/values/app_strings.xml create mode 100644 android/app/src/main/java/now/fortuitous/thanos/main/ChooserActivity.kt create mode 100644 android/app/src/main/java/now/fortuitous/thanos/main/ShortcutInit.kt delete mode 100755 android/app/src/main/res/xml/shortcuts.xml delete mode 100755 android/app/src/row/res/xml/shortcuts.xml diff --git a/android/android_framework/res/src/main/res/values-zh-rCN/app_strings.xml b/android/android_framework/res/src/main/res/values-zh-rCN/app_strings.xml new file mode 100644 index 000000000..4d1499155 --- /dev/null +++ b/android/android_framework/res/src/main/res/values-zh-rCN/app_strings.xml @@ -0,0 +1,4 @@ + + + 你想用哪种激活方式使用Thanox? + \ No newline at end of file diff --git a/android/android_framework/res/src/main/res/values/app_strings.xml b/android/android_framework/res/src/main/res/values/app_strings.xml new file mode 100644 index 000000000..874903c7c --- /dev/null +++ b/android/android_framework/res/src/main/res/values/app_strings.xml @@ -0,0 +1,4 @@ + + + Which activation method do you prefer? + \ No newline at end of file diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 8fdf2f9a6..5323b10c1 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -31,10 +31,6 @@ - - + { + Thanox() + } + + "thanos" -> { + Thanos() + } + + else -> { + ChooserActivity.Starter.start(thisActivity()) + finish() + } + } + } + + @Composable + private fun Thanox() { + // Block + if (blockOnCreate(thisActivity())) { finish() return } + LaunchedEffect(Unit) { + ShortcutInit(thisActivity()).initOnBootThanox() + } + + LaunchedEffect(Unit) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { + thisActivity().shortcutManager.disableShortcuts( + listOf( + "thanos_shortcut_smart_freeze", + "thanos_shortcut_process_manage" + ) + ) + thisActivity().shortcutManager.enableShortcuts( + listOf( + "shortcut_smart_freeze", + "shortcut_process_manage" + ) + ) + } + } + NavScreen() } + + @Composable + private fun Thanos() { + LaunchedEffect(Unit) { + ShortcutInit(thisActivity()).initOnBootThanos() + } + + ThanosApp { + ThanosTheme { + var privacyAgreementAccept by remember { + mutableStateOf(false) + } + LaunchedEffect(Unit) { + privacyAgreementAccept = + PreferenceManager.getDefaultSharedPreferences(thisActivity()) + .getBoolean(privacyAgreementKey, false) + } + + if (!privacyAgreementAccept) { + PrivacyStatementDialog(onDismissRequest = { + PreferenceManager.getDefaultSharedPreferences(thisActivity()).edit() + .putBoolean(privacyAgreementKey, true).apply() + privacyAgreementAccept = true + }) + } + + + MainGraph() + } + } + } } \ No newline at end of file diff --git a/android/app/src/main/java/now/fortuitous/thanos/main/NavScreen.kt b/android/app/src/main/java/now/fortuitous/thanos/main/NavScreen.kt index 59f7e41f3..c53e41ca6 100644 --- a/android/app/src/main/java/now/fortuitous/thanos/main/NavScreen.kt +++ b/android/app/src/main/java/now/fortuitous/thanos/main/NavScreen.kt @@ -528,7 +528,7 @@ private fun FrameworkErrorDialog( } @Composable -private fun PrivacyStatementDialog( +fun PrivacyStatementDialog( onDismissRequest: () -> Unit, ) { val context = LocalContext.current diff --git a/android/app/src/main/java/now/fortuitous/thanos/main/ShortcutInit.kt b/android/app/src/main/java/now/fortuitous/thanos/main/ShortcutInit.kt new file mode 100644 index 000000000..30ee4f359 --- /dev/null +++ b/android/app/src/main/java/now/fortuitous/thanos/main/ShortcutInit.kt @@ -0,0 +1,112 @@ +package now.fortuitous.thanos.main + +import android.content.Context +import android.content.Intent +import androidx.core.content.pm.ShortcutInfoCompat +import androidx.core.content.pm.ShortcutManagerCompat +import androidx.core.graphics.drawable.IconCompat +import androidx.core.net.toUri +import github.tornaco.android.thanos.R +import now.fortuitous.thanos.power.SmartFreezeActivity +import now.fortuitous.thanos.process.v2.ProcessManageActivityV2Delegate +import tornaco.apps.thanox.ThanosMainActivity + +class ShortcutInit(val context: Context) { + companion object { + const val ID_THANOX_PM = "thanox_pm" + const val ID_THANOX_SF = "thanox_sf" + const val ID_THANOS_PM = "thanos_pm" + const val ID_THANOS_SF = "thanos_sf" + } + + private fun installForThanox() { + if (!hasDynamicShortcut(ID_THANOX_SF)) { + addDynamicShortcut( + ID_THANOX_SF, + SmartFreezeActivity::class.java, + R.drawable.shortcut_smart_freeze, + context.getString(R.string.feature_title_smart_app_freeze) + ) + } + if (!hasDynamicShortcut(ID_THANOX_PM)) { + addDynamicShortcut( + ID_THANOX_PM, + ProcessManageActivityV2Delegate::class.java, + R.drawable.ic_shortcut_process_manage, + context.getString(R.string.feature_title_process_manage) + ) + } + } + + private fun installForThanos() { + if (!hasDynamicShortcut(ID_THANOS_SF)) { + addDynamicShortcut( + ID_THANOS_SF, + ThanosMainActivity::class.java, + R.drawable.shortcut_smart_freeze, + context.getString(R.string.feature_title_smart_app_freeze), + "SF" + ) + } + + if (!hasDynamicShortcut(ID_THANOS_PM)) { + addDynamicShortcut( + ID_THANOS_PM, + ThanosMainActivity::class.java, + R.drawable.ic_shortcut_process_manage, + context.getString(R.string.feature_title_process_manage), + "PM" + ) + } + } + + fun initOnBootThanos() { + installForThanos() + removeDynamicShortcuts(listOf(ID_THANOX_PM, ID_THANOX_SF)) + } + + fun initOnBootThanox() { + installForThanox() + removeDynamicShortcuts(listOf(ID_THANOS_PM, ID_THANOS_SF)) + } + + fun addDynamicShortcut( + id: String, + clazz: Class<*>, + iconRes: Int, + title: String, + data: String? = null + ): Boolean { + val shortcutInfoIntent = Intent(context, clazz).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + data?.let { + setData(it.toUri()) + } + } + shortcutInfoIntent.action = Intent.ACTION_VIEW + + val icon = IconCompat.createWithResource( + context, + iconRes + ) + + val shortcutInfo = ShortcutInfoCompat.Builder(context, id) + .setShortLabel(title) + .setLongLabel(title) + .setIcon(icon) + .setIntent(shortcutInfoIntent) + .build() + + return ShortcutManagerCompat.pushDynamicShortcut(context, shortcutInfo) + } + + fun removeDynamicShortcuts(id: List) { + ShortcutManagerCompat.removeDynamicShortcuts(context, id) + } + + fun hasDynamicShortcut(id: String): Boolean { + return ShortcutManagerCompat.getDynamicShortcuts(context).any { + it.id == id + } + } +} \ No newline at end of file diff --git a/android/app/src/main/java/now/fortuitous/thanos/pref/AppPreference.java b/android/app/src/main/java/now/fortuitous/thanos/pref/AppPreference.java index 7eb740e10..555b57408 100644 --- a/android/app/src/main/java/now/fortuitous/thanos/pref/AppPreference.java +++ b/android/app/src/main/java/now/fortuitous/thanos/pref/AppPreference.java @@ -37,14 +37,13 @@ public class AppPreference { private static final String PREF_KEY_CURRENT_TIP_INDEX = "PREF_KEY_CURRENT_TIP_INDEX"; private static final String PREF_KEY_PKG_SET_SORT_PREFIX = "PREF_KEY_PKG_SORT_"; private static final String PREF_KEY_FEATURE_FLAG_ = "PREF_KEY_FEATURE_FLAG_"; - + private static final String PREF_KEY_APP_SX = "PREF_KEY_APP_SX"; public static boolean isFirstRun(Context context) { return PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(PREF_KEY_FIRST_RUN, true); } - public static void setFirstRun(Context context, boolean first) { PreferenceManager.getDefaultSharedPreferences(context) .edit() @@ -52,13 +51,23 @@ public static void setFirstRun(Context context, boolean first) { .apply(); } + public static String getAppType(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context) + .getString(PREF_KEY_APP_SX, null); + } + + public static void setAppType(Context context, String first) { + PreferenceManager.getDefaultSharedPreferences(context) + .edit() + .putString(PREF_KEY_APP_SX, first) + .apply(); + } public static boolean isFeatureNoticeAccepted(Context context, String feature) { return PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(feature, false); } - public static void setFeatureNoticeAccepted(Context context, String feature, boolean first) { PreferenceManager.getDefaultSharedPreferences(context) .edit() @@ -66,7 +75,6 @@ public static void setFeatureNoticeAccepted(Context context, String feature, boo .apply(); } - public static boolean hasOnBoarding(Context context) { return PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(PREF_KEY_ON_BOARDING, false); @@ -87,7 +95,6 @@ public static boolean isProcessManagerV2Enabled(Context context) { .getBoolean(PREF_KEY_PROCESS_MANAGE_UI_V2, false); } - public static void setProcessManagerV2Enabled(Context context, boolean value) { PreferenceManager.getDefaultSharedPreferences(context) .edit() diff --git a/android/app/src/main/res/xml/shortcuts.xml b/android/app/src/main/res/xml/shortcuts.xml deleted file mode 100755 index e7cd559dd..000000000 --- a/android/app/src/main/res/xml/shortcuts.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/android/app/src/row/res/xml/shortcuts.xml b/android/app/src/row/res/xml/shortcuts.xml deleted file mode 100755 index 4e20250fa..000000000 --- a/android/app/src/row/res/xml/shortcuts.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/android/internal/Thanox-Internal b/android/internal/Thanox-Internal index 7801aede5..98605fa60 160000 --- a/android/internal/Thanox-Internal +++ b/android/internal/Thanox-Internal @@ -1 +1 @@ -Subproject commit 7801aede5011053381aa684e8b6f940fd95464ae +Subproject commit 98605fa60b3e983468374d92d571a7e91e8e80e3