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

Commit 92b109b6 authored by Brad Hinegardner's avatar Brad Hinegardner Committed by Android Build Coastguard Worker
Browse files

[RESTRICT AUTOMERGE] Stay in app pinned mode upon SystemUI crash

Bug: b/366405211
Test: atest LockTaskControllerTest.java
Flag: EXEMPT BUGFIX
(cherry picked from commit 575845147cb48d71893f12665bae2e8892aa7e06)
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:06e5f6cb4e893155d46b5e329a00495fccdc71eb
Merged-In: Ia9f54b229b998e29da53436ed6ed64214903724c
Change-Id: Ia9f54b229b998e29da53436ed6ed64214903724c
parent b98e6917
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -179,6 +179,7 @@ interface IActivityTaskManager {
    List<IBinder> getAppTasks(in String callingPackage);
    void startSystemLockTaskMode(int taskId);
    void stopSystemLockTaskMode();
    void rebuildSystemLockTaskPinnedMode();
    void finishVoiceTask(in IVoiceInteractionSession session);
    int addAppTask(in IBinder activityToken, in Intent intent,
            in ActivityManager.TaskDescription description, in Bitmap thumbnail);
+13 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.keyguard;

import static android.app.ActivityManager.LOCK_TASK_MODE_PINNED;
import static android.app.KeyguardManager.LOCK_ON_USER_SWITCH_CALLBACK;
import static android.app.StatusBarManager.SESSION_KEYGUARD;
import static android.provider.Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT;
@@ -51,6 +52,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.app.ActivityTaskManager;
import android.app.AlarmManager;
import android.app.BroadcastOptions;
import android.app.IActivityTaskManager;
@@ -3962,6 +3964,17 @@ public class KeyguardViewMediator implements CoreStartable,
            if (mBootSendUserPresent) {
                sendUserPresentBroadcast();
            }

            mHandler.post(() -> {
                try {
                    if (mActivityTaskManagerService.getLockTaskModeState()
                            == LOCK_TASK_MODE_PINNED) {
                        mActivityTaskManagerService.rebuildSystemLockTaskPinnedMode();
                    }
                } catch (RemoteException e) {
                    Log.e(TAG, "Failed to rebuild lock task pinned mode", e);
                }
            });
        }
    }

+3 −0
Original line number Diff line number Diff line
@@ -239,7 +239,10 @@ public class KeyguardServiceDelegate {
        public void onServiceDisconnected(ComponentName name) {
            if (DEBUG) Log.v(TAG, "*** Keyguard disconnected (boo!)");
            mKeyguardService = null;
            // Remember the keyguard enabled state when the service is disconnected.
            boolean wasEnabled = mKeyguardState.enabled;
            mKeyguardState.reset();
            mKeyguardState.enabled = wasEnabled;
            mHandler.post(() -> {
                try {
                    ActivityTaskManager.getService().setLockScreenShown(true /* keyguardShowing */,
+14 −0
Original line number Diff line number Diff line
@@ -2658,6 +2658,20 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        stopLockTaskModeInternal(null, true /* isSystemCaller */);
    }

    @Override
    public void rebuildSystemLockTaskPinnedMode() {
        enforceTaskPermission("rebuildSystemLockTaskPinnedMode");
        // This makes inner call to look as if it was initiated by system.
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized (mGlobalLock) {
                getLockTaskController().rebuildSystemLockTaskPinnedMode();
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    void startLockTaskMode(@Nullable Task task, boolean isSystemCaller) {
        ProtoLog.w(WM_DEBUG_LOCKTASK, "startLockTaskMode: %s", task);
        if (task == null || task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) {
+35 −0
Original line number Diff line number Diff line
@@ -681,6 +681,41 @@ public class LockTaskController {
                "startLockTask", true);
    }

    /**
     * Method to rebuild Lock Task Pinned Mode. This uses the existing locked tasks.
     */
    void rebuildSystemLockTaskPinnedMode() {
        int lockTaskModeState = mLockTaskModeState;
        if (lockTaskModeState != LOCK_TASK_MODE_PINNED) {
            Slog.e(TAG_LOCKTASK,
                    "rebuildSystemLockTaskPinnedMode: Attempt to rebuild pinned mode but not in "
                            + "pinned mode.");
            return;
        }
        if (mLockTaskModeTasks.isEmpty()) {
            Slog.i(TAG_LOCKTASK,
                    "rebuildSystemLockTaskPinnedMode: mLockTaskModeTasks empty, nothing to "
                            + "rebuild.");
            return;
        }
        Task task = mLockTaskModeTasks.getFirst();
        mSupervisor.mRecentTasks.onLockTaskModeStateChanged(LOCK_TASK_MODE_PINNED, task.mUserId);
        // rebuild pinned mode on the handler thread
        mHandler.post(() -> {
            try {
                final IStatusBarService statusBarService = getStatusBarService();
                if (statusBarService != null) {
                    statusBarService.showPinningEnterExitToast(true /* entering */);
                }
                mTaskChangeNotificationController.notifyLockTaskModeChanged(lockTaskModeState);
                setStatusBarState(lockTaskModeState, task.mUserId);
                setKeyguardState(lockTaskModeState, task.mUserId);
            } catch (RemoteException ex) {
                throw new RuntimeException(ex);
            }
        });
    }

    /**
     * Start lock task mode on the given task.
     * @param lockTaskModeState whether fully locked or pinned mode.
Loading