From ff292e38e49f464bc6bf5bfcd7f94dfbc8a98ed5 Mon Sep 17 00:00:00 2001 From: Tornaco Date: Mon, 25 Sep 2023 15:43:53 +0800 Subject: [PATCH] [app] add fallback IThanos --- .../thanos/core/app/ThanosManager.java | 153 +++++++++++++++++- .../android/thanos/main/DialogUtils.java | 27 ++++ .../android/thanos/main/NavViewModel2.kt | 4 + .../thanos/main/PrebuiltFeatureLauncher.kt | 100 ++++++++++-- 4 files changed, 272 insertions(+), 12 deletions(-) create mode 100644 android/app/src/main/java/github/tornaco/android/thanos/main/DialogUtils.java diff --git a/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/ThanosManager.java b/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/ThanosManager.java index 15451f657..098ea10be 100644 --- a/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/ThanosManager.java +++ b/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/ThanosManager.java @@ -2,34 +2,57 @@ import android.content.Context; import android.content.IntentFilter; +import android.os.RemoteException; import com.elvishew.xlog.XLog; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import github.tornaco.android.thanos.core.IPluginLogger; import github.tornaco.android.thanos.core.IThanos; import github.tornaco.android.thanos.core.app.activity.ActivityStackSupervisor; +import github.tornaco.android.thanos.core.app.activity.IActivityStackSupervisor; import github.tornaco.android.thanos.core.app.event.IEventSubscriber; +import github.tornaco.android.thanos.core.app.infinite.InfiniteZ; import github.tornaco.android.thanos.core.app.infinite.InfiniteZManager; +import github.tornaco.android.thanos.core.app.usage.IUsageStatsManager; import github.tornaco.android.thanos.core.app.usage.UsageStatsManager; import github.tornaco.android.thanos.core.audio.AudioManager; +import github.tornaco.android.thanos.core.audio.IAudioManager; import github.tornaco.android.thanos.core.backup.BackupAgent; +import github.tornaco.android.thanos.core.backup.IBackupAgent; +import github.tornaco.android.thanos.core.input.IInputManager; import github.tornaco.android.thanos.core.input.InputManager; +import github.tornaco.android.thanos.core.n.INotificationManager; import github.tornaco.android.thanos.core.n.NotificationManager; +import github.tornaco.android.thanos.core.net.INetworkManager; import github.tornaco.android.thanos.core.net.NetworkManager; +import github.tornaco.android.thanos.core.ops.IOps; import github.tornaco.android.thanos.core.ops.OpsManager; +import github.tornaco.android.thanos.core.os.IServiceManager; import github.tornaco.android.thanos.core.os.ServiceManager; +import github.tornaco.android.thanos.core.plus.IRS; import github.tornaco.android.thanos.core.plus.RSManager; +import github.tornaco.android.thanos.core.pm.IPkgManager; import github.tornaco.android.thanos.core.pm.PackageManager; +import github.tornaco.android.thanos.core.power.IPowerManager; import github.tornaco.android.thanos.core.power.PowerManager; +import github.tornaco.android.thanos.core.pref.IPrefManager; import github.tornaco.android.thanos.core.pref.PrefManager; +import github.tornaco.android.thanos.core.profile.IProfileManager; import github.tornaco.android.thanos.core.profile.ProfileManager; +import github.tornaco.android.thanos.core.push.IPushManager; import github.tornaco.android.thanos.core.push.PushManager; +import github.tornaco.android.thanos.core.push.wechat.IPushDelegateManager; import github.tornaco.android.thanos.core.push.wechat.PushDelegateManager; +import github.tornaco.android.thanos.core.secure.IPrivacyManager; import github.tornaco.android.thanos.core.secure.PrivacyManager; import github.tornaco.android.thanos.core.secure.ops.AppOpsManager; +import github.tornaco.android.thanos.core.secure.ops.IAppOpsService; +import github.tornaco.android.thanos.core.wm.IWindowManager; import github.tornaco.android.thanos.core.wm.WindowManager; import lombok.Getter; import lombok.SneakyThrows; @@ -39,6 +62,123 @@ public class ThanosManager { public static final String PROXIED_ANDROID_SERVICE_NAME = Context.DROPBOX_SERVICE; public static final int IPC_TRANS_CODE_THANOS_SERVER = "github.tornaco.android.thanos.core.IPC_TRANS_CODE_THANOS_SERVER".hashCode(); + private static final IThanos sDefaultFallbackService = new IThanos.Default() { + @Override + public IAppOpsService getAppOpsService() throws RemoteException { + return new IAppOpsService.Default(); + } + + @Override + public IServiceManager getServiceManager() throws RemoteException { + return new IServiceManager.Default(); + } + + @Override + public IActivityManager getActivityManager() throws RemoteException { + return new IActivityManager.Default(); + } + + @Override + public IActivityStackSupervisor getActivityStackSupervisor() throws RemoteException { + return new IActivityStackSupervisor.Default(); + } + + @Override + public IAudioManager getAudioManager() throws RemoteException { + return new IAudioManager.Default(); + } + + @Override + public IBackupAgent getBackupAgent() throws RemoteException { + return new IBackupAgent.Default(); + } + + @Override + public IInputManager getInputManager() throws RemoteException { + return new IInputManager.Default(); + } + + @Override + public INetworkManager getNetworkManager() throws RemoteException { + return new INetworkManager.Default(); + } + + @Override + public InfiniteZ getInfiniteZ() throws RemoteException { + return new InfiniteZ.Default(); + } + + @Override + public INotificationManager getNotificationManager() throws RemoteException { + return new INotificationManager.Default(); + } + + @Override + public IOps getOpsManager() throws RemoteException { + return new IOps.Default(); + } + + @Override + public IPkgManager getPkgManager() throws RemoteException { + return new IPkgManager.Default(); + } + + @Override + public IPluginLogger getPluginLogger(String pluginAlias) throws RemoteException { + return new IPluginLogger.Default(); + } + + @Override + public IPowerManager getPowerManager() throws RemoteException { + return new IPowerManager.Default(); + } + + @Override + public IPrefManager getPrefManager() throws RemoteException { + return new IPrefManager.Default(); + } + + @Override + public IPrivacyManager getPrivacyManager() throws RemoteException { + return new IPrivacyManager.Default(); + } + + @Override + public IProfileManager getProfileManager() throws RemoteException { + return new IProfileManager.Default(); + } + + @Override + public IPushDelegateManager getPushDelegateManager() throws RemoteException { + return new IPushDelegateManager.Default(); + } + + @Override + public IPushManager getPushManager() throws RemoteException { + return new IPushManager.Default(); + } + + @Override + public IRS getRS() throws RemoteException { + return new IRS.Default(); + } + + @Override + public IUsageStatsManager getUsageStatsManager() throws RemoteException { + return new IUsageStatsManager.Default(); + } + + @Override + public IWindowManager getWindowManager() throws RemoteException { + return new IWindowManager.Default(); + } + + @Override + public List getPatchingSource() throws RemoteException { + return Collections.emptyList(); + } + }; + private IThanos service; @Getter private Context context; @@ -49,7 +189,10 @@ public ThanosManager(Context context, IThanos service) { } public boolean isServiceInstalled() { - boolean firstCheck = service != null && service.asBinder() != null && service.asBinder().isBinderAlive(); + boolean firstCheck = service != null + && sDefaultFallbackService != service + && service.asBinder() != null + && service.asBinder().isBinderAlive(); if (!firstCheck) { return false; } @@ -225,6 +368,12 @@ public List getPatchingSource() { } public static ThanosManager from(Context context) { - return new ThanosManager(context, ThanosManagerNative.getDefault()); + IThanos def = ThanosManagerNative.getDefault(); + IThanos thanos = def; + if (def == null) { + XLog.w("Using sDefaultFallbackService"); + thanos = sDefaultFallbackService; + } + return new ThanosManager(context, thanos); } } diff --git a/android/app/src/main/java/github/tornaco/android/thanos/main/DialogUtils.java b/android/app/src/main/java/github/tornaco/android/thanos/main/DialogUtils.java new file mode 100644 index 000000000..e344dbffc --- /dev/null +++ b/android/app/src/main/java/github/tornaco/android/thanos/main/DialogUtils.java @@ -0,0 +1,27 @@ +package github.tornaco.android.thanos.main; + +import android.content.Context; + +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + +import github.tornaco.android.thanos.BuildProp; +import github.tornaco.android.thanos.R; +import github.tornaco.android.thanos.util.BrowserUtils; + +public class DialogUtils { + private DialogUtils() { + } + + public static void showNotActivated(Context context) { + new MaterialAlertDialogBuilder(context) + .setTitle(R.string.status_not_active) + .setMessage(R.string.message_active_needed) + .setCancelable(true) + .setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(R.string.common_menu_title_wiki, + (dialog, which) -> { + BrowserUtils.launch(context, BuildProp.THANOX_URL_DOCS_HOME); + }) + .show(); + } +} diff --git a/android/app/src/main/java/github/tornaco/android/thanos/main/NavViewModel2.kt b/android/app/src/main/java/github/tornaco/android/thanos/main/NavViewModel2.kt index 4fc62764b..76d3557f8 100644 --- a/android/app/src/main/java/github/tornaco/android/thanos/main/NavViewModel2.kt +++ b/android/app/src/main/java/github/tornaco/android/thanos/main/NavViewModel2.kt @@ -253,6 +253,10 @@ class NavViewModel2 @Inject constructor(@ApplicationContext private val context: } fun headerClick(activity: Activity) { + if (!thanox.isServiceInstalled) { + DialogUtils.showNotActivated(activity) + return + } withSubscriptionStatus(activity) { isSubscribed: Boolean -> if (isSubscribed) { ProcessManageActivityV2.Starter.start(activity) diff --git a/android/app/src/main/java/github/tornaco/android/thanos/main/PrebuiltFeatureLauncher.kt b/android/app/src/main/java/github/tornaco/android/thanos/main/PrebuiltFeatureLauncher.kt index 4e70f2454..2d239b4ff 100644 --- a/android/app/src/main/java/github/tornaco/android/thanos/main/PrebuiltFeatureLauncher.kt +++ b/android/app/src/main/java/github/tornaco/android/thanos/main/PrebuiltFeatureLauncher.kt @@ -58,49 +58,81 @@ class PrebuiltFeatureLauncher( val thanosManager = ThanosManager.from(context) when (featureId) { PrebuiltFeatureIds.ID_ONE_KEY_CLEAR -> { - if (thanosManager.isServiceInstalled) { - AppFeatureManager.withSubscriptionStatus(context) { - if (it) { - context.sendBroadcast(Intent(T.Actions.ACTION_RUNNING_PROCESS_CLEAR)) - onProcessCleared() - } else { - AppFeatureManager.showDonateIntroDialog(this.context) - } + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } + AppFeatureManager.withSubscriptionStatus(context) { + if (it) { + context.sendBroadcast(Intent(T.Actions.ACTION_RUNNING_PROCESS_CLEAR)) + onProcessCleared() + } else { + AppFeatureManager.showDonateIntroDialog(this.context) } - } else { - BrowserUtils.launch(context, BuildProp.THANOX_URL_DOCS_HOME) } } PrebuiltFeatureIds.ID_BACKGROUND_START -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } StartRestrictActivity.start(context) } PrebuiltFeatureIds.ID_BACKGROUND_RESTRICT -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } BackgroundRestrictActivity.start(context) } PrebuiltFeatureIds.ID_CLEAN_TASK_REMOVAL -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } CleanUpOnTaskRemovedActivity.start(context) } PrebuiltFeatureIds.ID_APPS_MANAGER -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } SuggestedAppsActivity.start(context) } PrebuiltFeatureIds.ID_SCREEN_ON_NOTIFICATION -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } ScreenOnNotificationActivity.start(context) } PrebuiltFeatureIds.ID_NOTIFICATION_RECORDER -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } NotificationRecordActivity.start(context) } PrebuiltFeatureIds.ID_NOTIFICATION_CENTER -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } NotificationCenterActivity.Starter.start(context) } PrebuiltFeatureIds.ID_TRAMPOLINE -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } AppFeatureManager.withSubscriptionStatus(context) { if (it) { ActivityTrampolineActivity.start(context) @@ -116,10 +148,18 @@ class PrebuiltFeatureLauncher( } PrebuiltFeatureIds.ID_PROFILE -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } RuleListActivity.start(context) } PrebuiltFeatureIds.ID_SMART_STANDBY -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } AppFeatureManager.withSubscriptionStatus(context) { if (it) { SmartStandbyV2Activity.start(context) @@ -130,14 +170,26 @@ class PrebuiltFeatureLauncher( } PrebuiltFeatureIds.ID_SMART_FREEZE -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } SmartFreezeActivity.start(context) } PrebuiltFeatureIds.ID_PRIVACY_CHEAT -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } DataCheatActivity.start(context) } PrebuiltFeatureIds.ID_OPS_BY_OPS -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } if (AppPreference.isFeatureNoticeAccepted(context, "NEW_OPS")) { Ops2Activity.start(context) } else { @@ -146,14 +198,26 @@ class PrebuiltFeatureLauncher( } PrebuiltFeatureIds.ID_TASK_BLUR -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } RecentTaskBlurListActivity.start(context) } PrebuiltFeatureIds.ID_OP_REMIND -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } RemindOpsActivity.start(context) } PrebuiltFeatureIds.ID_APP_LOCK -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } AppFeatureManager.withSubscriptionStatus(context) { if (it) { LockerStartActivity.start(context) @@ -164,6 +228,10 @@ class PrebuiltFeatureLauncher( } PrebuiltFeatureIds.ID_INFINITE_Z -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } AppFeatureManager.withSubscriptionStatus(context) { if (it) { InfiniteZActivity.start(context) @@ -174,6 +242,10 @@ class PrebuiltFeatureLauncher( } PrebuiltFeatureIds.ID_PLUGINS -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } } PrebuiltFeatureIds.ID_FEEDBACK -> { @@ -185,6 +257,10 @@ class PrebuiltFeatureLauncher( } PrebuiltFeatureIds.ID_WECHAT_PUSH -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } AppFeatureManager.withSubscriptionStatus(context) { if (it) { WechatPushDeleteMainActivity.start(context) @@ -195,6 +271,10 @@ class PrebuiltFeatureLauncher( } PrebuiltFeatureIds.ID_WAKELOCK_REMOVER -> { + if (!thanosManager.isServiceInstalled) { + DialogUtils.showNotActivated(context) + return + } AppFeatureManager.withSubscriptionStatus(context) { if (it) { WakeLockBlockerActivity.Starter.start(context)