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

Commit 9394bd84 authored by Matthew Fritze's avatar Matthew Fritze
Browse files

Launch Panic gesture from SysUI

- Add StatusBar interface for launching panic gesture
- Add basic method to launch the panic gesture in sysui
- Swap call to launch telephony to launching eshare intent

Tested in Pixel 3a using the Settings Panel intent (since it resolves)
and found that it does indeed launch ontop of the camera (see
screenshot) and turns off the screen. These can be fixed in a later CL.

Screenshot: https://screenshot.googleplex.com/8KKEEXbyBLkJssy

Test: atest StatusBarTest GestureLauncherServiceTest CommandQueueTest
Bug: 169087010
Change-Id: I9efccffd06edbf37c15ea92ef5935ab7091a7f80
parent f76ffeaf
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -101,6 +101,13 @@ oneway interface IStatusBar
     */
    void onCameraLaunchGestureDetected(int source);

    /**
     * Notifies the status bar that the Emergency Action launch gesture has been detected.
     *
     * TODO(b/169175022) Update method name and docs when feature name is locked.
     */
    void onEmergencyActionLaunchGestureDetected();

    /**
     * Shows the picture-in-picture menu if an activity is in picture-in-picture mode.
     */
+19 −0
Original line number Diff line number Diff line
@@ -140,6 +140,8 @@ public class CommandQueue extends IStatusBar.Stub implements CallbackController<
    private static final int MSG_SUPPRESS_AMBIENT_DISPLAY          = 56 << MSG_SHIFT;
    private static final int MSG_REQUEST_WINDOW_MAGNIFICATION_CONNECTION = 57 << MSG_SHIFT;
    private static final int MSG_HANDLE_WINDOW_MANAGER_LOGGING_COMMAND = 58 << MSG_SHIFT;
    //TODO(b/169175022) Update name and when feature name is locked.
    private static final int MSG_EMERGENCY_ACTION_LAUNCH_GESTURE      = 59 << MSG_SHIFT;

    public static final int FLAG_EXCLUDE_NONE = 0;
    public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
@@ -258,6 +260,11 @@ public class CommandQueue extends IStatusBar.Stub implements CallbackController<
        default void showAssistDisclosure() { }
        default void startAssist(Bundle args) { }
        default void onCameraLaunchGestureDetected(int source) { }

        /**
         * Notifies SysUI that the emergency action gesture was detected.
         */
        default void onEmergencyActionLaunchGestureDetected() { }
        default void showPictureInPictureMenu() { }
        default void setTopAppHidesStatusBar(boolean topAppHidesStatusBar) { }

@@ -729,6 +736,14 @@ public class CommandQueue extends IStatusBar.Stub implements CallbackController<
        }
    }

    @Override
    public void onEmergencyActionLaunchGestureDetected() {
        synchronized (mLock) {
            mHandler.removeMessages(MSG_EMERGENCY_ACTION_LAUNCH_GESTURE);
            mHandler.obtainMessage(MSG_EMERGENCY_ACTION_LAUNCH_GESTURE).sendToTarget();
        }
    }

    @Override
    public void addQsTile(ComponentName tile) {
        synchronized (mLock) {
@@ -1186,6 +1201,10 @@ public class CommandQueue extends IStatusBar.Stub implements CallbackController<
                        mCallbacks.get(i).onCameraLaunchGestureDetected(msg.arg1);
                    }
                    break;
                case MSG_EMERGENCY_ACTION_LAUNCH_GESTURE:
                    for (int i = 0; i < mCallbacks.size(); i++) {
                        mCallbacks.get(i).onEmergencyActionLaunchGestureDetected();
                    }
                case MSG_SHOW_PICTURE_IN_PICTURE_MENU:
                    for (int i = 0; i < mCallbacks.size(); i++) {
                        mCallbacks.get(i).showPictureInPictureMenu();
+24 −3
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ import android.content.IntentFilter;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.graphics.Point;
import android.graphics.PointF;
@@ -152,6 +153,7 @@ import com.android.systemui.dagger.qualifiers.UiBackground;
import com.android.systemui.demomode.DemoMode;
import com.android.systemui.demomode.DemoModeCommandReceiver;
import com.android.systemui.demomode.DemoModeController;
import com.android.systemui.emergency.EmergencyGesture;
import com.android.systemui.fragments.ExtensionFragmentListener;
import com.android.systemui.fragments.FragmentHostManager;
import com.android.systemui.keyguard.DismissCallbackRegistry;
@@ -819,7 +821,7 @@ public class StatusBar extends SystemUI implements DemoMode,
                    updateScrimController();
                };


        mActivityIntentHelper = new ActivityIntentHelper(mContext);
        DateTimeView.setReceiverHandler(timeTickHandler);
    }

@@ -833,8 +835,6 @@ public class StatusBar extends SystemUI implements DemoMode,
            mBubblesOptional.get().setExpandListener(mBubbleExpandListener);
        }

        mActivityIntentHelper = new ActivityIntentHelper(mContext);

        mColorExtractor.addOnColorsChangedListener(this);
        mStatusBarStateController.addCallback(this,
                SysuiStatusBarStateController.RANK_STATUS_BAR);
@@ -3982,6 +3982,27 @@ public class StatusBar extends SystemUI implements DemoMode,
        }
    }

    @Override
    public void onEmergencyActionLaunchGestureDetected() {
        // TODO (b/169793384) Polish the panic gesture to be just like its older brother, camera.
        Intent emergencyIntent = new Intent(EmergencyGesture.ACTION_LAUNCH_EMERGENCY);
        PackageManager pm = mContext.getPackageManager();
        ResolveInfo resolveInfo = pm.resolveActivity(emergencyIntent, /*flags=*/0);
        if (resolveInfo == null) {
            Log.wtf(TAG, "Couldn't find an app to process the emergency intent.");
            return;
        }

        if (mVibrator != null && mVibrator.hasVibrator()) {
            mVibrator.vibrate(500L);
        }

        emergencyIntent.setComponent(new ComponentName(resolveInfo.activityInfo.packageName,
                resolveInfo.activityInfo.name));
        emergencyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(emergencyIntent, /*dismissShade=*/true);
    }

    boolean isCameraAllowedByAdmin() {
        if (mDevicePolicyManager.getCameraDisabled(null,
                mLockscreenUserManager.getCurrentUserId())) {
+7 −0
Original line number Diff line number Diff line
@@ -70,6 +70,13 @@
            android:exported="false"
            android:resizeableActivity="true" />

        <activity android:name="com.android.systemui.emergency.EmergencyActivityTest"
                  android:exported="true">
            <intent-filter>
                <action android:name="com.android.systemui.action.LAUNCH_EMERGENCY"/>
            </intent-filter>
        </activity>

        <activity
            android:name="com.android.systemui.globalactions.GlobalActionsImeTest$TestActivity"
            android:excludeFromRecents="true"
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.emergency;

import android.app.Activity;
import android.os.Bundle;

import com.android.systemui.R;

/**
 * Test activity for resolving {@link EmergencyGesture#ACTION_LAUNCH_EMERGENCY} action.
 */
public class EmergencyActivityTest extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
Loading