Merge "Allow default dialer app to use the "phoneCall" FGS type." into udc-dev
This commit is contained in:
@@ -44,6 +44,7 @@ import android.annotation.NonNull;
|
|||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.compat.CompatChanges;
|
import android.app.compat.CompatChanges;
|
||||||
|
import android.app.role.RoleManager;
|
||||||
import android.compat.Compatibility;
|
import android.compat.Compatibility;
|
||||||
import android.compat.annotation.ChangeId;
|
import android.compat.annotation.ChangeId;
|
||||||
import android.compat.annotation.Disabled;
|
import android.compat.annotation.Disabled;
|
||||||
@@ -59,6 +60,7 @@ import android.hardware.usb.UsbDevice;
|
|||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.permission.PermissionCheckerManager;
|
import android.permission.PermissionCheckerManager;
|
||||||
import android.provider.DeviceConfig;
|
import android.provider.DeviceConfig;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -75,6 +77,7 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -334,7 +337,8 @@ public abstract class ForegroundServiceTypePolicy {
|
|||||||
new RegularPermission(Manifest.permission.FOREGROUND_SERVICE_PHONE_CALL)
|
new RegularPermission(Manifest.permission.FOREGROUND_SERVICE_PHONE_CALL)
|
||||||
}, true),
|
}, true),
|
||||||
new ForegroundServiceTypePermissions(new ForegroundServiceTypePermission[] {
|
new ForegroundServiceTypePermissions(new ForegroundServiceTypePermission[] {
|
||||||
new RegularPermission(Manifest.permission.MANAGE_OWN_CALLS)
|
new RegularPermission(Manifest.permission.MANAGE_OWN_CALLS),
|
||||||
|
new RolePermission(RoleManager.ROLE_DIALER)
|
||||||
}, false),
|
}, false),
|
||||||
FGS_TYPE_PERM_ENFORCEMENT_FLAG_PHONE_CALL /* permissionEnforcementFlag */,
|
FGS_TYPE_PERM_ENFORCEMENT_FLAG_PHONE_CALL /* permissionEnforcementFlag */,
|
||||||
true /* permissionEnforcementFlagDefaultValue */
|
true /* permissionEnforcementFlagDefaultValue */
|
||||||
@@ -1130,6 +1134,29 @@ public abstract class ForegroundServiceTypePolicy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This represents a particular role an app needs to hold for a specific service type.
|
||||||
|
*/
|
||||||
|
static class RolePermission extends ForegroundServiceTypePermission {
|
||||||
|
final String mRole;
|
||||||
|
|
||||||
|
RolePermission(@NonNull String role) {
|
||||||
|
super(role);
|
||||||
|
mRole = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@PackageManager.PermissionResult
|
||||||
|
public int checkPermission(@NonNull Context context, int callerUid, int callerPid,
|
||||||
|
String packageName, boolean allowWhileInUse) {
|
||||||
|
final RoleManager rm = context.getSystemService(RoleManager.class);
|
||||||
|
final List<String> holders = rm.getRoleHoldersAsUser(mRole,
|
||||||
|
UserHandle.getUserHandleForUid(callerUid));
|
||||||
|
return holders != null && holders.contains(packageName)
|
||||||
|
? PERMISSION_GRANTED : PERMISSION_DENIED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This represents a special Android permission to be required for accessing usb devices.
|
* This represents a special Android permission to be required for accessing usb devices.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -168,7 +168,8 @@ public class ServiceInfo extends ComponentInfo
|
|||||||
* <p>Starting foreground service with this type from apps targeting API level
|
* <p>Starting foreground service with this type from apps targeting API level
|
||||||
* {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} and later, will require permission
|
* {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} and later, will require permission
|
||||||
* {@link android.Manifest.permission#FOREGROUND_SERVICE_PHONE_CALL} and
|
* {@link android.Manifest.permission#FOREGROUND_SERVICE_PHONE_CALL} and
|
||||||
* {@link android.Manifest.permission#MANAGE_OWN_CALLS}.
|
* {@link android.Manifest.permission#MANAGE_OWN_CALLS} or holding the default
|
||||||
|
* {@link android.app.role.RoleManager#ROLE_DIALER dialer role}.
|
||||||
*/
|
*/
|
||||||
@RequiresPermission(
|
@RequiresPermission(
|
||||||
allOf = {
|
allOf = {
|
||||||
|
|||||||
@@ -1618,7 +1618,8 @@
|
|||||||
{@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} and above, starting a foreground
|
{@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} and above, starting a foreground
|
||||||
service with this type will require permission
|
service with this type will require permission
|
||||||
{@link android.Manifest.permission#FOREGROUND_SERVICE_PHONE_CALL} and
|
{@link android.Manifest.permission#FOREGROUND_SERVICE_PHONE_CALL} and
|
||||||
{@link android.Manifest.permission#MANAGE_OWN_CALLS}.
|
{@link android.Manifest.permission#MANAGE_OWN_CALLS} or holding the default
|
||||||
|
{@link android.app.role.RoleManager#ROLE_DIALER dialer role}.
|
||||||
-->
|
-->
|
||||||
<flag name="phoneCall" value="0x04" />
|
<flag name="phoneCall" value="0x04" />
|
||||||
<!-- GPS, map, navigation location update.
|
<!-- GPS, map, navigation location update.
|
||||||
|
|||||||
Reference in New Issue
Block a user