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

Commit 4cc34d76 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Stop scan on device chooser activity backgrounded"

parents b58ce251 098a0450
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -19,4 +19,5 @@ package android.companion;
/** @hide */
interface ICompanionDeviceDiscoveryServiceCallback {
    oneway void onDeviceSelected(String packageName, int userId, String deviceAddress);
    oneway void onDeviceSelectionCancel();
}
+16 −6
Original line number Diff line number Diff line
@@ -79,15 +79,25 @@ public class DeviceChooserActivity extends Activity {
        }

        mPairButton = findViewById(R.id.button_pair);
        mPairButton.setOnClickListener((view) ->
                onPairTapped(getService().mSelectedDevice));
        mPairButton.setOnClickListener(v -> onPairTapped(getService().mSelectedDevice));
        updatePairButtonEnabled();

        mCancelButton = findViewById(R.id.button_cancel);
        mCancelButton.setOnClickListener((view) -> {
        mCancelButton.setOnClickListener(v -> cancel());
    }

    private void cancel() {
        getService().onCancel();
        setResult(RESULT_CANCELED);
        finish();
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (!isFinishing()) {
            cancel();
        }
    }

    private CharSequence getCallingAppName() {
+8 −2
Original line number Diff line number Diff line
@@ -202,8 +202,6 @@ public class DeviceDiscoveryService extends Service {
            reset();
        } else if (DEBUG) Log.i(LOG_TAG, "startDiscovery: duplicate request: " + request);



        if (!ArrayUtils.isEmpty(mDevicesFound)) {
            onReadyToShowUI();
        }
@@ -307,6 +305,14 @@ public class DeviceDiscoveryService extends Service {
        }
    }

    void onCancel() {
        try {
            mServiceCallback.onDeviceSelectionCancel();
        } catch (RemoteException e) {
            throw new RuntimeException(e);
        }
    }

    class DevicesAdapter extends ArrayAdapter<DeviceFilterPair> {
        //TODO wifi icon
        private Drawable BLUETOOTH_ICON = icon(android.R.drawable.stat_sys_data_bluetooth);
+10 −5
Original line number Diff line number Diff line
@@ -135,10 +135,10 @@ public class CompanionDeviceManagerService extends SystemService implements Bind

    @Override
    public void binderDied() {
        Handler.getMain().post(this::handleBinderDied);
        Handler.getMain().post(this::cleanup);
    }

    private void handleBinderDied() {
    private void cleanup() {
        mServiceConnection = unbind(mServiceConnection);
        mFindDeviceCallback = unlinkToDeath(mFindDeviceCallback, this, 0);
    }
@@ -201,7 +201,6 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
            }
        }


        @Override
        public List<String> getAssociations(String callingPackage) {
            return CollectionUtils.map(
@@ -237,7 +236,7 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
                    mFindDeviceCallback.asBinder().linkToDeath(
                            CompanionDeviceManagerService.this, 0);
                } catch (RemoteException e) {
                    handleBinderDied();
                    cleanup();
                    return;
                }
                try {
@@ -266,10 +265,16 @@ public class CompanionDeviceManagerService extends SystemService implements Bind

            @Override
            public void onDeviceSelected(String packageName, int userId, String deviceAddress) {
                //TODO unbind
                updateSpecialAccessPermissionForAssociatedPackage(packageName, userId);
                recordAssociation(packageName, deviceAddress);
                cleanup();
            }

            @Override
            public void onDeviceSelectionCancel() {
                cleanup();
            }

        };
    }