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

Commit bfe82d19 authored by Charles He's avatar Charles He
Browse files

AM: remove toasts for LockTask mode.

Previously, toasts like "Screen pinned", "Screen unpinned", "This app
can't be pinned" are shown during the LockTask mode. These messages are
unncecessary for this use case, so we remove them. They will now only be
shown for the user-initiated screen pinning mode.

Bug: 67934620
Test: bit FrameworksServicesTests:com.android.server.am.LockTaskControllerTest
Test: cts-tradefed run cts-dev --module DevicePolicyManager -t com.android.cts.devicepolicy.DeviceOwnerTest#testLockTask_deviceOwnerUser
Change-Id: I2dd1a95afac207040263eadafd459a90de6aa9eb
parent 4b11fce4
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -4346,8 +4346,6 @@
    <string name="lock_to_app_toast">To unpin this screen, touch &amp; hold Back and Overview
        buttons</string>

    <!-- Notify user that they are locked in lock-to-app mode -->
    <string name="lock_to_app_toast_locked">This app can\'t be unpinned</string>
    <!-- Starting lock-to-app indication. -->
    <string name="lock_to_app_start">Screen pinned</string>
    <!-- Exting lock-to-app indication. -->
+0 −1
Original line number Diff line number Diff line
@@ -754,7 +754,6 @@
  <java-symbol type="string" name="last_month" />
  <java-symbol type="string" name="launchBrowserDefault" />
  <java-symbol type="string" name="lock_to_app_toast" />
  <java-symbol type="string" name="lock_to_app_toast_locked" />
  <java-symbol type="string" name="lock_to_app_start" />
  <java-symbol type="string" name="lock_to_app_exit" />
  <java-symbol type="string" name="lock_to_app_unlock_pin" />
+11 −4
Original line number Diff line number Diff line
@@ -327,7 +327,9 @@ public class LockTaskController {
            if (getDevicePolicyManager() != null) {
                getDevicePolicyManager().notifyLockTaskModeChanged(false, null, userId);
            }
            getLockTaskNotify().show(false);
            if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) {
                getLockTaskNotify().showPinningExitToast();
            }
            try {
                boolean shouldLockKeyguard = Settings.Secure.getIntForUser(
                        mContext.getContentResolver(),
@@ -349,10 +351,13 @@ public class LockTaskController {
    }

    /**
     * Show the lock task violation toast.
     * Show the lock task violation toast. Currently we only show toast for screen pinning mode, and
     * no-op if the device is in locked mode.
     */
    void showLockTaskToast() {
        mHandler.post(() -> getLockTaskNotify().showToast(mLockTaskModeState));
        if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) {
            mHandler.post(() -> getLockTaskNotify().showEscapeToast());
        }
    }

    // Starting lock task
@@ -439,7 +444,9 @@ public class LockTaskController {
    private void performStartLockTask(String packageName, int userId, int lockTaskModeState) {
        // When lock task starts, we disable the status bars.
        try {
            getLockTaskNotify().show(true);
            if (lockTaskModeState == LOCK_TASK_MODE_PINNED) {
                getLockTaskNotify().showPinningStartToast();
            }
            mLockTaskModeState = lockTaskModeState;
            if (getStatusBarService() != null) {
                int flags = 0;
+21 −28
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.server.am;

import android.app.ActivityManager;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
@@ -29,7 +28,7 @@ import com.android.internal.R;

/**
 *  Helper to manage showing/hiding a image to notify them that they are entering
 *  or exiting lock-to-app mode.
 *  or exiting screen pinning mode.
 */
public class LockTaskNotify {
    private static final String TAG = "LockTaskNotify";
@@ -45,20 +44,22 @@ public class LockTaskNotify {
        mHandler = new H();
    }

    public void showToast(int lockTaskModeState) {
        mHandler.obtainMessage(H.SHOW_TOAST, lockTaskModeState, 0 /* Not used */).sendToTarget();
    /** Show "Screen pinned" toast. */
    void showPinningStartToast() {
        makeAllUserToastAndShow(R.string.lock_to_app_start);
    }

    public void handleShowToast(int lockTaskModeState) {
        String text = null;
        if (lockTaskModeState == ActivityManager.LOCK_TASK_MODE_LOCKED) {
            text = mContext.getString(R.string.lock_to_app_toast_locked);
        } else if (lockTaskModeState == ActivityManager.LOCK_TASK_MODE_PINNED) {
            text = mContext.getString(R.string.lock_to_app_toast);
    /** Show "Screen unpinned" toast. */
    void showPinningExitToast() {
        makeAllUserToastAndShow(R.string.lock_to_app_exit);
    }
        if (text == null) {
            return;

    /** Show a toast that describes the gesture the user should use to escape pinned mode. */
    void showEscapeToast() {
        mHandler.obtainMessage(H.SHOW_ESCAPE_TOAST).sendToTarget();
    }

    private void handleShowEscapeToast() {
        long showToastTime = SystemClock.elapsedRealtime();
        if ((showToastTime - mLastShowToastTime) < SHOW_TOAST_MINIMUM_INTERVAL) {
            Slog.i(TAG, "Ignore toast since it is requested in very short interval.");
@@ -67,20 +68,12 @@ public class LockTaskNotify {
        if (mLastToast != null) {
            mLastToast.cancel();
        }
        mLastToast = makeAllUserToastAndShow(text);
        mLastToast = makeAllUserToastAndShow(R.string.lock_to_app_toast);
        mLastShowToastTime = showToastTime;
    }

    public void show(boolean starting) {
        int showString = R.string.lock_to_app_exit;
        if (starting) {
            showString = R.string.lock_to_app_start;
        }
        makeAllUserToastAndShow(mContext.getString(showString));
    }

    private Toast makeAllUserToastAndShow(String text) {
        Toast toast = Toast.makeText(mContext, text, Toast.LENGTH_LONG);
    private Toast makeAllUserToastAndShow(int resId) {
        Toast toast = Toast.makeText(mContext, resId, Toast.LENGTH_LONG);
        toast.getWindowParams().privateFlags |=
                WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
        toast.show();
@@ -88,13 +81,13 @@ public class LockTaskNotify {
    }

    private final class H extends Handler {
        private static final int SHOW_TOAST = 3;
        private static final int SHOW_ESCAPE_TOAST = 3;

        @Override
        public void handleMessage(Message msg) {
            switch(msg.what) {
                case SHOW_TOAST:
                    handleShowToast(msg.arg1);
                case SHOW_ESCAPE_TOAST:
                    handleShowEscapeToast();
                    break;
            }
        }
+4 −2
Original line number Diff line number Diff line
@@ -189,6 +189,8 @@ public class LockTaskControllerTest {

        // THEN lock task mode should be started
        verifyLockTaskStarted(STATUS_BAR_MASK_PINNED);
        // THEN screen pinning toast should be shown
        verify(mLockTaskNotify).showPinningStartToast();
    }

    @Test
@@ -255,8 +257,6 @@ public class LockTaskControllerTest {
        // WHEN system calls stopLockTaskMode
        mLockTaskController.stopLockTaskMode(true, SYSTEM_UID);

        // THEN a lock tash toast should be shown
        verify(mLockTaskNotify).showToast(LOCK_TASK_MODE_LOCKED);
        // THEN lock task mode should still be active
        assertEquals(LOCK_TASK_MODE_LOCKED, mLockTaskController.getLockTaskModeState());
    }
@@ -302,6 +302,8 @@ public class LockTaskControllerTest {
        verifyLockTaskStopped(times(1));
        // THEN the keyguard should be shown
        verify(mLockPatternUtils).requireCredentialEntry(UserHandle.USER_ALL);
        // THEN screen pinning toast should be shown
        verify(mLockTaskNotify).showPinningExitToast();
    }

    @Test