Merge "Provide CDM API to associate without prompt" into sc-dev

This commit is contained in:
Eugene Susla
2021-03-24 20:56:54 +00:00
committed by Android (Google) Code Review
7 changed files with 52 additions and 0 deletions

View File

@@ -2180,6 +2180,7 @@ package android.bluetooth.le {
package android.companion {
public final class CompanionDeviceManager {
method @RequiresPermission("android.permission.ASSOCIATE_COMPANION_DEVICES") public boolean associate(@NonNull String, @NonNull android.net.MacAddress);
method @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public boolean canPairWithoutPrompt(@NonNull String, @NonNull String, int);
method @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public boolean isDeviceAssociatedForWifiConnection(@NonNull String, @NonNull android.net.MacAddress, @NonNull android.os.UserHandle);
}

View File

@@ -425,6 +425,32 @@ public final class CompanionDeviceManager {
mContext.getPackageName(), deviceAddress);
} catch (RemoteException e) {
ExceptionUtils.propagateIfInstanceOf(e.getCause(), DeviceNotAssociatedException.class);
}
}
/**
* Associates given device with given app for the given user directly, without UI prompt.
*
* @return whether successful
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.ASSOCIATE_COMPANION_DEVICES)
public boolean associate(
@NonNull String packageName,
@NonNull MacAddress macAddress) {
if (!checkFeaturePresent()) {
return false;
}
Objects.requireNonNull(packageName, "package name cannot be null");
Objects.requireNonNull(macAddress, "mac address cannot be null");
UserHandle user = android.os.Process.myUserHandle();
try {
return mService.createAssociation(
packageName, macAddress.toString(), user.getIdentifier());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}

View File

@@ -51,4 +51,6 @@ interface ICompanionDeviceManager {
void unregisterDevicePresenceListenerService(in String packageName, in String deviceAddress);
boolean canPairWithoutPrompt(in String packageName, in String deviceMacAddress, int userId);
boolean createAssociation(in String packageName, in String macAddress, int userId);
}

View File

@@ -4227,6 +4227,11 @@
<permission android:name="android.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE"
android:protectionLevel="normal" />
<!-- Allows an application to create new companion device associations.
@hide -->
<permission android:name="android.permission.ASSOCIATE_COMPANION_DEVICES"
android:protectionLevel="internal|role" />
<!-- @SystemApi Allows an application to use SurfaceFlinger's low level features.
<p>Not for use by third-party applications.
@hide

View File

@@ -3732,6 +3732,13 @@
-->
<string name="config_defaultWellbeingPackage" translatable="false"></string>
<!-- The package name for the companion provider app.
This package must be trusted, as it has the permissions to associate apps with devices
without a UI prompt.
Example: "com.google.android.gms"
-->
<string name="config_companionProviderPackage" translatable="false"></string>
<!-- The component name for the default system attention service.
This service must be trusted, as it can be activated without explicit consent of the user.
See android.attention.AttentionManagerService.

View File

@@ -3536,6 +3536,7 @@
<java-symbol type="string" name="notification_channel_do_not_disturb" />
<java-symbol type="string" name="notification_channel_accessibility_magnification" />
<java-symbol type="string" name="notification_channel_accessibility_security_policy" />
<java-symbol type="string" name="config_companionProviderPackage" />
<java-symbol type="string" name="config_defaultAutofillService" />
<java-symbol type="string" name="config_defaultOnDeviceSpeechRecognitionService" />
<java-symbol type="string" name="config_defaultTextClassifierPackage" />

View File

@@ -639,6 +639,16 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
}));
}
@Override
public boolean createAssociation(String packageName, String macAddress, int userId) {
getContext().enforceCallingOrSelfPermission(
android.Manifest.permission.ASSOCIATE_COMPANION_DEVICES, "createAssociation");
addAssociation(new Association(
userId, macAddress, packageName, null, false, System.currentTimeMillis()));
return true;
}
private void checkCanCallNotificationApi(String callingPackage) throws RemoteException {
checkCallerIsSystemOr(callingPackage);
int userId = getCallingUserId();