Merge "Make sure sendresult after association was created" into sc-v2-dev
This commit is contained in:
@@ -29,4 +29,6 @@ oneway interface ICompanionDeviceDiscoveryService {
|
||||
in String callingPackage,
|
||||
in IFindDeviceCallback findCallback,
|
||||
in AndroidFuture<Association> 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +117,11 @@ public class CompanionDeviceDiscoveryService extends Service {
|
||||
CompanionDeviceDiscoveryService::startDiscovery,
|
||||
CompanionDeviceDiscoveryService.this, request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAssociationCreated() {
|
||||
Handler.getMain().post(CompanionDeviceDiscoveryService.this::onAssociationCreated);
|
||||
}
|
||||
};
|
||||
|
||||
private ScanCallback mBLEScanCallback;
|
||||
@@ -222,6 +227,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);
|
||||
}
|
||||
|
||||
@@ -457,6 +457,9 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
|
||||
}, FgThread.getExecutor()).whenComplete(uncheckExceptions((association, err) -> {
|
||||
if (err == null) {
|
||||
addAssociation(association, userId);
|
||||
mServiceConnectors.forUser(userId).post(service -> {
|
||||
service.onAssociationCreated();
|
||||
});
|
||||
} else {
|
||||
Slog.e(LOG_TAG, "Failed to discover device(s)", err);
|
||||
callback.onFailure("No devices found: " + err.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user