Bluetooth: Fix Resource Leak in OPP (1/2)

Handle onDestroy in DevicePickerFragment class, which would be
called when user presses back button and does not select any device.
This will send intent to class that called DevicePickerFragment that
no device is selected.

Test: Performed the usecase overnight and see if no crash is observed.

Bug: 35626275
Change-Id: Ib3965d7dea8d59b244abdc6ffe61ef21109346fb
diff --git a/src/com/android/settings/bluetooth/DevicePickerFragment.java b/src/com/android/settings/bluetooth/DevicePickerFragment.java
index 00c7316..f07b7ac 100644
--- a/src/com/android/settings/bluetooth/DevicePickerFragment.java
+++ b/src/com/android/settings/bluetooth/DevicePickerFragment.java
@@ -103,6 +103,7 @@
     public void onStart() {
         super.onStart();
         addCachedDevices();
+        mSelectedDevice = null;
         if (mStartScanOnStart) {
             mLocalAdapter.startScanning(true);
             mStartScanOnStart = false;
@@ -110,6 +111,17 @@
     }
 
     @Override
+    public void onDestroy() {
+        super.onDestroy();
+        /* Check if any device was selected, if no device selected
+         * send  ACTION_DEVICE_SELECTED with a null device, otherwise
+         * don't do anything */
+        if (mSelectedDevice == null) {
+            sendDevicePickedIntent(null);
+        }
+    }
+
+    @Override
     void onDevicePreferenceClick(BluetoothDevicePreference btPreference) {
         mLocalAdapter.stopScanning();
         LocalBluetoothPreferences.persistSelectedDeviceInPicker(