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

Commit b68213be authored by Winson Chung's avatar Winson Chung
Browse files

Move lock task check to shared lib.

Bug: 70294936
Test: Ensure that launcher can check screen pinning state
Change-Id: I2951fb3605525c5cdb7b27b099c95a762322971c
parent 70f93ee6
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.shared.system;

import static android.app.ActivityManager.LOCK_TASK_MODE_NONE;
import static android.app.ActivityManager.LOCK_TASK_MODE_PINNED;
import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
@@ -31,6 +33,7 @@ import android.app.ActivityOptions;
import android.app.AppGlobals;
import android.app.IAssistDataReceiver;
import android.app.WindowConfiguration.ActivityType;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -47,6 +50,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.IconDrawableFactory;
import android.util.Log;
import android.view.IRecentsAnimationController;
@@ -436,4 +440,23 @@ public class ActivityManagerWrapper {
            Log.w(TAG, "Failed to cancel window transition for task=" + taskId, e);
        }
    }

    /**
     * @return whether there is currently a locked task (ie. in screen pinning).
     */
    public boolean isLockToAppActive() {
        try {
            return ActivityManager.getService().getLockTaskModeState() != LOCK_TASK_MODE_NONE;
        } catch (RemoteException e) {
            return false;
        }
    }

    /**
     * @return whether screen pinning is enabled.
     */
    public boolean isLockToAppEnabled() {
        final ContentResolver cr = AppGlobals.getInitialApplication().getContentResolver();
        return Settings.System.getInt(cr, Settings.System.LOCK_TO_APP_ENABLED, 0) != 0;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -415,7 +415,7 @@ public class Recents extends SystemUI
        final int activityType = runningTask != null
                ? runningTask.configuration.windowConfiguration.getActivityType()
                : ACTIVITY_TYPE_UNDEFINED;
        boolean screenPinningActive = sSystemServicesProxy.isScreenPinningActive();
        boolean screenPinningActive = ActivityManagerWrapper.getInstance().isLockToAppActive();
        boolean isRunningTaskInHomeOrRecentsStack =
                activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_RECENTS;
        if (runningTask != null && !isRunningTaskInHomeOrRecentsStack && !screenPinningActive) {
+4 −5
Original line number Diff line number Diff line
@@ -386,8 +386,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener

    public void toggleRecents(int growTarget) {
        // Skip preloading if the task is locked
        SystemServicesProxy ssp = Recents.getSystemServices();
        if (ssp.isScreenPinningActive()) {
        if (ActivityManagerWrapper.getInstance().isLockToAppActive()) {
            return;
        }

@@ -409,8 +408,8 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
            MutableBoolean isHomeStackVisible = new MutableBoolean(true);
            long elapsedTime = SystemClock.elapsedRealtime() - mLastToggleTime;

            SystemServicesProxy ssp = Recents.getSystemServices();
            if (ssp.isRecentsActivityVisible(isHomeStackVisible)) {
                RecentsDebugFlags debugFlags = Recents.getDebugFlags();
                RecentsConfiguration config = Recents.getConfiguration();
                RecentsActivityLaunchState launchState = config.getLaunchState();
                if (!launchState.launchedWithAltTab) {
@@ -466,8 +465,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener

    public void preloadRecents() {
        // Skip preloading if the task is locked
        SystemServicesProxy ssp = Recents.getSystemServices();
        if (ssp.isScreenPinningActive()) {
        if (ActivityManagerWrapper.getInstance().isLockToAppActive()) {
            return;
        }

@@ -481,6 +479,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        // RecentsActivity) only if there is a task to animate to.  Post this to ensure that we
        // don't block the touch feedback on the nav bar button which triggers this.
        mHandler.post(() -> {
            SystemServicesProxy ssp = Recents.getSystemServices();
            if (!ssp.isRecentsActivityVisible(null)) {
                ActivityManager.RunningTaskInfo runningTask =
                        ActivityManagerWrapper.getInstance().getRunningTask();
+0 −23
Original line number Diff line number Diff line
@@ -378,29 +378,6 @@ public class SystemServicesProxy {
        }
    }

    /**
     * Returns a global setting.
     */
    public int getGlobalSetting(Context context, String setting) {
        ContentResolver cr = context.getContentResolver();
        return Settings.Global.getInt(cr, setting, 0);
    }

    /**
     * Returns a system setting.
     */
    public int getSystemSetting(Context context, String setting) {
        ContentResolver cr = context.getContentResolver();
        return Settings.System.getInt(cr, setting, 0);
    }

    /**
     * Returns a system property.
     */
    public String getSystemProperty(String key) {
        return SystemProperties.get(key);
    }

    /**
     * Returns the smallest width/height.
     */
+2 −2
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ import com.android.systemui.recents.views.grid.GridTaskView;
import com.android.systemui.recents.views.grid.TaskGridLayoutAlgorithm;
import com.android.systemui.recents.views.grid.TaskViewFocusFrame;

import com.android.systemui.shared.system.ActivityManagerWrapper;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -2187,8 +2188,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
    private void readSystemFlags() {
        SystemServicesProxy ssp = Recents.getSystemServices();
        mTouchExplorationEnabled = ssp.isTouchExplorationEnabled();
        mScreenPinningEnabled = ssp.getSystemSetting(getContext(),
                Settings.System.LOCK_TO_APP_ENABLED) != 0;
        mScreenPinningEnabled = ActivityManagerWrapper.getInstance().isLockToAppEnabled();
    }

    private void updateStackActionButtonVisibility() {