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

Commit cc0f89b6 authored by Matthew Fritze's avatar Matthew Fritze
Browse files

Handle multiple Activities matching eSOS intent

We should be able to handle multiple emergengy sos activities on the
device without showing a disambig dialog. This CL adds a config string
to set the package name of the preferred app to handle the emergengy sos
intent (not using RoleManager#ROLE_EMERGENCY since SysUI doesn't have
the necessary permission).

The preference is given to the activity as follows:

1. Activity is from a system app with package name matching new config string
2. Activity is from a system app
3. Gesture becomes a no-op (will not match non-system activities)

Test: manual {StatusBar makes testing a launched activity
challenging}

Bug: 181610572
Change-Id: I862b4e3edf990d5f011aa0dc073070ede8b474b1
parent 943a2392
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -577,6 +577,9 @@
    <!-- Whether wallet view is shown in landscape / seascape orientations -->
    <bool name="global_actions_show_landscape_wallet_view">false</bool>

    <!-- Package name of the preferred system app to perform eSOS action -->
    <string name="config_preferredEmergencySosPackage" translatable="false"></string>

    <!-- Whether to use the split 2-column notification shade -->
    <bool name="config_use_split_notification_shade">false</bool>

+32 −1
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ import android.provider.Settings;
import android.service.dreams.DreamService;
import android.service.dreams.IDreamManager;
import android.service.notification.StatusBarNotification;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.DisplayMetrics;
import android.util.EventLog;
@@ -4071,7 +4072,9 @@ public class StatusBar extends SystemUI implements DemoMode,
    private @Nullable Intent getEmergencyActionIntent() {
        Intent emergencyIntent = new Intent(EmergencyGesture.ACTION_LAUNCH_EMERGENCY);
        PackageManager pm = mContext.getPackageManager();
        ResolveInfo resolveInfo = pm.resolveActivity(emergencyIntent, /*flags=*/0);
        List<ResolveInfo> emergencyActivities = pm.queryIntentActivities(emergencyIntent,
                PackageManager.MATCH_SYSTEM_ONLY);
        ResolveInfo resolveInfo = getTopEmergencySosInfo(emergencyActivities);
        if (resolveInfo == null) {
            Log.wtf(TAG, "Couldn't find an app to process the emergency intent.");
            return null;
@@ -4082,6 +4085,34 @@ public class StatusBar extends SystemUI implements DemoMode,
        return emergencyIntent;
    }

    /**
     * Select and return the "best" ResolveInfo for Emergency SOS Activity.
     */
    private @Nullable ResolveInfo getTopEmergencySosInfo(List<ResolveInfo> emergencyActivities) {
        // No matched activity.
        if (emergencyActivities == null || emergencyActivities.isEmpty()) {
            return null;
        }

        // Of multiple matched Activities, give preference to the pre-set package name.
        String preferredAppPackageName =
                mContext.getString(R.string.config_preferredEmergencySosPackage);

        // If there is no preferred app, then return first match.
        if (TextUtils.isEmpty(preferredAppPackageName)) {
            return emergencyActivities.get(0);
        }

        for (ResolveInfo emergencyInfo: emergencyActivities) {
            // If activity is from the preferred app, use it.
            if (TextUtils.equals(emergencyInfo.activityInfo.packageName, preferredAppPackageName)) {
                return emergencyInfo;
            }
        }
        // No matching activity: return first match
        return emergencyActivities.get(0);
    }

    boolean isCameraAllowedByAdmin() {
        if (mDevicePolicyManager.getCameraDisabled(null,
                mLockscreenUserManager.getCurrentUserId())) {