一、环境
高通865 Android 10
二、情景
应用跳转时,通过广播发送源app的包名和目标app的包名
三、代码实现
frameworks/base/services/core/java/com/android/server/wm/ActivityStarter.java
@@ -132,6 +132,14 @@ import java.io.PrintWriter;import java.text.DateFormat;import java.util.Date;+//added begin
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.Parcelable;
+import android.os.HandlerThread;
+//added end
+/*** Controller for interpreting how and then launching an activity.*
@@ -242,6 +250,39 @@ class ActivityStarter {void recycle(ActivityStarter starter);}+ private Handler mHandler;
+ private static final int DO_SEND_ACTIVITY_LAUNCHES_MSG = 1;
+
+ //added begin
+ private final class pkgHandler extends Handler {
+ public pkgHandler(Looper looper) {
+ super(looper, null, true);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch(msg.what) {
+ case DO_SEND_ACTIVITY_LAUNCHES_MSG:
+ android.util.Log.d("qxy","ActivityStartController --> handleMessage --> DO_SEND_ACTIVITY_LAUNCHES_MSG");
+ android.util.Log.d("qxy","Thread.currentThread().getId() = " + Thread.currentThread().getId()
+ + "\n" + "getMainLooper().getThread().getId() = " + mService.mContext.getMainLooper().getThread().getId());
+ Bundle bundle = msg.getData();
+ String pksFrom = bundle.getString("pksFrom");
+ String pksTo = bundle.getString("pksTo");
+ android.util.Log.d("qxy","pksFrom :" + pksFrom + " pksTo = " + pksTo);
+ Intent mIntent = new Intent();
+ mIntent.setAction("com.sc.app.launcher.jump");
+ mIntent.putExtra("pksFrom",pksFrom);
+ mIntent.putExtra("pksTo",pksTo);
+ mService.mContext.sendBroadcast(mIntent);
+ break;
+ }
+ }
+ }
+ //added end
+
+
+/*** Default implementation of {@link StarterFactory}.*/
@@ -1228,6 +1269,27 @@ class ActivityStarter {// Collect information about the target of the Intent.ActivityInfo aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags, profilerInfo);+ //add begin
+ /*
+ From -> callingPackage;
+ To -> intent.getComponent().getPackageName();
+ */
+ if(callingPackage != null && !callingPackage.equals(intent.getComponent().getPackageName())){
+ HandlerThread handlerThread = new HandlerThread("handler_thread");
+ handlerThread.start();
+ mHandler = new pkgHandler(handlerThread.getLooper());
+ mHandler.removeMessages(DO_SEND_ACTIVITY_LAUNCHES_MSG);
+ Message msg = mHandler.obtainMessage(DO_SEND_ACTIVITY_LAUNCHES_MSG);
+ Bundle mBundle = new Bundle();
+ mBundle.putString("pksFrom", callingPackage);
+ mBundle.putString("pksTo", intent.getComponent().getPackageName());
+ msg.setData(mBundle);
+ mHandler.sendMessage(msg);
+ }add end
+
+
+synchronized (mService.mGlobalLock) {final ActivityStack stack = mRootActivityContainer.getTopDisplayFocusedStack();stack.mConfigWillChange = globalConfig != null