OSDN Git Service

Lock work tasks from SystemUI instead of ActivityStarter
authorRobin Lee <rgl@google.com>
Tue, 10 Jan 2017 17:02:34 +0000 (17:02 +0000)
committerRobin Lee <rgl@google.com>
Wed, 11 Jan 2017 14:13:07 +0000 (14:13 +0000)
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

core/java/android/app/ITaskStackListener.aidl
core/java/android/app/TaskStackListener.java
packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivityController.java [new file with mode: 0644]
packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
services/core/java/com/android/server/am/ActivityStackSupervisor.java
services/core/java/com/android/server/am/ActivityStarter.java
services/core/java/com/android/server/am/TaskChangeNotificationController.java

index e454ae1..ef997c9 100644 (file)
@@ -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);
 }
index 0639552..ad5e69b 100644 (file)
@@ -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) {
+    }
 }
index 8e5db97..ce89aab 100644 (file)
@@ -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
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivityController.java b/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivityController.java
new file mode 100644 (file)
index 0000000..22fceff
--- /dev/null
@@ -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);
+        }
+    };
+}
index ddffea2..05df634 100644 (file)
@@ -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;
+                }
             }
         }
     }
index aeab7be..a935249 100644 (file)
@@ -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);
                     }
                 }
             }
index 5f04d7f..09af941 100644 (file)
@@ -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,
index fd248c6..fbdbb1b 100644 (file)
@@ -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();
+    }
 }