diff options
author | Eugene Susla <eugenesusla@google.com> | 2017-02-13 12:46:46 -0800 |
---|---|---|
committer | Eugene Susla <eugenesusla@google.com> | 2017-03-06 16:53:32 -0800 |
commit | 47aafbe033202ccc2c0ea9af2b0f1596ebed4373 (patch) | |
tree | 061ce59e55ddc668bfa22422238e3c89d88dd48e /packages/CompanionDeviceManager | |
parent | 280a9cfaab9b07dc36df04c0f376ea88ab187068 (diff) |
Record app<->device association to xml file
Bug: 30932767
Test: Ensure file not exists -> query associations -> ensure result is empty list
Associate device -> cat xml file -> ensure record appears as extected
Disassociate device -> cat xml file -> ensure record is no longer present
Change-Id: Ibe456a6d9292e05e2391f5138e43fdaa37f87e1b
Diffstat (limited to 'packages/CompanionDeviceManager')
2 files changed, 14 insertions, 12 deletions
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceChooserActivity.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceChooserActivity.java index 25127efad502..12bab18c88c9 100644 --- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceChooserActivity.java +++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceChooserActivity.java @@ -92,7 +92,7 @@ public class DeviceChooserActivity extends Activity { try { final PackageManager packageManager = getPackageManager(); return packageManager.getApplicationLabel( - packageManager.getApplicationInfo(getService().mCallingPackage, 0)); + packageManager.getApplicationInfo(getCallingPackage(), 0)); } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } @@ -128,7 +128,7 @@ public class DeviceChooserActivity extends Activity { } protected void onPairTapped(BluetoothDevice selectedDevice) { - getService().onDeviceSelected(); + getService().onDeviceSelected(getCallingPackage(), selectedDevice.getAddress()); setResult(RESULT_OK, new Intent().putExtra(CompanionDeviceManager.EXTRA_DEVICE, selectedDevice)); finish(); diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java index 11c722d7676c..f0f910848943 100644 --- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java +++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java @@ -33,6 +33,7 @@ import android.bluetooth.le.ScanResult; import android.bluetooth.le.ScanSettings; import android.companion.AssociationRequest; import android.companion.BluetoothLEDeviceFilter; +import android.companion.CompanionDeviceManager; import android.companion.ICompanionDeviceDiscoveryService; import android.companion.ICompanionDeviceDiscoveryServiceCallback; import android.companion.IFindDeviceCallback; @@ -71,7 +72,6 @@ public class DeviceDiscoveryService extends Service { DevicesAdapter mDevicesAdapter; IFindDeviceCallback mFindCallback; ICompanionDeviceDiscoveryServiceCallback mServiceCallback; - String mCallingPackage; private final ICompanionDeviceDiscoveryService mBinder = new ICompanionDeviceDiscoveryService.Stub() { @@ -88,7 +88,6 @@ public class DeviceDiscoveryService extends Service { } mFindCallback = findCallback; mServiceCallback = serviceCallback; - mCallingPackage = callingPackage; DeviceDiscoveryService.this.startDiscovery(request); } }; @@ -174,14 +173,6 @@ public class DeviceDiscoveryService extends Service { return super.onUnbind(intent); } - public void onDeviceSelected() { - try { - mServiceCallback.onDeviceSelected(mCallingPackage, getUserId()); - } catch (RemoteException e) { - Log.e(LOG_TAG, "Error reporting selected device"); - } - } - private void stopScan() { if (DEBUG) Log.i(LOG_TAG, "stopScan() called"); mBluetoothAdapter.cancelDiscovery(); @@ -234,6 +225,17 @@ public class DeviceDiscoveryService extends Service { } } + void onDeviceSelected(String callingPackage, String deviceAddress) { + try { + mServiceCallback.onDeviceSelected( + //TODO is this the right userId? + callingPackage, getUserId(), deviceAddress); + } catch (RemoteException e) { + Log.e(LOG_TAG, "Failed to record association: " + + callingPackage + " <-> " + deviceAddress); + } + } + class DevicesAdapter extends ArrayAdapter<BluetoothDevice> { private Drawable BLUETOOTH_ICON = icon(android.R.drawable.stat_sys_data_bluetooth); |