Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1211c67 authored by Evan Chen's avatar Evan Chen Committed by Android (Google) Code Review
Browse files

Merge "Make sure sendresult after association was created" into sc-v2-dev

parents 2bb5aa55 404168a4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -29,4 +29,6 @@ oneway interface ICompanionDeviceDiscoveryService {
        in String callingPackage,
        in IFindDeviceCallback findCallback,
        in AndroidFuture<Association> serviceCallback);

    void onAssociationCreated();
}
+7 −1
Original line number Diff line number Diff line
@@ -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();
    }

+10 −0
Original line number Diff line number Diff line
@@ -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);
    }
+3 −0
Original line number Diff line number Diff line
@@ -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());