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

Commit 200c37f4 authored by Eugene Susla's avatar Eugene Susla Committed by Svetoslav Ganov
Browse files

[DO NOT MERGE] Stop scan on device chooser activity backgrounded

This effectively treats chooser activity pause event as cancel.

Bug: 30932767
Test: Install two toy apps and call associate API from both.
  Ensure foreground app always end up showing fresh data.

Change-Id: I7f5742e9878245550f678efd244bf84c427baef3
parent 5423b4e0
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
@@ -140,10 +140,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);
    }
@@ -207,7 +207,6 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
            }
        }


        @Override
        public List<String> getAssociations(String callingPackage, int userId)
                throws RemoteException {
@@ -263,7 +262,7 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
                    mFindDeviceCallback.asBinder().linkToDeath(
                            CompanionDeviceManagerService.this, 0);
                } catch (RemoteException e) {
                    handleBinderDied();
                    cleanup();
                    return;
                }
                try {
@@ -292,10 +291,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();
            }

        };
    }