Skip to content

Commit

Permalink
[app] add fallback IThanos
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed Sep 26, 2023
1 parent 7ccc662 commit ff292e3
Show file tree
Hide file tree
Showing 4 changed files with 272 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> getPatchingSource() throws RemoteException {
return Collections.emptyList();
}
};

private IThanos service;
@Getter
private Context context;
Expand All @@ -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;
}
Expand Down Expand Up @@ -225,6 +368,12 @@ public List<String> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit ff292e3

Please sign in to comment.