Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c41f6ec8 authored by Robin Lee's avatar Robin Lee
Browse files

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
parent 3fef1f28
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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);
}
+4 −0
Original line number Diff line number Diff line
@@ -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) {
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -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
+61 −0
Original line number Diff line number Diff line
/*
 * 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);
        }
    };
}
+13 −0
Original line number Diff line number Diff line
@@ -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;
                }
            }
        }
    }
Loading