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

Commit 9efc89a8 authored by Evan Severson's avatar Evan Severson
Browse files

Show mic access as background for emergency app

It is believed that the user will be confused if they see that the app
is only requesting microphone access in the foreground. This is just a
UI change and the app actually never has access in the backgorund.

Test: Carcrash onboarding flow
Bug: 160718710
Change-Id: I97fcdea178b86231a3de74da6c3023514a896395
parent e284153c
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -756,7 +756,8 @@ public class GrantPermissionsActivity extends Activity
                                || groupState.mGroup.getName().equals(
                                Manifest.permission_group.MICROPHONE)) {
                            mButtonVisibilities[ALLOW_BUTTON] = false;
                            if (mCouldHaveFgCapabilities) {
                            if (mCouldHaveFgCapabilities
                                    || Utils.isEmergencyApp(this, mCallingPackage)) {
                                mButtonVisibilities[ALLOW_ALWAYS_BUTTON] = true;
                                mButtonVisibilities[ALLOW_ONE_TIME_BUTTON] = false;
                            } else {
@@ -832,7 +833,8 @@ public class GrantPermissionsActivity extends Activity
                                || groupState.mGroup.getName().equals(
                                        Manifest.permission_group.MICROPHONE)) {
                            mButtonVisibilities[ALLOW_BUTTON] = false;
                            if (mCouldHaveFgCapabilities) {
                            if (mCouldHaveFgCapabilities
                                    || Utils.isEmergencyApp(this, mCallingPackage)) {
                                mButtonVisibilities[ALLOW_ALWAYS_BUTTON] = true;
                                mButtonVisibilities[ALLOW_ONE_TIME_BUTTON] = false;
                            } else {
+11 −3
Original line number Diff line number Diff line
@@ -278,9 +278,11 @@ class AppPermissionViewModel(

                    if (detailId == 0) {
                        detailId = getForegroundCapableDetailResId(foregroundCapableType)
                        if (detailId != 0) {
                            detailResIdLiveData.value = detailId to null
                        }
                    }
                }
            } else {
                // Allow / Deny case
                allowedState.isShown = true
@@ -308,7 +310,8 @@ class AppPermissionViewModel(
                    allowedState.isShown = false
                    allowedForegroundState.isChecked = allowedState.isChecked
                    allowedForegroundState.isEnabled = allowedState.isEnabled
                    if (couldPackageHaveFgCapabilities) {
                    if (couldPackageHaveFgCapabilities || (Utils.isEmergencyApp(app, packageName) &&
                                    isMicrophone(permGroupName))) {
                        allowedAlwaysState.isShown = true
                        allowedAlwaysState.isChecked = allowedForegroundState.isChecked
                        allowedAlwaysState.isEnabled = allowedForegroundState.isEnabled
@@ -319,11 +322,13 @@ class AppPermissionViewModel(

                        if (detailId == 0) {
                            detailId = getForegroundCapableDetailResId(foregroundCapableType)
                            if (detailId != 0) {
                                detailResIdLiveData.value = detailId to null
                            }
                        }
                    }
                }
            }
            if (group.packageInfo.targetSdkVersion < Build.VERSION_CODES.M) {
                // Pre-M app's can't ask for runtime permissions
                askState.isShown = false
@@ -367,6 +372,9 @@ class AppPermissionViewModel(
        return permissionGroupName.equals(Manifest.permission_group.CAMERA) ||
                permissionGroupName.equals(Manifest.permission_group.MICROPHONE)
    }
    private fun isMicrophone(permissionGroupName: String): Boolean {
        return permissionGroupName.equals(Manifest.permission_group.MICROPHONE)
    }

    /**
     * Modifies the radio buttons to reflect the current policy fixing state
+14 −0
Original line number Diff line number Diff line
@@ -1127,4 +1127,18 @@ public final class Utils {
                || (userManager.isManagedProfile(user.getIdentifier())
                && !DeviceUtils.isTelevision(app));
    }

    /**
     * @return Whether a package is an emergency app.
     */
    public static boolean isEmergencyApp(@NonNull Context context,  @NonNull String packageName) {
        try {
            return context.getSystemService(RoleManager.class)
                    .getRoleHolders(RoleManager.ROLE_EMERGENCY).contains(packageName);
        } catch (Throwable t) {
            // Avoid crashing for any reason, this isn't very well tested
            Log.e(LOG_TAG, "Unable to check if " + packageName + " is an emergency app.", t);
            return false;
        }
    }
}