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

Commit 58507ad2 authored by Ricardo Correa's avatar Ricardo Correa
Browse files

Grant Call audio access to default dialer role

The call audio access will be granted to default dialer apps that require such capability.
This change also added InCallService as a requirement for Dialer role, so we avoid some role abuse.
Also include a string informing that the user will be granting the call audio to the default dialer application.

Test: Compilation and manual test
Bug: 135197853

Change-Id: I77824569091ef964fcff67c663ef370d21841db0
parent 4fbb21d3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -475,11 +475,11 @@
    <!-- Short label for the dialer role. [CHAR LIMIT=30] -->
    <string name="role_dialer_short_label">Phone app</string>
    <!-- Description for the dialer role. [CHAR LIMIT=NONE] -->
    <string name="role_dialer_description">Apps that allow you to make and receive telephone calls on your device</string>
    <string name="role_dialer_description">Phone apps allow you to make and receive telephone calls on your device\n\nPhone apps can also access and record call audio</string>
    <!-- Template for the title when an app requests to become the default dialer app. [CHAR LIMIT=100] -->
    <string name="role_dialer_request_title">Set <xliff:g id="app_name" example="Super Phone">%1$s</xliff:g> as your default phone app?</string>
    <!-- Description when an app requests to become the default dialer app. [CHAR LIMIT=60] -->
    <string name="role_dialer_request_description">Gets access to call log, send SMS</string>
    <string name="role_dialer_request_description">Gets access to call log and call audio, send SMS</string>
    <!-- Search keywords for the dialer role. [CHAR LIMIT=NONE] -->
    <string name="role_dialer_search_keywords">dialer</string>

+6 −0
Original line number Diff line number Diff line
@@ -184,6 +184,12 @@
                    <data scheme="tel" />
                </intent-filter>
            </activity>
            <service permission="android.permission.BIND_INCALL_SERVICE">
              <meta-data name="android.telecom.IN_CALL_SERVICE_UI" value="true" />
              <intent-filter>
                <action name="android.telecom.InCallService" />
              </intent-filter>
            </service>
        </required-components>
        <permissions>
            <permission-set name="phone" />
+29 −0
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package com.android.permissioncontroller.role.model;

import android.app.AppOpsManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.UserHandle;
import android.telecom.TelecomManager;
import android.telephony.TelephonyManager;
@@ -28,6 +31,7 @@ import androidx.preference.Preference;

import com.android.permissioncontroller.R;
import com.android.permissioncontroller.permission.utils.CollectionUtils;
import com.android.permissioncontroller.role.utils.PackageUtils;

import java.util.Objects;

@@ -40,6 +44,10 @@ import java.util.Objects;
 */
public class DialerRoleBehavior implements RoleBehavior {

    private static final AppOp sAccessCallAudioOp = new AppOp(AppOpsManager.OPSTR_ACCESS_CALL_AUDIO,
                                                              null,
                                                              AppOpsManager.MODE_ALLOWED);

    @Override
    public boolean isAvailableAsUser(@NonNull Role role, @NonNull UserHandle user,
            @NonNull Context context) {
@@ -79,4 +87,25 @@ public class DialerRoleBehavior implements RoleBehavior {
            @NonNull Context context) {
        return context.getResources().getBoolean(R.bool.config_showDialerRole);
    }

    @Override
    public void grant(@NonNull Role role, @NonNull String packageName, @NonNull Context context) {
        PackageInfo packageInfo = PackageUtils.getPackageInfo(packageName,
                                                              PackageManager.GET_PERMISSIONS,
                                                              context);
        if (packageInfo == null) {
            return;
        }
        for (String permission : packageInfo.requestedPermissions) {
            if (Objects.equals(android.Manifest.permission.ACCESS_CALL_AUDIO, permission)) {
                sAccessCallAudioOp.grant(packageName, context);
                break;
            }
        }
    }

    @Override
    public void revoke(@NonNull Role role, @NonNull String packageName, @NonNull Context context) {
        sAccessCallAudioOp.revoke(packageName, context);
    }
}