summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff Chang <chengjeff@google.com> 2021-11-30 16:23:38 +0800
committer Jeff Chang <chengjeff@google.com> 2021-12-02 10:23:32 +0800
commite8c584a8d2ed91676f651a16f82cc493e610d9fe (patch)
treee43ed7061d89aed1b64a8689875fb98210961c5b
parent6a1ecf7c453521da7b985fcbf0d70b4ae330ac1a (diff)
Create a API #onActivityLaunched in ActivityInterceptorCallback
Create a new API #onActivityLaunched() which is called when an activity is successfully launched, and provides the activity and task information to the interceptor. Bug: 207596723 Test: testActivityLaunchedCallback_singleCallback Change-Id: I42d73042d6f213f40f023e42814f73507bcbe7ee
-rw-r--r--services/core/java/com/android/server/wm/ActivityInterceptorCallback.java7
-rw-r--r--services/core/java/com/android/server/wm/ActivityStartInterceptor.java13
-rw-r--r--services/core/java/com/android/server/wm/ActivityStarter.java4
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java16
4 files changed, 40 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityInterceptorCallback.java b/services/core/java/com/android/server/wm/ActivityInterceptorCallback.java
index 00e1f55e0b3d..d736ede7e97e 100644
--- a/services/core/java/com/android/server/wm/ActivityInterceptorCallback.java
+++ b/services/core/java/com/android/server/wm/ActivityInterceptorCallback.java
@@ -19,6 +19,7 @@ package com.android.server.wm;
import android.annotation.IntDef;
import android.annotation.Nullable;
import android.app.ActivityOptions;
+import android.app.TaskInfo;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ResolveInfo;
@@ -40,6 +41,12 @@ public abstract class ActivityInterceptorCallback {
public abstract @Nullable Intent intercept(ActivityInterceptorInfo info);
/**
+ * Called when an activity is successfully launched.
+ */
+ public void onActivityLaunched(TaskInfo taskInfo, ActivityInfo activityInfo) {
+ }
+
+ /**
* The unique id of each interceptor which determines the order it will execute in.
*/
@IntDef(suffix = { "_ORDERED_ID" }, value = {
diff --git a/services/core/java/com/android/server/wm/ActivityStartInterceptor.java b/services/core/java/com/android/server/wm/ActivityStartInterceptor.java
index 223f0be9bbea..352a0709d0d2 100644
--- a/services/core/java/com/android/server/wm/ActivityStartInterceptor.java
+++ b/services/core/java/com/android/server/wm/ActivityStartInterceptor.java
@@ -37,6 +37,7 @@ import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
import android.annotation.Nullable;
import android.app.ActivityOptions;
import android.app.KeyguardManager;
+import android.app.TaskInfo;
import android.app.admin.DevicePolicyManagerInternal;
import android.content.Context;
import android.content.IIntentSender;
@@ -402,4 +403,16 @@ class ActivityStartInterceptor {
mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/);
return true;
}
+
+ /**
+ * Called when an activity is successfully launched.
+ */
+ void onActivityLaunched(TaskInfo taskInfo, ActivityInfo activityInfo) {
+ final SparseArray<ActivityInterceptorCallback> callbacks =
+ mService.getActivityInterceptorCallbacks();
+ for (int i = 0; i < callbacks.size(); i++) {
+ final ActivityInterceptorCallback callback = callbacks.valueAt(i);
+ callback.onActivityLaunched(taskInfo, activityInfo);
+ }
+ }
}
diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java
index 73a783eba602..233b0198a2a6 100644
--- a/services/core/java/com/android/server/wm/ActivityStarter.java
+++ b/services/core/java/com/android/server/wm/ActivityStarter.java
@@ -1559,6 +1559,10 @@ class ActivityStarter {
mService.getTaskChangeNotificationController().notifyActivityRestartAttempt(
targetTask.getTaskInfo(), homeTaskVisible, clearedTask, visible);
}
+
+ if (ActivityManager.isStartResultSuccessful(result)) {
+ mInterceptor.onActivityLaunched(targetTask.getTaskInfo(), r.info);
+ }
}
/**
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java
index c103bc6fb9a1..3e617d58caa0 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java
@@ -19,6 +19,10 @@ package com.android.server.wm;
import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
import static android.content.pm.ApplicationInfo.FLAG_SUSPENDED;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.any;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.times;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
@@ -327,4 +331,16 @@ public class ActivityStartInterceptorTest {
assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, 0, 0, null));
assertEquals("android.test.second", mInterceptor.mIntent.getAction());
}
+
+ @Test
+ public void testActivityLaunchedCallback_singleCallback() {
+ addMockInterceptorCallback(null);
+
+ assertEquals(1, mActivityInterceptorCallbacks.size());
+ final ActivityInterceptorCallback callback = mActivityInterceptorCallbacks.valueAt(0);
+ spyOn(callback);
+ mInterceptor.onActivityLaunched(null, null);
+
+ verify(callback, times(1)).onActivityLaunched(any(), any());
+ }
}