Skip to content

Commit 30f20d5

Browse files
Louis ChangAndroid Build Coastguard Worker
authored andcommitted
Avoid locking profile task when it is already lock
WorkLockActivity was started repeatedly on top of the task that contains work apps when turning screen on and off over and over. So, lots of the WorkLockActivity instances were created and added in the task, which caused system sluggish. Bug: 177457096 Test: manually test work challenges Test: RootWindowContainerTests Change-Id: Iac345471ef3badad6b9e5c0cc2873c60938663eb Merged-In: Iac345471ef3badad6b9e5c0cc2873c60938663eb (cherry picked from commit 805585ed1baa0ddeeab07aa1f77819333a73c93d) (cherry picked from commit 499234d859d4a12a0856951b71ebf57015913ffa)
1 parent 3781f8d commit 30f20d5

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

services/core/java/com/android/server/wm/RootWindowContainer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.android.server.wm;
1818

1919
import static android.app.ActivityTaskManager.INVALID_TASK_ID;
20+
import static android.app.KeyguardManager.ACTION_CONFIRM_DEVICE_CREDENTIAL_WITH_USER;
2021
import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
2122
import static android.app.WindowConfiguration.ACTIVITY_TYPE_DREAM;
2223
import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
@@ -3365,6 +3366,15 @@ void lockAllProfileTasks(@UserIdInt int userId) {
33653366
mService.deferWindowLayout();
33663367
try {
33673368
forAllLeafTasks(task -> {
3369+
final ActivityRecord top = task.topRunningActivity();
3370+
if (top != null && !top.finishing
3371+
&& ACTION_CONFIRM_DEVICE_CREDENTIAL_WITH_USER.equals(top.intent.getAction())
3372+
&& top.packageName.equals(
3373+
mService.getSysUiServiceComponentLocked().getPackageName())) {
3374+
// Do nothing since the task is already secure by sysui.
3375+
return;
3376+
}
3377+
33683378
if (task.getActivity(activity -> !activity.finishing && activity.mUserId == userId)
33693379
!= null) {
33703380
mService.getTaskChangeNotificationController().notifyTaskProfileLocked(

services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.android.server.wm;
1818

19+
import static android.app.KeyguardManager.ACTION_CONFIRM_DEVICE_CREDENTIAL_WITH_USER;
1920
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
2021
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
2122
import static android.view.Display.DEFAULT_DISPLAY;
@@ -25,6 +26,7 @@
2526
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
2627
import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
2728

29+
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
2830
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
2931
import static com.android.server.wm.ActivityStack.ActivityState.FINISHING;
3032
import static com.android.server.wm.ActivityStack.ActivityState.PAUSED;
@@ -37,11 +39,15 @@
3739
import static org.junit.Assert.assertEquals;
3840
import static org.junit.Assert.assertFalse;
3941
import static org.junit.Assert.assertTrue;
42+
import static org.mockito.ArgumentMatchers.anyInt;
4043
import static org.mockito.ArgumentMatchers.eq;
44+
import static org.mockito.Mockito.clearInvocations;
45+
import static org.mockito.Mockito.never;
4146
import static org.mockito.Mockito.verify;
4247

4348
import android.app.WindowConfiguration;
4449
import android.content.ComponentName;
50+
import android.content.Intent;
4551
import android.content.pm.ActivityInfo;
4652
import android.os.UserHandle;
4753
import android.platform.test.annotations.Presubmit;
@@ -194,13 +200,32 @@ public void testLockAllProfileTasks() {
194200
.setUid(UserHandle.PER_USER_RANGE + 1)
195201
.setTask(task)
196202
.build();
203+
doReturn(true).when(topActivity).okToShowLocked();
204+
topActivity.intent.setAction(Intent.ACTION_MAIN);
197205

198206
// Make sure the listeners will be notified for putting the task to locked state
199207
TaskChangeNotificationController controller =
200208
mWm.mAtmService.getTaskChangeNotificationController();
201209
spyOn(controller);
202210
mWm.mRoot.lockAllProfileTasks(0);
203211
verify(controller).notifyTaskProfileLocked(eq(task.mTaskId), eq(0));
212+
213+
// Create the work lock activity on top of the task
214+
final ActivityRecord workLockActivity =
215+
new ActivityTestsBase.ActivityBuilder(mWm.mAtmService)
216+
.setStack(stack)
217+
.setUid(UserHandle.PER_USER_RANGE + 1)
218+
.setTask(task)
219+
.build();
220+
doReturn(true).when(workLockActivity).okToShowLocked();
221+
workLockActivity.intent.setAction(ACTION_CONFIRM_DEVICE_CREDENTIAL_WITH_USER);
222+
doReturn(workLockActivity.mActivityComponent).when(
223+
mWm.mAtmService).getSysUiServiceComponentLocked();
224+
225+
// Make sure the listener won't be notified again.
226+
clearInvocations(controller);
227+
mWm.mRoot.lockAllProfileTasks(0);
228+
verify(controller, never()).notifyTaskProfileLocked(eq(task.mTaskId), anyInt());
204229
}
205230
}
206231

0 commit comments

Comments
 (0)