[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
This commit is contained in:
Eugene Susla
2017-03-28 15:40:44 -07:00
committed by Svetoslav Ganov
parent 5423b4e0a8
commit 200c37f413
4 changed files with 35 additions and 13 deletions

View File

@@ -19,4 +19,5 @@ package android.companion;
/** @hide */
interface ICompanionDeviceDiscoveryServiceCallback {
oneway void onDeviceSelected(String packageName, int userId, String deviceAddress);
oneway void onDeviceSelectionCancel();
}

View File

@@ -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) -> {
setResult(RESULT_CANCELED);
finish();
});
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() {

View File

@@ -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);

View File

@@ -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();
}
};
}