diff options
| author | Adam Lesinski <adamlesinski@google.com> | 2016-04-11 12:18:18 -0700 |
|---|---|---|
| committer | Adam Lesinski <adamlesinski@google.com> | 2016-04-15 15:27:52 -0700 |
| commit | 6b31ff83910fe3ceb75f4af508bff62c13d71bc5 (patch) | |
| tree | 46b94ad7bd3e70da2be777f711b3373f9bc72ef4 /framework/java/android/bluetooth/BluetoothAdapter.java | |
| parent | 75f3ec20467e276ce24fb55758ee02e360ddc9cd (diff) | |
BatteryStats: Introduce Async external stats requests
Instead of calling out to external processes with a blocking IPC,
pass along a Binder on which the external process can pass back
the response. The calling process can then wait for the reply with
a timeout.
This eliminates watchdog restarts of the system_server when an external
process like telephony or bluetooth hangs.
Bug:26842468
Change-Id: I1b242e4ed22a63f1a4a0be8c78de8ac4d7bf56c5
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
| -rw-r--r-- | framework/java/android/bluetooth/BluetoothAdapter.java | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java index 2a7eff8830..e74847711b 100644 --- a/framework/java/android/bluetooth/BluetoothAdapter.java +++ b/framework/java/android/bluetooth/BluetoothAdapter.java @@ -31,11 +31,14 @@ import android.bluetooth.le.ScanRecord; import android.bluetooth.le.ScanResult; import android.bluetooth.le.ScanSettings; import android.content.Context; +import android.os.BatteryStats; import android.os.Binder; import android.os.IBinder; import android.os.ParcelUuid; import android.os.RemoteException; +import android.os.ResultReceiver; import android.os.ServiceManager; +import android.os.SynchronousResultReceiver; import android.os.SystemProperties; import android.util.Log; import android.util.Pair; @@ -53,6 +56,7 @@ import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.TimeoutException; /** * Represents the local device Bluetooth adapter. The {@link BluetoothAdapter} @@ -1369,33 +1373,62 @@ public final class BluetoothAdapter { * * @return a record with {@link BluetoothActivityEnergyInfo} or null if * report is unavailable or unsupported + * @deprecated use the asynchronous + * {@link #requestControllerActivityEnergyInfo(int, ResultReceiver)} instead. * @hide */ + @Deprecated public BluetoothActivityEnergyInfo getControllerActivityEnergyInfo(int updateType) { - if (getState() != STATE_ON) return null; + SynchronousResultReceiver receiver = new SynchronousResultReceiver(); + requestControllerActivityEnergyInfo(updateType, receiver); + try { + SynchronousResultReceiver.Result result = receiver.awaitResult(1000); + if (result.bundle != null) { + return result.bundle.getParcelable(BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY); + } + } catch (TimeoutException e) { + Log.e(TAG, "getControllerActivityEnergyInfo timed out"); + } + return null; + } + + /** + * Request the record of {@link BluetoothActivityEnergyInfo} object that + * has the activity and energy info. This can be used to ascertain what + * the controller has been up to, since the last sample. + * + * A null value for the activity info object may be sent if the bluetooth service is + * unreachable or the device does not support reporting such information. + * + * @param updateType Type of info, cached vs refreshed. + * @param result The callback to which to send the activity info. + * @hide + */ + public void requestControllerActivityEnergyInfo(int updateType, ResultReceiver result) { + if (getState() != STATE_ON) { + result.send(0, null); + return; + } + try { - BluetoothActivityEnergyInfo record; if (!mService.isActivityAndEnergyReportingSupported()) { - return null; + result.send(0, null); + return; } synchronized(this) { if (updateType == ACTIVITY_ENERGY_INFO_REFRESHED) { mService.getActivityEnergyInfoFromController(); wait(CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS); } - record = mService.reportActivityInfo(); - if (record.isValid()) { - return record; - } else { - return null; - } + mService.requestActivityInfo(result); } } catch (InterruptedException e) { Log.e(TAG, "getControllerActivityEnergyInfoCallback wait interrupted: " + e); + result.send(0, null); } catch (RemoteException e) { Log.e(TAG, "getControllerActivityEnergyInfoCallback: " + e); + result.send(0, null); } - return null; } /** |
