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

Commit 3e7e3cdc authored by Utkarsh Gupta's avatar Utkarsh Gupta Committed by Michael W
Browse files

Allow screen unpinning on devices without navbar

Change-Id: Iedfc08f4d95bbee3c8578c0d2450b90739e63603

Screen Pinning: Show correct text for on screen nav.

  Similar to I09c2ef661bff272cb4f7ca43bac0e45f4b20a4d4,
  we're not getting an instance of PhoneWindowManager which
  we can rely on to update dynamically.

  TICKET: OPO-393

Change-Id: Iacf8221066461fb6940dd88432e665812545c3ff
parent 50468f60
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -122,4 +122,10 @@
    <string name="status_bar_camera">Camera</string>
    <string name="status_bar_location">Location</string>
    <string name="status_bar_microphone">Microphone</string>

    <!-- Screen pinning dialog description. (for devices without navbar) -->
    <string name="screen_pinning_description_no_navbar">This keeps it in view until you unpin. Touch &amp; hold Back to unpin.</string>

    <!-- Notify use that they are in Lock-to-app (for devices without navbar)-->
    <string name="screen_pinning_toast_no_navbar">To unpin this screen, touch &amp; hold Back button</string>
</resources>
+22 −6
Original line number Diff line number Diff line
@@ -33,9 +33,11 @@ import android.os.Binder;
import android.os.RemoteException;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.IWindowManager;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.DecelerateInterpolator;
import android.widget.Button;
@@ -264,14 +266,18 @@ public class ScreenPinningRequest implements View.OnClickListener,
                mLayout.findViewById(R.id.screen_pinning_recents_group).setVisibility(VISIBLE);
                mLayout.findViewById(R.id.screen_pinning_home_bg_light).setVisibility(INVISIBLE);
                mLayout.findViewById(R.id.screen_pinning_home_bg).setVisibility(INVISIBLE);
                descriptionStringResId = touchExplorationEnabled
                descriptionStringResId = !hasNavigationBar()
                        ? R.string.screen_pinning_description_no_navbar
                        : touchExplorationEnabled
                                ? R.string.screen_pinning_description_accessible
                                : R.string.screen_pinning_description;
            } else {
                mLayout.findViewById(R.id.screen_pinning_recents_group).setVisibility(INVISIBLE);
                mLayout.findViewById(R.id.screen_pinning_home_bg_light).setVisibility(VISIBLE);
                mLayout.findViewById(R.id.screen_pinning_home_bg).setVisibility(VISIBLE);
                descriptionStringResId = touchExplorationEnabled
                descriptionStringResId = !hasNavigationBar()
                        ? R.string.screen_pinning_description_no_navbar
                        : touchExplorationEnabled
                                ? R.string.screen_pinning_description_recents_invisible_accessible
                                : R.string.screen_pinning_description_recents_invisible;
            }
@@ -311,6 +317,16 @@ public class ScreenPinningRequest implements View.OnClickListener,
            }
        }

        private boolean hasNavigationBar() {
            IWindowManager windowManagerService = WindowManagerGlobal.getWindowManagerService();
            try {
                return windowManagerService.hasNavigationBar(mContext.getDisplayId());
            } catch (RemoteException e) {
                // ignore
            }
            return false;
        }

        @Override
        public void onDetachedFromWindow() {
            mContext.unregisterReceiver(mReceiver);
+21 −5
Original line number Diff line number Diff line
@@ -17,8 +17,12 @@
package com.android.systemui.statusbar.phone;

import android.content.Context;
import android.os.RemoteException;
import android.os.SystemClock;
import android.util.Slog;
import android.view.IWindowManager;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.widget.Toast;

import com.android.systemui.R;
@@ -60,7 +64,9 @@ public class ScreenPinningNotify {
        if (mLastToast != null) {
            mLastToast.cancel();
        }
        mLastToast = makeAllUserToastAndShow(isGestureNavEnabled
        mLastToast = makeAllUserToastAndShow(!hasNavigationBar()
                ? R.string.screen_pinning_toast_no_navbar
                : isGestureNavEnabled
                        ? R.string.screen_pinning_toast_gesture_nav
                        : isRecentsButtonVisible
                                ? R.string.screen_pinning_toast
@@ -73,4 +79,14 @@ public class ScreenPinningNotify {
        toast.show();
        return toast;
    }

    private boolean hasNavigationBar() {
        IWindowManager windowManagerService = WindowManagerGlobal.getWindowManagerService();
        try {
            return windowManagerService.hasNavigationBar(mContext.getDisplayId());
        } catch (RemoteException e) {
            // ignore
        }
        return false;
     }
}
+21 −1
Original line number Diff line number Diff line
@@ -1661,6 +1661,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private final Runnable mBackLongPress = new Runnable() {
        @Override
        public void run() {
            if (unpinActivity(false)) {
                return;
            }

            if (ActionUtils.killForegroundApp(mContext, mCurrentUserId)) {
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
                        "Back - Long Press");
@@ -3415,7 +3419,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
            return -1;
        } else if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (mKillAppLongpressBack) {
            if (mKillAppLongpressBack || unpinActivity(true)) {
                if (down && repeatCount == 0) {
                    mHandler.postDelayed(mBackLongPress, mBackKillTimeout);
                }
@@ -3658,6 +3662,22 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return false;
    }

    private boolean unpinActivity(boolean checkOnly) {
        if (!hasNavigationBar()) {
            try {
                if (ActivityTaskManager.getService().isInLockTaskMode()) {
                    if (!checkOnly) {
                        ActivityTaskManager.getService().stopSystemLockTaskMode();
                    }
                    return true;
                }
            } catch (RemoteException e) {
                // ignore
            }
        }
        return false;
    }

    // TODO(b/117479243): handle it in InputPolicy
    /** {@inheritDoc} */
    @Override