Lock work tasks from SystemUI instead of ActivityStarter
By adding an onTaskProfileLocked(taskId, userId) RPC to TaskStackListener and routing that through to a new WorkLockController. Bug: 31001762 Test: //tests/PoApi/src/com/google/android/afwtest/poapi/WorkChallengeTest Change-Id: I3fd28e6926c3f928e78b3c6ce0fe27413617695f
This commit is contained in:
@@ -95,4 +95,11 @@ oneway interface ITaskStackListener {
|
||||
* perform relevant animations before the window disappears.
|
||||
*/
|
||||
void onTaskRemovalStarted(int taskId);
|
||||
|
||||
/**
|
||||
* Called when the task has been put in a locked state because one or more of the
|
||||
* activities inside it belong to a managed profile user, and that user has just
|
||||
* been locked.
|
||||
*/
|
||||
void onTaskProfileLocked(int taskId, int userId);
|
||||
}
|
||||
|
||||
@@ -74,4 +74,8 @@ public abstract class TaskStackListener extends ITaskStackListener.Stub {
|
||||
public void onActivityRequestedOrientationChanged(int taskId, int requestedOrientation)
|
||||
throws RemoteException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskProfileLocked(int taskId, int userId) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,6 +326,12 @@ public class KeyguardViewMediator extends SystemUI {
|
||||
*/
|
||||
private boolean mPendingLock;
|
||||
|
||||
/**
|
||||
* Controller for showing individual "work challenge" lock screen windows inside managed profile
|
||||
* tasks when the current user has been unlocked but the profile is still locked.
|
||||
*/
|
||||
private WorkLockActivityController mWorkLockController;
|
||||
|
||||
private boolean mLockLater;
|
||||
|
||||
private boolean mWakeAndUnlocking;
|
||||
@@ -708,6 +714,8 @@ public class KeyguardViewMediator extends SystemUI {
|
||||
|
||||
mHideAnimation = AnimationUtils.loadAnimation(mContext,
|
||||
com.android.internal.R.anim.lock_screen_behind_enter);
|
||||
|
||||
mWorkLockController = new WorkLockActivityController(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.systemui.keyguard;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityOptions;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.systemui.recents.events.EventBus;
|
||||
import com.android.systemui.recents.misc.SystemServicesProxy;
|
||||
import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener;
|
||||
|
||||
public class WorkLockActivityController {
|
||||
private final Context mContext;
|
||||
|
||||
public WorkLockActivityController(Context context) {
|
||||
mContext = context;
|
||||
EventBus.getDefault().register(this);
|
||||
SystemServicesProxy.getInstance(context).registerTaskStackListener(mLockListener);
|
||||
}
|
||||
|
||||
private void startWorkChallengeInTask(int taskId, int userId) {
|
||||
Intent intent = new Intent(KeyguardManager.ACTION_CONFIRM_DEVICE_CREDENTIAL_WITH_USER)
|
||||
.setComponent(new ComponentName(mContext, WorkLockActivity.class))
|
||||
.putExtra(Intent.EXTRA_USER_ID, userId)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
|
||||
| Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
|
||||
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
||||
final ActivityOptions options = ActivityOptions.makeBasic();
|
||||
options.setLaunchTaskId(taskId);
|
||||
options.setTaskOverlay(true);
|
||||
mContext.startActivityAsUser(intent, options.toBundle(), UserHandle.CURRENT);
|
||||
}
|
||||
|
||||
private final TaskStackListener mLockListener = new TaskStackListener() {
|
||||
@Override
|
||||
public void onTaskProfileLocked(int taskId, int userId) {
|
||||
startWorkChallengeInTask(taskId, userId);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -154,6 +154,7 @@ public class SystemServicesProxy {
|
||||
public void onPinnedStackAnimationEnded() { }
|
||||
public void onActivityForcedResizable(String packageName, int taskId) { }
|
||||
public void onActivityDismissingDockedStack() { }
|
||||
public void onTaskProfileLocked(int taskId, int userId) { }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,6 +198,11 @@ public class SystemServicesProxy {
|
||||
public void onActivityDismissingDockedStack() throws RemoteException {
|
||||
mHandler.sendEmptyMessage(H.ON_ACTIVITY_DISMISSING_DOCKED_STACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskProfileLocked(int taskId, int userId) {
|
||||
mHandler.obtainMessage(H.ON_TASK_PROFILE_LOCKED, taskId, userId).sendToTarget();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1155,6 +1161,7 @@ public class SystemServicesProxy {
|
||||
private static final int ON_PINNED_STACK_ANIMATION_ENDED = 4;
|
||||
private static final int ON_ACTIVITY_FORCED_RESIZABLE = 5;
|
||||
private static final int ON_ACTIVITY_DISMISSING_DOCKED_STACK = 6;
|
||||
private static final int ON_TASK_PROFILE_LOCKED = 7;
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
@@ -1196,6 +1203,12 @@ public class SystemServicesProxy {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ON_TASK_PROFILE_LOCKED: {
|
||||
for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) {
|
||||
mTaskStackListeners.get(i).onTaskProfileLocked(msg.arg1, msg.arg2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -801,7 +801,8 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
|
||||
// to an activity belonging to userId. Example case: a document picker for
|
||||
// personal files, opened by a work app, should still get locked.
|
||||
if (taskTopActivityIsUser(task, userId)) {
|
||||
mService.mActivityStarter.startTaskLockedActivity(task);
|
||||
mService.mTaskChangeNotificationController.notifyTaskProfileLocked(
|
||||
task.taskId, userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,27 +660,6 @@ class ActivityStarter {
|
||||
UserHandle.CURRENT);
|
||||
}
|
||||
|
||||
void startTaskLockedActivity(final TaskRecord task) {
|
||||
final ActivityRecord activityRecord = task.topRunningActivityLocked();
|
||||
if (activityRecord == null) {
|
||||
Slog.w(TAG, "Unable to find activity record to start lock activity for task: " + task);
|
||||
return;
|
||||
}
|
||||
|
||||
final KeyguardManager km = (KeyguardManager) mService.mContext
|
||||
.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
Intent intent = new Intent(KeyguardManager.ACTION_CONFIRM_DEVICE_CREDENTIAL_WITH_USER);
|
||||
intent.setPackage("com.android.systemui");
|
||||
intent.putExtra(Intent.EXTRA_TASK_ID, task.lastTaskDescription);
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, task.userId);
|
||||
intent.addFlags(FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | FLAG_ACTIVITY_REORDER_TO_FRONT
|
||||
| FLAG_ACTIVITY_SINGLE_TOP);
|
||||
final ActivityOptions options = ActivityOptions.makeBasic();
|
||||
options.setLaunchTaskId(task.taskId);
|
||||
options.setTaskOverlay(true);
|
||||
mService.mContext.startActivityAsUser(intent, options.toBundle(), UserHandle.CURRENT);
|
||||
}
|
||||
|
||||
final int startActivityMayWait(IApplicationThread caller, int callingUid,
|
||||
String callingPackage, Intent intent, String resolvedType,
|
||||
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
|
||||
|
||||
@@ -39,6 +39,7 @@ class TaskChangeNotificationController {
|
||||
static final int NOTIFY_TASK_DESCRIPTION_CHANGED_LISTENERS_MSG = 11;
|
||||
static final int NOTIFY_ACTIVITY_REQUESTED_ORIENTATION_CHANGED_LISTENERS = 12;
|
||||
static final int NOTIFY_TASK_REMOVAL_STARTED_LISTENERS = 13;
|
||||
static final int NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG = 14;
|
||||
|
||||
// Delay in notifying task stack change listeners (in millis)
|
||||
static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100;
|
||||
@@ -110,6 +111,9 @@ class TaskChangeNotificationController {
|
||||
case NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG:
|
||||
forAllListeners((listener) -> listener.onActivityDismissingDockedStack());
|
||||
break;
|
||||
case NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG:
|
||||
forAllListeners((listener) -> listener.onTaskProfileLocked(msg.arg1, msg.arg2));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,4 +232,13 @@ class TaskChangeNotificationController {
|
||||
mHandler.obtainMessage(NOTIFY_TASK_REMOVAL_STARTED_LISTENERS, taskId, 0 /* unused */)
|
||||
.sendToTarget();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify listeners that the task has been put in a locked state because one or more of the
|
||||
* activities inside it belong to a managed profile user that has been locked.
|
||||
*/
|
||||
void notifyTaskProfileLocked(int taskId, int userId) {
|
||||
mHandler.obtainMessage(NOTIFY_TASK_PROFILE_LOCKED_LISTENERS_MSG, taskId, userId)
|
||||
.sendToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user