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 String callingPackage,
|
||||||
in IFindDeviceCallback findCallback,
|
in IFindDeviceCallback findCallback,
|
||||||
in AndroidFuture<String> serviceCallback);
|
in AndroidFuture<String> serviceCallback);
|
||||||
|
|
||||||
|
void onAssociationCreated();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -254,8 +254,14 @@ public class CompanionDeviceActivity extends Activity {
|
|||||||
Log.i(LOG_TAG, "onDeviceConfirmed(selectedDevice = " + selectedDevice + ")");
|
Log.i(LOG_TAG, "onDeviceConfirmed(selectedDevice = " + selectedDevice + ")");
|
||||||
getService().onDeviceSelected(
|
getService().onDeviceSelected(
|
||||||
getCallingPackage(), getDeviceMacAddress(selectedDevice.device));
|
getCallingPackage(), getDeviceMacAddress(selectedDevice.device));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setResultAndFinish() {
|
||||||
|
Log.i(LOG_TAG, "setResultAndFinish(selectedDevice = "
|
||||||
|
+ getService().mSelectedDevice.device + ")");
|
||||||
setResult(RESULT_OK,
|
setResult(RESULT_OK,
|
||||||
new Intent().putExtra(CompanionDeviceManager.EXTRA_DEVICE, selectedDevice.device));
|
new Intent().putExtra(
|
||||||
|
CompanionDeviceManager.EXTRA_DEVICE, getService().mSelectedDevice.device));
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,11 @@ public class CompanionDeviceDiscoveryService extends Service {
|
|||||||
CompanionDeviceDiscoveryService::startDiscovery,
|
CompanionDeviceDiscoveryService::startDiscovery,
|
||||||
CompanionDeviceDiscoveryService.this, request));
|
CompanionDeviceDiscoveryService.this, request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAssociationCreated() {
|
||||||
|
Handler.getMain().post(CompanionDeviceDiscoveryService.this::onAssociationCreated);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private ScanCallback mBLEScanCallback;
|
private ScanCallback mBLEScanCallback;
|
||||||
@@ -221,6 +226,11 @@ public class CompanionDeviceDiscoveryService extends Service {
|
|||||||
SCAN_TIMEOUT);
|
SCAN_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainThread
|
||||||
|
private void onAssociationCreated() {
|
||||||
|
mActivity.setResultAndFinish();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean shouldScan(List<? extends DeviceFilter> mediumSpecificFilters) {
|
private boolean shouldScan(List<? extends DeviceFilter> mediumSpecificFilters) {
|
||||||
return !isEmpty(mediumSpecificFilters) || isEmpty(mFilters);
|
return !isEmpty(mediumSpecificFilters) || isEmpty(mFilters);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,6 +154,9 @@ class AssociationRequestsProcessor {
|
|||||||
if (err == null) {
|
if (err == null) {
|
||||||
mService.createAssociationInternal(
|
mService.createAssociationInternal(
|
||||||
userId, deviceAddress, callingPackage, deviceProfile);
|
userId, deviceAddress, callingPackage, deviceProfile);
|
||||||
|
mServiceConnectors.forUser(userId).post(service -> {
|
||||||
|
service.onAssociationCreated();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
Slog.e(TAG, "Failed to discover device(s)", err);
|
Slog.e(TAG, "Failed to discover device(s)", err);
|
||||||
callback.onFailure("No devices found: " + err.getMessage());
|
callback.onFailure("No devices found: " + err.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user