diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java index f9e1069cfe958..90e3b1e734542 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java @@ -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; + } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/Recents.java b/packages/SystemUI/src/com/android/systemui/recents/Recents.java index 1da4deb61176f..409c753c147c8 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/Recents.java +++ b/packages/SystemUI/src/com/android/systemui/recents/Recents.java @@ -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) { diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java index ee1b09109d380..3f6f30bba8c41 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java @@ -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(); diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java index 613d9fbb985cf..93fd34aa05195 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java +++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java @@ -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. */ diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java index 5be2900831b3c..3cc3273c0db44 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java @@ -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() {