[CDM perm sync] Skip user consent for the same OEM devices
Bug: 193583135 Test: manually tested the CDM test app and Pixel watch app Change-Id: Ic0633860856afa881ac78798acc079d99405438c
This commit is contained in:
@@ -47,7 +47,6 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentSender;
|
import android.content.IntentSender;
|
||||||
import android.content.pm.PackageManagerInternal;
|
import android.content.pm.PackageManagerInternal;
|
||||||
import android.content.pm.Signature;
|
|
||||||
import android.net.MacAddress;
|
import android.net.MacAddress;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -55,17 +54,11 @@ import android.os.Handler;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.util.Log;
|
|
||||||
import android.util.PackageUtils;
|
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
import com.android.internal.util.ArrayUtils;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class responsible for handling incoming {@link AssociationRequest}s.
|
* Class responsible for handling incoming {@link AssociationRequest}s.
|
||||||
@@ -449,31 +442,6 @@ class AssociationRequestsProcessor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private boolean mayAssociateWithoutPrompt(@NonNull String packageName, @UserIdInt int userId) {
|
private boolean mayAssociateWithoutPrompt(@NonNull String packageName, @UserIdInt int userId) {
|
||||||
// Below we check if the requesting package is allowlisted (usually by the OEM) for creating
|
|
||||||
// CDM associations without user confirmation (prompt).
|
|
||||||
// For this we'll check to config arrays:
|
|
||||||
// - com.android.internal.R.array.config_companionDevicePackages
|
|
||||||
// and
|
|
||||||
// - com.android.internal.R.array.config_companionDeviceCerts.
|
|
||||||
// Both arrays are expected to contain similar number of entries.
|
|
||||||
// config_companionDevicePackages contains package names of the allowlisted packages.
|
|
||||||
// config_companionDeviceCerts contains SHA256 digests of the signatures of the
|
|
||||||
// corresponding packages.
|
|
||||||
// If a package may be signed with one of several certificates, its package name would
|
|
||||||
// appear multiple times in the config_companionDevicePackages, with different entries
|
|
||||||
// (one for each of the valid signing certificates) at the corresponding positions in
|
|
||||||
// config_companionDeviceCerts.
|
|
||||||
final String[] allowlistedPackages = mContext.getResources()
|
|
||||||
.getStringArray(com.android.internal.R.array.config_companionDevicePackages);
|
|
||||||
if (!ArrayUtils.contains(allowlistedPackages, packageName)) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, packageName + " is not allowlisted for creating associations "
|
|
||||||
+ "without user confirmation (prompt)");
|
|
||||||
Log.v(TAG, "Allowlisted packages=" + Arrays.toString(allowlistedPackages));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Throttle frequent associations
|
// Throttle frequent associations
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
final List<AssociationInfo> associationForPackage =
|
final List<AssociationInfo> associationForPackage =
|
||||||
@@ -493,40 +461,6 @@ class AssociationRequestsProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] allowlistedPackagesSignatureDigests = mContext.getResources()
|
return PackageUtils.isPackageAllowlisted(mContext, mPackageManager, packageName);
|
||||||
.getStringArray(com.android.internal.R.array.config_companionDeviceCerts);
|
|
||||||
final Set<String> allowlistedSignatureDigestsForRequestingPackage = new HashSet<>();
|
|
||||||
for (int i = 0; i < allowlistedPackages.length; i++) {
|
|
||||||
if (allowlistedPackages[i].equals(packageName)) {
|
|
||||||
final String digest = allowlistedPackagesSignatureDigests[i].replaceAll(":", "");
|
|
||||||
allowlistedSignatureDigestsForRequestingPackage.add(digest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final Signature[] requestingPackageSignatures = mPackageManager.getPackage(packageName)
|
|
||||||
.getSigningDetails().getSignatures();
|
|
||||||
final String[] requestingPackageSignatureDigests =
|
|
||||||
PackageUtils.computeSignaturesSha256Digests(requestingPackageSignatures);
|
|
||||||
|
|
||||||
boolean requestingPackageSignatureAllowlisted = false;
|
|
||||||
for (String signatureDigest : requestingPackageSignatureDigests) {
|
|
||||||
if (allowlistedSignatureDigestsForRequestingPackage.contains(signatureDigest)) {
|
|
||||||
requestingPackageSignatureAllowlisted = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!requestingPackageSignatureAllowlisted) {
|
|
||||||
Slog.w(TAG, "Certificate mismatch for allowlisted package " + packageName);
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, " > allowlisted signatures for " + packageName + ": ["
|
|
||||||
+ String.join(", ", allowlistedSignatureDigestsForRequestingPackage)
|
|
||||||
+ "]");
|
|
||||||
Log.d(TAG, " > actual signatures for " + packageName + ": "
|
|
||||||
+ Arrays.toString(requestingPackageSignatureDigests));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return requestingPackageSignatureAllowlisted;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -247,7 +247,8 @@ public class CompanionDeviceManagerService extends SystemService {
|
|||||||
mCompanionAppController = new CompanionApplicationController(
|
mCompanionAppController = new CompanionApplicationController(
|
||||||
context, mAssociationStore, mDevicePresenceMonitor);
|
context, mAssociationStore, mDevicePresenceMonitor);
|
||||||
mTransportManager = new CompanionTransportManager(context, mAssociationStore);
|
mTransportManager = new CompanionTransportManager(context, mAssociationStore);
|
||||||
mSystemDataTransferProcessor = new SystemDataTransferProcessor(this, mAssociationStore,
|
mSystemDataTransferProcessor = new SystemDataTransferProcessor(this,
|
||||||
|
mPackageManagerInternal, mAssociationStore,
|
||||||
mSystemDataTransferRequestStore, mTransportManager);
|
mSystemDataTransferRequestStore, mTransportManager);
|
||||||
// TODO(b/279663946): move context sync to a dedicated system service
|
// TODO(b/279663946): move context sync to a dedicated system service
|
||||||
mCrossDeviceSyncController = new CrossDeviceSyncController(getContext(), mTransportManager);
|
mCrossDeviceSyncController = new CrossDeviceSyncController(getContext(), mTransportManager);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import static android.content.pm.PackageManager.FEATURE_COMPANION_DEVICE_SETUP;
|
|||||||
import static android.content.pm.PackageManager.GET_CONFIGURATIONS;
|
import static android.content.pm.PackageManager.GET_CONFIGURATIONS;
|
||||||
import static android.content.pm.PackageManager.GET_PERMISSIONS;
|
import static android.content.pm.PackageManager.GET_PERMISSIONS;
|
||||||
|
|
||||||
|
import static com.android.server.companion.CompanionDeviceManagerService.DEBUG;
|
||||||
import static com.android.server.companion.CompanionDeviceManagerService.TAG;
|
import static com.android.server.companion.CompanionDeviceManagerService.TAG;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
@@ -35,20 +36,28 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.PackageInfoFlags;
|
import android.content.pm.PackageManager.PackageInfoFlags;
|
||||||
import android.content.pm.PackageManager.ResolveInfoFlags;
|
import android.content.pm.PackageManager.ResolveInfoFlags;
|
||||||
|
import android.content.pm.PackageManagerInternal;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
|
import android.content.pm.Signature;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
|
import com.android.internal.util.ArrayUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods for working with {@link PackageInfo}-s.
|
* Utility methods for working with {@link PackageInfo}-s.
|
||||||
*/
|
*/
|
||||||
final class PackageUtils {
|
public final class PackageUtils {
|
||||||
private static final Intent COMPANION_SERVICE_INTENT =
|
private static final Intent COMPANION_SERVICE_INTENT =
|
||||||
new Intent(CompanionDeviceService.SERVICE_INTERFACE);
|
new Intent(CompanionDeviceService.SERVICE_INTERFACE);
|
||||||
private static final String PROPERTY_PRIMARY_TAG =
|
private static final String PROPERTY_PRIMARY_TAG =
|
||||||
@@ -141,4 +150,69 @@ final class PackageUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the package is allowlisted in the overlay config.
|
||||||
|
* For this we'll check to config arrays:
|
||||||
|
* - com.android.internal.R.array.config_companionDevicePackages
|
||||||
|
* and
|
||||||
|
* - com.android.internal.R.array.config_companionDeviceCerts.
|
||||||
|
* Both arrays are expected to contain similar number of entries.
|
||||||
|
* config_companionDevicePackages contains package names of the allowlisted packages.
|
||||||
|
* config_companionDeviceCerts contains SHA256 digests of the signatures of the
|
||||||
|
* corresponding packages.
|
||||||
|
* If a package is signed with one of several certificates, its package name would
|
||||||
|
* appear multiple times in the config_companionDevicePackages, with different entries
|
||||||
|
* (one for each of the valid signing certificates) at the corresponding positions in
|
||||||
|
* config_companionDeviceCerts.
|
||||||
|
*/
|
||||||
|
public static boolean isPackageAllowlisted(Context context,
|
||||||
|
PackageManagerInternal packageManagerInternal, @NonNull String packageName) {
|
||||||
|
final String[] allowlistedPackages = context.getResources()
|
||||||
|
.getStringArray(com.android.internal.R.array.config_companionDevicePackages);
|
||||||
|
if (!ArrayUtils.contains(allowlistedPackages, packageName)) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, packageName + " is not allowlisted.");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String[] allowlistedPackagesSignatureDigests = context.getResources()
|
||||||
|
.getStringArray(com.android.internal.R.array.config_companionDeviceCerts);
|
||||||
|
final Set<String> allowlistedSignatureDigestsForRequestingPackage = new HashSet<>();
|
||||||
|
for (int i = 0; i < allowlistedPackages.length; i++) {
|
||||||
|
if (allowlistedPackages[i].equals(packageName)) {
|
||||||
|
final String digest = allowlistedPackagesSignatureDigests[i].replaceAll(":", "");
|
||||||
|
allowlistedSignatureDigestsForRequestingPackage.add(digest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final Signature[] requestingPackageSignatures = packageManagerInternal.getPackage(
|
||||||
|
packageName)
|
||||||
|
.getSigningDetails().getSignatures();
|
||||||
|
final String[] requestingPackageSignatureDigests =
|
||||||
|
android.util.PackageUtils.computeSignaturesSha256Digests(
|
||||||
|
requestingPackageSignatures);
|
||||||
|
|
||||||
|
boolean requestingPackageSignatureAllowlisted = false;
|
||||||
|
for (String signatureDigest : requestingPackageSignatureDigests) {
|
||||||
|
if (allowlistedSignatureDigestsForRequestingPackage.contains(signatureDigest)) {
|
||||||
|
requestingPackageSignatureAllowlisted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!requestingPackageSignatureAllowlisted) {
|
||||||
|
Slog.w(TAG, "Certificate mismatch for allowlisted package " + packageName);
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, " > allowlisted signatures for " + packageName + ": ["
|
||||||
|
+ String.join(", ", allowlistedSignatureDigestsForRequestingPackage)
|
||||||
|
+ "]");
|
||||||
|
Log.d(TAG, " > actual signatures for " + packageName + ": "
|
||||||
|
+ Arrays.toString(requestingPackageSignatureDigests));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return requestingPackageSignatureAllowlisted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import android.companion.datatransfer.SystemDataTransferRequest;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManagerInternal;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -50,6 +51,7 @@ import android.util.Slog;
|
|||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
import com.android.server.companion.AssociationStore;
|
import com.android.server.companion.AssociationStore;
|
||||||
import com.android.server.companion.CompanionDeviceManagerService;
|
import com.android.server.companion.CompanionDeviceManagerService;
|
||||||
|
import com.android.server.companion.PackageUtils;
|
||||||
import com.android.server.companion.PermissionsUtils;
|
import com.android.server.companion.PermissionsUtils;
|
||||||
import com.android.server.companion.transport.CompanionTransportManager;
|
import com.android.server.companion.transport.CompanionTransportManager;
|
||||||
|
|
||||||
@@ -77,6 +79,7 @@ public class SystemDataTransferProcessor {
|
|||||||
"system_data_transfer_result_receiver";
|
"system_data_transfer_result_receiver";
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
private final PackageManagerInternal mPackageManager;
|
||||||
private final AssociationStore mAssociationStore;
|
private final AssociationStore mAssociationStore;
|
||||||
private final SystemDataTransferRequestStore mSystemDataTransferRequestStore;
|
private final SystemDataTransferRequestStore mSystemDataTransferRequestStore;
|
||||||
private final CompanionTransportManager mTransportManager;
|
private final CompanionTransportManager mTransportManager;
|
||||||
@@ -85,10 +88,12 @@ public class SystemDataTransferProcessor {
|
|||||||
private final ComponentName mCompanionDeviceDataTransferActivity;
|
private final ComponentName mCompanionDeviceDataTransferActivity;
|
||||||
|
|
||||||
public SystemDataTransferProcessor(CompanionDeviceManagerService service,
|
public SystemDataTransferProcessor(CompanionDeviceManagerService service,
|
||||||
|
PackageManagerInternal packageManager,
|
||||||
AssociationStore associationStore,
|
AssociationStore associationStore,
|
||||||
SystemDataTransferRequestStore systemDataTransferRequestStore,
|
SystemDataTransferRequestStore systemDataTransferRequestStore,
|
||||||
CompanionTransportManager transportManager) {
|
CompanionTransportManager transportManager) {
|
||||||
mContext = service.getContext();
|
mContext = service.getContext();
|
||||||
|
mPackageManager = packageManager;
|
||||||
mAssociationStore = associationStore;
|
mAssociationStore = associationStore;
|
||||||
mSystemDataTransferRequestStore = systemDataTransferRequestStore;
|
mSystemDataTransferRequestStore = systemDataTransferRequestStore;
|
||||||
mTransportManager = transportManager;
|
mTransportManager = transportManager;
|
||||||
@@ -132,6 +137,11 @@ public class SystemDataTransferProcessor {
|
|||||||
*/
|
*/
|
||||||
public PendingIntent buildPermissionTransferUserConsentIntent(String packageName,
|
public PendingIntent buildPermissionTransferUserConsentIntent(String packageName,
|
||||||
@UserIdInt int userId, int associationId) {
|
@UserIdInt int userId, int associationId) {
|
||||||
|
if (PackageUtils.isPackageAllowlisted(mContext, mPackageManager, packageName)) {
|
||||||
|
Slog.i(LOG_TAG, "User consent Intent should be skipped. Returning null.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
final AssociationInfo association = resolveAssociation(packageName, userId, associationId);
|
final AssociationInfo association = resolveAssociation(packageName, userId, associationId);
|
||||||
|
|
||||||
Slog.i(LOG_TAG, "Creating permission sync intent for userId [" + userId
|
Slog.i(LOG_TAG, "Creating permission sync intent for userId [" + userId
|
||||||
@@ -175,12 +185,16 @@ public class SystemDataTransferProcessor {
|
|||||||
final AssociationInfo association = resolveAssociation(packageName, userId, associationId);
|
final AssociationInfo association = resolveAssociation(packageName, userId, associationId);
|
||||||
|
|
||||||
// Check if the request has been consented by the user.
|
// Check if the request has been consented by the user.
|
||||||
|
if (PackageUtils.isPackageAllowlisted(mContext, mPackageManager, packageName)) {
|
||||||
|
Slog.i(LOG_TAG, "Skip user consent check due to the same OEM package.");
|
||||||
|
} else {
|
||||||
List<SystemDataTransferRequest> storedRequests =
|
List<SystemDataTransferRequest> storedRequests =
|
||||||
mSystemDataTransferRequestStore.readRequestsByAssociationId(userId,
|
mSystemDataTransferRequestStore.readRequestsByAssociationId(userId,
|
||||||
associationId);
|
associationId);
|
||||||
boolean hasConsented = false;
|
boolean hasConsented = false;
|
||||||
for (SystemDataTransferRequest storedRequest : storedRequests) {
|
for (SystemDataTransferRequest storedRequest : storedRequests) {
|
||||||
if (storedRequest instanceof PermissionSyncRequest && storedRequest.isUserConsented()) {
|
if (storedRequest instanceof PermissionSyncRequest
|
||||||
|
&& storedRequest.isUserConsented()) {
|
||||||
hasConsented = true;
|
hasConsented = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -190,9 +204,11 @@ public class SystemDataTransferProcessor {
|
|||||||
Slog.e(LOG_TAG, message);
|
Slog.e(LOG_TAG, message);
|
||||||
try {
|
try {
|
||||||
callback.onError(message);
|
callback.onError(message);
|
||||||
} catch (RemoteException ignored) { }
|
} catch (RemoteException ignored) {
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Start permission sync
|
// Start permission sync
|
||||||
final long callingIdentityToken = Binder.clearCallingIdentity();
|
final long callingIdentityToken = Binder.clearCallingIdentity();
|
||||||
|
|||||||
Reference in New Issue
Block a user