Loading services/core/java/com/android/server/am/ActivityManagerService.java +4 −1 Original line number Diff line number Diff line Loading @@ -4866,7 +4866,7 @@ public class ActivityManagerService extends IActivityManager.Stub } @GuardedBy("this") private final boolean attachApplicationLocked(IApplicationThread thread, private boolean attachApplicationLocked(@NonNull IApplicationThread thread, int pid, int callingUid, long startSeq) { // Find the application record that is being attached... either via Loading Loading @@ -5287,6 +5287,9 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public final void attachApplication(IApplicationThread thread, long startSeq) { if (thread == null) { throw new SecurityException("Invalid application interface"); } synchronized (this) { int callingPid = Binder.getCallingPid(); final int callingUid = Binder.getCallingUid(); Loading services/core/java/com/android/server/wm/ActivityStack.java +10 −5 Original line number Diff line number Diff line Loading @@ -2854,6 +2854,11 @@ class ActivityStack extends Task implements BoundsAnimationTarget { boolean navigateUpTo(ActivityRecord srec, Intent destIntent, int resultCode, Intent resultData) { if (!srec.attachedToProcess()) { // Nothing to do if the caller is not attached, because this method should be called // from an alive activity. return false; } final Task task = srec.getTask(); if (!mChildren.contains(task) || !task.hasChild(srec)) { Loading Loading @@ -2915,14 +2920,14 @@ class ActivityStack extends Task implements BoundsAnimationTarget { resultData = resultDataHolder[0]; if (parent != null && foundParentInTask) { final int callingUid = srec.info.applicationInfo.uid; final int parentLaunchMode = parent.info.launchMode; final int destIntentFlags = destIntent.getFlags(); if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, srec.packageName); parent.deliverNewIntentLocked(callingUid, destIntent, srec.packageName); } else { try { ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( Loading @@ -2935,11 +2940,11 @@ class ActivityStack extends Task implements BoundsAnimationTarget { .setActivityInfo(aInfo) .setResultTo(parent.appToken) .setCallingPid(-1) .setCallingUid(parent.launchedFromUid) .setCallingPackage(parent.launchedFromPackage) .setCallingUid(callingUid) .setCallingPackage(srec.packageName) .setCallingFeatureId(parent.launchedFromFeatureId) .setRealCallingPid(-1) .setRealCallingUid(parent.launchedFromUid) .setRealCallingUid(callingUid) .setComponentSpecified(true) .execute(); foundParentInTask = res == ActivityManager.START_SUCCESS; Loading services/core/java/com/android/server/wm/WindowProcessController.java +3 −1 Original line number Diff line number Diff line Loading @@ -221,9 +221,11 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio // has been sent to client by {@link android.app.IApplicationThread#bindApplication}. // If this process is system server, it is fine because system is booting and a new // configuration will update when display is ready. if (thread != null) { setLastReportedConfiguration(getConfiguration()); } } } IApplicationThread getThread() { return mThread; Loading services/tests/wmtests/src/com/android/server/wm/ActivityStackTests.java +35 −0 Original line number Diff line number Diff line Loading @@ -54,8 +54,12 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import android.app.ActivityManager; import android.app.IApplicationThread; import android.content.ComponentName; import android.content.pm.ActivityInfo; import android.os.UserHandle; Loading Loading @@ -1108,6 +1112,37 @@ public class ActivityStackTests extends ActivityTestsBase { assertTrue(listener.mChanged); } @Test public void testNavigateUpTo() { final ActivityStartController controller = mock(ActivityStartController.class); final ActivityStarter starter = new ActivityStarter(controller, mService, mService.mStackSupervisor, mock(ActivityStartInterceptor.class)); doReturn(controller).when(mService).getActivityStartController(); spyOn(starter); doReturn(ActivityManager.START_SUCCESS).when(starter).execute(); final ActivityRecord firstActivity = new ActivityBuilder(mService).setTask(mTask).build(); final ActivityRecord secondActivity = new ActivityBuilder(mService).setTask(mTask) .setUid(firstActivity.getUid() + 1).build(); doReturn(starter).when(controller).obtainStarter(eq(firstActivity.intent), anyString()); final IApplicationThread thread = secondActivity.app.getThread(); secondActivity.app.setThread(null); // This should do nothing from a non-attached caller. assertFalse(mStack.navigateUpTo(secondActivity /* source record */, firstActivity.intent /* destIntent */, 0 /* resultCode */, null /* resultData */)); secondActivity.app.setThread(thread); assertTrue(mStack.navigateUpTo(secondActivity /* source record */, firstActivity.intent /* destIntent */, 0 /* resultCode */, null /* resultData */)); // The firstActivity uses default launch mode, so the activities between it and itself will // be finished. assertTrue(secondActivity.finishing); assertTrue(firstActivity.finishing); // The caller uid of the new activity should be the current real caller. assertEquals(starter.mRequest.callingUid, secondActivity.getUid()); } @Test public void testResetTaskWithFinishingActivities() { final ActivityRecord taskTop = Loading services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java +1 −0 Original line number Diff line number Diff line Loading @@ -238,6 +238,7 @@ class ActivityTestsBase extends SystemServiceTestsBase { aInfo.applicationInfo.uid = mUid; aInfo.processName = mProcessName; aInfo.packageName = mComponent.getPackageName(); aInfo.name = mComponent.getClassName(); if (mTargetActivity != null) { aInfo.targetActivity = mTargetActivity; } Loading Loading
services/core/java/com/android/server/am/ActivityManagerService.java +4 −1 Original line number Diff line number Diff line Loading @@ -4866,7 +4866,7 @@ public class ActivityManagerService extends IActivityManager.Stub } @GuardedBy("this") private final boolean attachApplicationLocked(IApplicationThread thread, private boolean attachApplicationLocked(@NonNull IApplicationThread thread, int pid, int callingUid, long startSeq) { // Find the application record that is being attached... either via Loading Loading @@ -5287,6 +5287,9 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public final void attachApplication(IApplicationThread thread, long startSeq) { if (thread == null) { throw new SecurityException("Invalid application interface"); } synchronized (this) { int callingPid = Binder.getCallingPid(); final int callingUid = Binder.getCallingUid(); Loading
services/core/java/com/android/server/wm/ActivityStack.java +10 −5 Original line number Diff line number Diff line Loading @@ -2854,6 +2854,11 @@ class ActivityStack extends Task implements BoundsAnimationTarget { boolean navigateUpTo(ActivityRecord srec, Intent destIntent, int resultCode, Intent resultData) { if (!srec.attachedToProcess()) { // Nothing to do if the caller is not attached, because this method should be called // from an alive activity. return false; } final Task task = srec.getTask(); if (!mChildren.contains(task) || !task.hasChild(srec)) { Loading Loading @@ -2915,14 +2920,14 @@ class ActivityStack extends Task implements BoundsAnimationTarget { resultData = resultDataHolder[0]; if (parent != null && foundParentInTask) { final int callingUid = srec.info.applicationInfo.uid; final int parentLaunchMode = parent.info.launchMode; final int destIntentFlags = destIntent.getFlags(); if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, srec.packageName); parent.deliverNewIntentLocked(callingUid, destIntent, srec.packageName); } else { try { ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( Loading @@ -2935,11 +2940,11 @@ class ActivityStack extends Task implements BoundsAnimationTarget { .setActivityInfo(aInfo) .setResultTo(parent.appToken) .setCallingPid(-1) .setCallingUid(parent.launchedFromUid) .setCallingPackage(parent.launchedFromPackage) .setCallingUid(callingUid) .setCallingPackage(srec.packageName) .setCallingFeatureId(parent.launchedFromFeatureId) .setRealCallingPid(-1) .setRealCallingUid(parent.launchedFromUid) .setRealCallingUid(callingUid) .setComponentSpecified(true) .execute(); foundParentInTask = res == ActivityManager.START_SUCCESS; Loading
services/core/java/com/android/server/wm/WindowProcessController.java +3 −1 Original line number Diff line number Diff line Loading @@ -221,9 +221,11 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio // has been sent to client by {@link android.app.IApplicationThread#bindApplication}. // If this process is system server, it is fine because system is booting and a new // configuration will update when display is ready. if (thread != null) { setLastReportedConfiguration(getConfiguration()); } } } IApplicationThread getThread() { return mThread; Loading
services/tests/wmtests/src/com/android/server/wm/ActivityStackTests.java +35 −0 Original line number Diff line number Diff line Loading @@ -54,8 +54,12 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import android.app.ActivityManager; import android.app.IApplicationThread; import android.content.ComponentName; import android.content.pm.ActivityInfo; import android.os.UserHandle; Loading Loading @@ -1108,6 +1112,37 @@ public class ActivityStackTests extends ActivityTestsBase { assertTrue(listener.mChanged); } @Test public void testNavigateUpTo() { final ActivityStartController controller = mock(ActivityStartController.class); final ActivityStarter starter = new ActivityStarter(controller, mService, mService.mStackSupervisor, mock(ActivityStartInterceptor.class)); doReturn(controller).when(mService).getActivityStartController(); spyOn(starter); doReturn(ActivityManager.START_SUCCESS).when(starter).execute(); final ActivityRecord firstActivity = new ActivityBuilder(mService).setTask(mTask).build(); final ActivityRecord secondActivity = new ActivityBuilder(mService).setTask(mTask) .setUid(firstActivity.getUid() + 1).build(); doReturn(starter).when(controller).obtainStarter(eq(firstActivity.intent), anyString()); final IApplicationThread thread = secondActivity.app.getThread(); secondActivity.app.setThread(null); // This should do nothing from a non-attached caller. assertFalse(mStack.navigateUpTo(secondActivity /* source record */, firstActivity.intent /* destIntent */, 0 /* resultCode */, null /* resultData */)); secondActivity.app.setThread(thread); assertTrue(mStack.navigateUpTo(secondActivity /* source record */, firstActivity.intent /* destIntent */, 0 /* resultCode */, null /* resultData */)); // The firstActivity uses default launch mode, so the activities between it and itself will // be finished. assertTrue(secondActivity.finishing); assertTrue(firstActivity.finishing); // The caller uid of the new activity should be the current real caller. assertEquals(starter.mRequest.callingUid, secondActivity.getUid()); } @Test public void testResetTaskWithFinishingActivities() { final ActivityRecord taskTop = Loading
services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java +1 −0 Original line number Diff line number Diff line Loading @@ -238,6 +238,7 @@ class ActivityTestsBase extends SystemServiceTestsBase { aInfo.applicationInfo.uid = mUid; aInfo.processName = mProcessName; aInfo.packageName = mComponent.getPackageName(); aInfo.name = mComponent.getClassName(); if (mTargetActivity != null) { aInfo.targetActivity = mTargetActivity; } Loading