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

Commit e6309aa5 authored by Winson's avatar Winson Committed by Winson Chung
Browse files

Prevent docking via nav bar until user is set up.

- Also prevents docking if screen pinning is currently active.
- Fixes issue where you could go into recents when setting up a 
  secondary user.

Bug: 26438797
Bug: 26316912
Change-Id: I30576b52842b76184ef0b2252bc572f74a5d6db8
parent 778f495f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ public interface RecentsComponent {
    /**
     * Docks the top-most task and opens recents.
     */
    void dockTopTask(boolean draggingInRecents, int stackCreateMode, Rect initialBounds);
    boolean dockTopTask(boolean draggingInRecents, int stackCreateMode, Rect initialBounds);

    /**
     * Called during a drag-from-navbar-in gesture.
+26 −15
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.recents;

import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
@@ -205,7 +206,7 @@ public class Recents extends SystemUI
    public void showRecents(boolean triggeredFromAltTab, View statusBarView) {
        // Ensure the device has been provisioned before allowing the user to interact with
        // recents
        if (!isDeviceProvisioned()) {
        if (!isUserSetup()) {
            return;
        }

@@ -242,7 +243,7 @@ public class Recents extends SystemUI
    public void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
        // Ensure the device has been provisioned before allowing the user to interact with
        // recents
        if (!isDeviceProvisioned()) {
        if (!isUserSetup()) {
            return;
        }

@@ -277,7 +278,7 @@ public class Recents extends SystemUI
    public void toggleRecents(Display display, int layoutDirection, View statusBarView) {
        // Ensure the device has been provisioned before allowing the user to interact with
        // recents
        if (!isDeviceProvisioned()) {
        if (!isUserSetup()) {
            return;
        }

@@ -312,7 +313,7 @@ public class Recents extends SystemUI
    public void preloadRecents() {
        // Ensure the device has been provisioned before allowing the user to interact with
        // recents
        if (!isDeviceProvisioned()) {
        if (!isUserSetup()) {
            return;
        }

@@ -340,7 +341,7 @@ public class Recents extends SystemUI
    public void cancelPreloadingRecents() {
        // Ensure the device has been provisioned before allowing the user to interact with
        // recents
        if (!isDeviceProvisioned()) {
        if (!isUserSetup()) {
            return;
        }

@@ -365,11 +366,20 @@ public class Recents extends SystemUI
    }

    @Override
    public void dockTopTask(boolean draggingInRecents, int stackCreateMode, Rect initialBounds) {
        mImpl.dockTopTask(draggingInRecents, stackCreateMode,initialBounds);
    public boolean dockTopTask(boolean draggingInRecents, int stackCreateMode, Rect initialBounds) {
        // Ensure the device has been provisioned before allowing the user to interact with
        // recents
        if (!isUserSetup()) {
            return false;
        }

        if (mImpl.dockTopTask(draggingInRecents, stackCreateMode,initialBounds)) {
            if (draggingInRecents) {
                mDraggingInRecentsCurrentUser = sSystemServicesProxy.getCurrentUser();
            }
            return true;
        }
        return false;
    }

    @Override
@@ -422,7 +432,7 @@ public class Recents extends SystemUI
    public void showNextAffiliatedTask() {
        // Ensure the device has been provisioned before allowing the user to interact with
        // recents
        if (!isDeviceProvisioned()) {
        if (!isUserSetup()) {
            return;
        }

@@ -433,7 +443,7 @@ public class Recents extends SystemUI
    public void showPrevAffiliatedTask() {
        // Ensure the device has been provisioned before allowing the user to interact with
        // recents
        if (!isDeviceProvisioned()) {
        if (!isUserSetup()) {
            return;
        }

@@ -559,11 +569,12 @@ public class Recents extends SystemUI
    }

    /**
     * @return whether this device is provisioned.
     * @return whether this device is provisioned and the current user is set up.
     */
    private boolean isDeviceProvisioned() {
        return Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.DEVICE_PROVISIONED, 0) != 0;
    private boolean isUserSetup() {
        ContentResolver cr = mContext.getContentResolver();
        return (Settings.Global.getInt(cr, Settings.Global.DEVICE_PROVISIONED, 0) != 0) &&
                (Settings.Secure.getInt(cr, Settings.Secure.USER_SETUP_COMPLETE, 0) != 0);
    }

    /**
+7 −9
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.graphics.RectF;
import android.os.Handler;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
import android.util.MutableBoolean;
import android.view.AppTransitionAnimationSpec;
@@ -257,7 +258,6 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub implements
        }
    }

    @Override
    public void showRecents(boolean triggeredFromAltTab, boolean draggingInRecents,
            boolean animate, boolean reloadTasks) {
        mTriggeredFromAltTab = triggeredFromAltTab;
@@ -300,7 +300,6 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub implements
        }
    }

    @Override
    public void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
        if (mBootCompleted) {
            if (triggeredFromAltTab && mFastAltTabTrigger.isDozing()) {
@@ -321,7 +320,6 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub implements
        }
    }

    @Override
    public void toggleRecents() {
        // Skip this toggle if we are already waiting to trigger recents via alt-tab
        if (mFastAltTabTrigger.isDozing()) {
@@ -375,7 +373,6 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub implements
        }
    }

    @Override
    public void preloadRecents() {
        // Preload only the raw task list into a new load plan (which will be consumed by the
        // RecentsActivity) only if there is a task to animate to.
@@ -396,17 +393,14 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub implements
        }
    }

    @Override
    public void cancelPreloadingRecents() {
        // Do nothing
    }

    @Override
    public void onDraggingInRecents(float distanceFromTop) {
        EventBus.getDefault().sendOntoMainThread(new DraggingInRecentsEvent(distanceFromTop));
    }

    @Override
    public void onDraggingInRecentsEnded(float velocity) {
        EventBus.getDefault().sendOntoMainThread(new DraggingInRecentsEndedEvent(velocity));
    }
@@ -547,14 +541,18 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub implements
        showRelativeAffiliatedTask(false);
    }

    public void dockTopTask(boolean draggingInRecents, int stackCreateMode, Rect initialBounds) {
    public boolean dockTopTask(boolean draggingInRecents, int stackCreateMode, Rect initialBounds) {
        SystemServicesProxy ssp = Recents.getSystemServices();
        ActivityManager.RunningTaskInfo topTask = ssp.getTopMostTask();
        if (topTask != null && !SystemServicesProxy.isHomeStack(topTask.stackId)) {
        boolean screenPinningActive = ssp.isScreenPinningActive();
        boolean isTopTaskHome = SystemServicesProxy.isHomeStack(topTask.stackId);
        if (topTask != null && !isTopTaskHome && !screenPinningActive) {
            ssp.moveTaskToDockedStack(topTask.id, stackCreateMode, initialBounds);
            showRecents(false /* triggeredFromAltTab */, draggingInRecents, false /* animate */,
                    true /* reloadTasks*/);
            return true;
        }
        return false;
    }

    /**
+14 −1
Original line number Diff line number Diff line
@@ -506,7 +506,7 @@ public class SystemServicesProxy {
    public void sendCloseSystemWindows(String reason) {
        if (ActivityManagerNative.isSystemReady()) {
            try {
                ActivityManagerNative.getDefault().closeSystemDialogs(reason);
                mIam.closeSystemDialogs(reason);
            } catch (RemoteException e) {
            }
        }
@@ -778,6 +778,19 @@ public class SystemServicesProxy {
        return mAccm.isEnabled() && mAccm.isTouchExplorationEnabled();
    }

    /**
     * Returns whether the current task is in screen-pinning mode.
     */
    public boolean isScreenPinningActive() {
        if (mIam == null) return false;

        try {
            return mIam.isInLockTaskMode();
        } catch (RemoteException e) {
            return false;
        }
    }

    /**
     * Returns a global setting.
     */
+15 −11
Original line number Diff line number Diff line
@@ -175,10 +175,10 @@ public class NavigationBarGestureHelper extends GestureDetector.SimpleOnGestureL
                    : xDiff > mScrollTouchSlop && xDiff > yDiff;
            if (touchSlopExceeded && mDivider.getView().getWindowManagerProxy().getDockSide()
                    == DOCKED_INVALID) {
                mDragMode = calculateDragMode();
                Rect initialBounds = null;
                int dragMode = calculateDragMode();
                int createMode = ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT;
                if (mDragMode == DRAG_MODE_DIVIDER) {
                if (dragMode == DRAG_MODE_DIVIDER) {
                    initialBounds = new Rect();
                    mDivider.getView().calculateBoundsForPosition(mIsVertical
                                    ? (int) event.getRawX()
@@ -187,20 +187,24 @@ public class NavigationBarGestureHelper extends GestureDetector.SimpleOnGestureL
                                    ? DOCKED_TOP
                                    : DOCKED_LEFT,
                            initialBounds);
                } else if (mDragMode == DRAG_MODE_RECENTS && mTouchDownX
                } else if (dragMode == DRAG_MODE_RECENTS && mTouchDownX
                        < mContext.getResources().getDisplayMetrics().widthPixels / 2) {
                    createMode = ActivityManager.DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT;
                }
                mRecentsComponent.dockTopTask(mDragMode == DRAG_MODE_RECENTS, createMode,
                        initialBounds);
                boolean docked = mRecentsComponent.dockTopTask(dragMode == DRAG_MODE_RECENTS,
                        createMode, initialBounds);
                if (docked) {
                    mDragMode = dragMode;
                    if (mDragMode == DRAG_MODE_DIVIDER) {
                        mDivider.getView().startDragging(false /* animate */);
                    }
                    mDockWindowTouchSlopExceeded = true;
                    MetricsLogger.action(mContext,
                            MetricsLogger.ACTION_WINDOW_DOCK_SWIPE);

                    return true;
                }
            }
        } else {
            if (mDragMode == DRAG_MODE_DIVIDER) {
                int position = !mIsVertical ? (int) event.getRawY() : (int) event.getRawX();
Loading