【Android】Android Q適配startActivity

最近在適配Android Q,發(fā)現(xiàn)用的Hook框架不好用了,于是在同事大佬的幫助下拿到源碼,翻了一下,以下是區(qū)別

Android 8

public ActivityResult execStartActivity(
            Context who, IBinder contextThread, IBinder token, Activity target,
            Intent intent, int requestCode, Bundle options) {
        //.....省略不重要的
        try {
            intent.migrateExtraStreamToClipData();
            intent.prepareToLeaveProcess(who);
           int result = ActivityManager.getService()
                .startActivity(whoThread, who.getBasePackageName(), intent,
                        intent.resolveTypeIfNeeded(who.getContentResolver()),
                        token, target != null ? target.mEmbeddedID : null,
                        requestCode, 0, null, options);
            checkStartActivityResult(result, intent);
        } catch (RemoteException e) {
            throw new RuntimeException("Failure from system", e);
        }
        return null;
    }

重點是這一句

ActivityManager.getService().startActivity();

這是通過ActivityManagerService啟動的。

Android Q

@UnsupportedAppUsage
public ActivityResult execStartActivity(Context paramContext, IBinder paramIBinder1, IBinder paramIBinder2, Activity paramActivity, Intent paramIntent, int paramInt, Bundle paramBundle)
  {
    //.....省略不重要的
    try{
      paramIntent.migrateExtraStreamToClipData();
      paramIntent.prepareToLeaveProcess(paramContext);
      localIActivityTaskManager = ActivityTaskManager.getService();
      paramIBinder1 = paramContext.getBasePackageName();
      ??? = paramIntent.resolveTypeIfNeeded(paramContext.getContentResolver());
      if (paramActivity != null) {
        try{
          paramContext = paramActivity.mEmbeddedID;
        }
        catch (RemoteException paramContext){
          break label287;
        }
      } else {
        paramContext = null;
      }
      try{
        checkStartActivityResult(localIActivityTaskManager.startActivity(localIApplicationThread, paramIBinder1, paramIntent, (String)???, paramIBinder2, paramContext, paramInt, 0, null, paramBundle), paramIntent);
        return null;
      }
      catch (RemoteException paramContext) {}
      throw new RuntimeException("Failure from system", paramContext);
    }
    catch (RemoteException paramContext) {}
  }

可以看到重點是這里

localIActivityTaskManager = ActivityTaskManager.getService();
localIActivityTaskManager.startActivity();

這里是通過ActivityTaskManagerService來啟動的。
因為啟動類變了,所以Hook失效。

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容