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

Commit 02f64684 authored by Fan Zhang's avatar Fan Zhang
Browse files

Prototype launching FED after detecting 5 taps power button

This launches FED, not the panic UI. And it's not launching through
sysui as designed.

It also does not deal with keyguard so screen will flash when tapping 5
times.

Left TODOs in code to fix later.

Test: manual
Bug: 161394591
Change-Id: I9791279a2bc13355a8b79af665ef449cd6040c7b
parent 544a5148
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.provider.Settings;
import android.telecom.TelecomManager;
import android.util.MutableBoolean;
import android.util.Slog;
import android.view.KeyEvent;
@@ -457,6 +458,8 @@ public class GestureLauncherService extends SystemService {
            }
        } else if (launchPanic) {
            Slog.i(TAG, "Panic gesture detected, launching panic.");
            launchPanic = handlePanicButtonGesture();
            // TODO(b/160006048): Add logging
        }
        mMetricsLogger.histogram("power_consecutive_short_tap_count",
                mPowerButtonSlowConsecutiveTaps);
@@ -501,6 +504,46 @@ public class GestureLauncherService extends SystemService {
        }
    }

    /**
     * @return true if panic ui was launched, false otherwise.
     */
    @VisibleForTesting
    boolean handlePanicButtonGesture() {
        // TODO(b/160006048): This is the wrong way to launch panic ui. Rewrite this to go
        //  through SysUI
        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER,
                "GestureLauncher:handlePanicButtonGesture");
        try {
            boolean userSetupComplete = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                    Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
            if (!userSetupComplete) {
                if (DBG) {
                    Slog.d(TAG, String.format(
                            "userSetupComplete = %s, ignoring panic gesture.",
                            userSetupComplete));
                }
                return false;
            }
            if (DBG) {
                Slog.d(TAG, String.format(
                        "userSetupComplete = %s, performing panic gesture.",
                        userSetupComplete));
            }
            // TODO(b/160006048): Not all devices have telephony. Check system feature first.
            TelecomManager telecomManager = (TelecomManager) mContext.getSystemService(
                    Context.TELECOM_SERVICE);
            mContext.startActivity(telecomManager.createLaunchEmergencyDialerIntent(null).addFlags(
                    Intent.FLAG_ACTIVITY_NEW_TASK
                            | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
                            | Intent.FLAG_ACTIVITY_SINGLE_TOP).putExtra(
                    "com.android.phone.EmergencyDialer.extra.ENTRY_TYPE",
                    2)); // 2 maps to power button, forcing into fast emergency dialer experience.
            return true;
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
        }
    }

    private final BroadcastReceiver mUserReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
+19 −0
Original line number Diff line number Diff line
@@ -28,11 +28,13 @@ import static org.mockito.Mockito.when;

import android.app.StatusBarManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Looper;
import android.os.UserHandle;
import android.platform.test.annotations.Presubmit;
import android.provider.Settings;
import android.telecom.TelecomManager;
import android.test.mock.MockContentResolver;
import android.util.MutableBoolean;
import android.view.KeyEvent;
@@ -80,6 +82,7 @@ public class GestureLauncherServiceTest {
    private @Mock Context mContext;
    private @Mock Resources mResources;
    private @Mock StatusBarManagerInternal mStatusBarManagerInternal;
    private @Mock TelecomManager mTelecomManager;
    private @Mock MetricsLogger mMetricsLogger;
    private MockContentResolver mContentResolver;
    private GestureLauncherService mGestureLauncherService;
@@ -104,6 +107,8 @@ public class GestureLauncherServiceTest {
        mContentResolver = new MockContentResolver(mContext);
        mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
        when(mContext.getContentResolver()).thenReturn(mContentResolver);
        when(mContext.getSystemService(Context.TELECOM_SERVICE)).thenReturn(mTelecomManager);
        when(mTelecomManager.createLaunchEmergencyDialerIntent(null)).thenReturn(new Intent());

        mGestureLauncherService = new GestureLauncherService(mContext, mMetricsLogger);
    }
@@ -175,6 +180,13 @@ public class GestureLauncherServiceTest {
        verify(mStatusBarManagerInternal).onCameraLaunchGestureDetected(FAKE_SOURCE);
    }

    @Test
    public void testHandlePanicGesture_userSetupComplete() {
        withUserSetupCompleteValue(true);

        assertTrue(mGestureLauncherService.handlePanicButtonGesture());
    }

    @Test
    public void testHandleCameraLaunchGesture_userSetupNotComplete() {
        withUserSetupCompleteValue(false);
@@ -183,6 +195,13 @@ public class GestureLauncherServiceTest {
        assertFalse(mGestureLauncherService.handleCameraGesture(useWakeLock, FAKE_SOURCE));
    }

    @Test
    public void testHandlePanicGesture_userSetupNotComplete() {
        withUserSetupCompleteValue(false);

        assertFalse(mGestureLauncherService.handlePanicButtonGesture());
    }

    @Test
    public void testInterceptPowerKeyDown_firstPowerDownCameraPowerGestureOnInteractive() {
        withCameraDoubleTapPowerEnableConfigValue(true);