Update associate API by adding certificate param

Fix: 184264581

Test: N/A
Change-Id: Ie28a2e68826744c0f020113d1b85b5a4b2d54c7f
This commit is contained in:
Guojing Yuan
2021-05-21 21:24:56 +00:00
parent 16cd6bb81f
commit cc4ffc849b
4 changed files with 19 additions and 5 deletions

View File

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

View File

@@ -442,13 +442,18 @@ public final class CompanionDeviceManager {
/**
* Associates given device with given app for the given user directly, without UI prompt.
*
* @param packageName package name of the companion app
* @param macAddress mac address of the device to associate
* @param certificate The SHA256 digest of the companion app's signing certificate
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.ASSOCIATE_COMPANION_DEVICES)
public void associate(
@NonNull String packageName,
@NonNull MacAddress macAddress) {
@NonNull MacAddress macAddress,
@NonNull byte[] certificate) {
if (!checkFeaturePresent()) {
return;
}
@@ -458,7 +463,7 @@ public final class CompanionDeviceManager {
UserHandle user = android.os.Process.myUserHandle();
try {
mService.createAssociation(
packageName, macAddress.toString(), user.getIdentifier());
packageName, macAddress.toString(), user.getIdentifier(), certificate);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}

View File

@@ -52,5 +52,6 @@ interface ICompanionDeviceManager {
boolean canPairWithoutPrompt(in String packageName, in String deviceMacAddress, int userId);
void createAssociation(in String packageName, in String macAddress, int userId);
void createAssociation(in String packageName, in String macAddress, int userId,
in byte[] certificate);
}

View File

@@ -20,6 +20,7 @@ package com.android.server.companion;
import static android.bluetooth.le.ScanSettings.CALLBACK_TYPE_ALL_MATCHES;
import static android.bluetooth.le.ScanSettings.SCAN_MODE_BALANCED;
import static android.content.Context.BIND_IMPORTANT;
import static android.content.pm.PackageManager.CERT_INPUT_SHA256;
import static android.content.pm.PackageManager.MATCH_ALL;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
@@ -657,7 +658,14 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
}
@Override
public void createAssociation(String packageName, String macAddress, int userId) {
public void createAssociation(String packageName, String macAddress, int userId,
byte[] certificate) {
if (!getContext().getPackageManager().hasSigningCertificate(
packageName, certificate, CERT_INPUT_SHA256)) {
Slog.e(LOG_TAG, "Given certificate doesn't match the package certificate.");
return;
}
getContext().enforceCallingOrSelfPermission(
android.Manifest.permission.ASSOCIATE_COMPANION_DEVICES, "createAssociation");