Do not create Associtions in CompanionDeviceDiscoveryService
Since and T Associations objects will have the ID feilds. These IDs must be unique, and will be assigned by the CdmService. To make this possible all new Associations objects (records) should be created by the CdmService. At the moment, however, CompanionDeviceDiscoveryService also creates Associations objects. Change ICompanionDeviceDiscoveryService interface, so that when it discovers a device reports back to the CdmService only the mac address of the device, instead of a fully constructed Association object. CdmService will take the address and creates an Association itself. Bug: 197933995 Test: make Change-Id: I4af928a7bc1c690bc7c3c7c50ec896884e10e3bd
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package android.companion;
|
||||
|
||||
import android.companion.Association;
|
||||
import android.companion.AssociationRequest;
|
||||
import android.companion.IFindDeviceCallback;
|
||||
import com.android.internal.infra.AndroidFuture;
|
||||
@@ -28,5 +27,5 @@ oneway interface ICompanionDeviceDiscoveryService {
|
||||
in AssociationRequest request,
|
||||
in String callingPackage,
|
||||
in IFindDeviceCallback findCallback,
|
||||
in AndroidFuture<Association> serviceCallback);
|
||||
in AndroidFuture<String> serviceCallback);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ import android.bluetooth.le.ScanCallback;
|
||||
import android.bluetooth.le.ScanFilter;
|
||||
import android.bluetooth.le.ScanResult;
|
||||
import android.bluetooth.le.ScanSettings;
|
||||
import android.companion.Association;
|
||||
import android.companion.AssociationRequest;
|
||||
import android.companion.BluetoothDeviceFilter;
|
||||
import android.companion.BluetoothLeDeviceFilter;
|
||||
@@ -95,7 +94,7 @@ public class CompanionDeviceDiscoveryService extends Service {
|
||||
DeviceFilterPair mSelectedDevice;
|
||||
IFindDeviceCallback mFindCallback;
|
||||
|
||||
AndroidFuture<Association> mServiceCallback;
|
||||
AndroidFuture<String> mServiceCallback;
|
||||
boolean mIsScanning = false;
|
||||
@Nullable
|
||||
CompanionDeviceActivity mActivity = null;
|
||||
@@ -106,7 +105,7 @@ public class CompanionDeviceDiscoveryService extends Service {
|
||||
public void startDiscovery(AssociationRequest request,
|
||||
String callingPackage,
|
||||
IFindDeviceCallback findCallback,
|
||||
AndroidFuture serviceCallback) {
|
||||
AndroidFuture<String> serviceCallback) {
|
||||
Log.i(LOG_TAG,
|
||||
"startDiscovery() called with: filter = [" + request
|
||||
+ "], findCallback = [" + findCallback + "]"
|
||||
@@ -320,9 +319,7 @@ public class CompanionDeviceDiscoveryService extends Service {
|
||||
if (callingPackage == null || deviceAddress == null) {
|
||||
return;
|
||||
}
|
||||
mServiceCallback.complete(new Association(
|
||||
getUserId(), deviceAddress, callingPackage, mRequest.getDeviceProfile(), false,
|
||||
System.currentTimeMillis()));
|
||||
mServiceCallback.complete(deviceAddress);
|
||||
}
|
||||
|
||||
void onCancel() {
|
||||
|
||||
@@ -208,7 +208,7 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
|
||||
private ScanCallback mBleScanCallback = new BleScanCallback();
|
||||
private AssociationRequest mRequest;
|
||||
private String mCallingPackage;
|
||||
private AndroidFuture<Association> mOngoingDeviceDiscovery;
|
||||
private AndroidFuture<?> mOngoingDeviceDiscovery;
|
||||
private PermissionControllerManager mPermissionControllerManager;
|
||||
|
||||
private BluetoothDeviceConnectedListener mBluetoothDeviceConnectedListener =
|
||||
@@ -383,7 +383,7 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
|
||||
Slog.d(LOG_TAG, "cleanup(); discovery = "
|
||||
+ mOngoingDeviceDiscovery + ", request = " + mRequest);
|
||||
synchronized (mLock) {
|
||||
AndroidFuture<Association> ongoingDeviceDiscovery = mOngoingDeviceDiscovery;
|
||||
AndroidFuture<?> ongoingDeviceDiscovery = mOngoingDeviceDiscovery;
|
||||
if (ongoingDeviceDiscovery != null && !ongoingDeviceDiscovery.isDone()) {
|
||||
ongoingDeviceDiscovery.cancel(true);
|
||||
}
|
||||
@@ -458,13 +458,16 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
|
||||
return mServiceConnectors.forUser(userId).postAsync(service -> {
|
||||
Slog.d(LOG_TAG, "Connected to CDM service; starting discovery for " + request);
|
||||
|
||||
AndroidFuture<Association> future = new AndroidFuture<>();
|
||||
AndroidFuture<String> future = new AndroidFuture<>();
|
||||
service.startDiscovery(request, callingPackage, callback, future);
|
||||
return future;
|
||||
}).cancelTimeout();
|
||||
|
||||
}, FgThread.getExecutor()).whenComplete(uncheckExceptions((association, err) -> {
|
||||
}, FgThread.getExecutor()).whenComplete(uncheckExceptions((deviceAddress, err) -> {
|
||||
if (err == null) {
|
||||
Association association = new Association(userId, deviceAddress, callingPackage,
|
||||
mRequest.getDeviceProfile(), false,
|
||||
System.currentTimeMillis());
|
||||
addAssociation(association, userId);
|
||||
} else {
|
||||
Slog.e(LOG_TAG, "Failed to discover device(s)", err);
|
||||
|
||||
Reference in New Issue
Block a user