Make sure sendresult after association was created
Add a new method to send activity result in CompanionDeviceDiscoveryService and make sure CDMService to call it before addAssociation. Bug: 203418937 Test: atest CtsOsTestCases:android.os.cts.CompanionDeviceManagerTest Change-Id: Ied7d705934418869287a8be6cd44abe3b806db00
This commit is contained in:
@@ -28,4 +28,6 @@ oneway interface ICompanionDeviceDiscoveryService {
|
||||
in String callingPackage,
|
||||
in IFindDeviceCallback findCallback,
|
||||
in AndroidFuture<String> serviceCallback);
|
||||
|
||||
void onAssociationCreated();
|
||||
}
|
||||
|
||||
@@ -254,8 +254,14 @@ public class CompanionDeviceActivity extends Activity {
|
||||
Log.i(LOG_TAG, "onDeviceConfirmed(selectedDevice = " + selectedDevice + ")");
|
||||
getService().onDeviceSelected(
|
||||
getCallingPackage(), getDeviceMacAddress(selectedDevice.device));
|
||||
}
|
||||
|
||||
void setResultAndFinish() {
|
||||
Log.i(LOG_TAG, "setResultAndFinish(selectedDevice = "
|
||||
+ getService().mSelectedDevice.device + ")");
|
||||
setResult(RESULT_OK,
|
||||
new Intent().putExtra(CompanionDeviceManager.EXTRA_DEVICE, selectedDevice.device));
|
||||
new Intent().putExtra(
|
||||
CompanionDeviceManager.EXTRA_DEVICE, getService().mSelectedDevice.device));
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
@@ -116,6 +116,11 @@ public class CompanionDeviceDiscoveryService extends Service {
|
||||
CompanionDeviceDiscoveryService::startDiscovery,
|
||||
CompanionDeviceDiscoveryService.this, request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAssociationCreated() {
|
||||
Handler.getMain().post(CompanionDeviceDiscoveryService.this::onAssociationCreated);
|
||||
}
|
||||
};
|
||||
|
||||
private ScanCallback mBLEScanCallback;
|
||||
@@ -221,6 +226,11 @@ public class CompanionDeviceDiscoveryService extends Service {
|
||||
SCAN_TIMEOUT);
|
||||
}
|
||||
|
||||
@MainThread
|
||||
private void onAssociationCreated() {
|
||||
mActivity.setResultAndFinish();
|
||||
}
|
||||
|
||||
private boolean shouldScan(List<? extends DeviceFilter> mediumSpecificFilters) {
|
||||
return !isEmpty(mediumSpecificFilters) || isEmpty(mFilters);
|
||||
}
|
||||
|
||||
@@ -154,6 +154,9 @@ class AssociationRequestsProcessor {
|
||||
if (err == null) {
|
||||
mService.createAssociationInternal(
|
||||
userId, deviceAddress, callingPackage, deviceProfile);
|
||||
mServiceConnectors.forUser(userId).post(service -> {
|
||||
service.onAssociationCreated();
|
||||
});
|
||||
} else {
|
||||
Slog.e(TAG, "Failed to discover device(s)", err);
|
||||
callback.onFailure("No devices found: " + err.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user