diff options
author | Etienne Ruffieux <eruffieux@google.com> | 2022-01-24 20:48:26 +0000 |
---|---|---|
committer | Etienne Ruffieux <eruffieux@google.com> | 2022-01-24 22:33:04 +0000 |
commit | 0733599493c444ec3628b3340c5469b9c1b1b7ce (patch) | |
tree | 2a87fb9f3b40ec83cd43f2589c99615d29d79bf8 /framework/java/android/bluetooth/BluetoothFrameworkInitializer.java | |
parent | cbb7b0f2a1ce07dc61cac6e9868198782830abd7 (diff) |
Adding system API to set the BindeCallsStats Consumer.
Tag: #feature
Bug: 195146428
Test: build
Change-Id: Id7a27eaedfaebfa0748a948ee04d1227ddb9f979
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothFrameworkInitializer.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothFrameworkInitializer.java | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/framework/java/android/bluetooth/BluetoothFrameworkInitializer.java b/framework/java/android/bluetooth/BluetoothFrameworkInitializer.java index 3faf2ce3f6..dc8b862539 100644 --- a/framework/java/android/bluetooth/BluetoothFrameworkInitializer.java +++ b/framework/java/android/bluetooth/BluetoothFrameworkInitializer.java @@ -22,6 +22,8 @@ import android.app.SystemServiceRegistry; import android.content.Context; import android.os.BluetoothServiceManager; +import java.util.function.Consumer; + /** * Class for performing registration for Bluetooth service. * @@ -32,6 +34,7 @@ public class BluetoothFrameworkInitializer { private BluetoothFrameworkInitializer() {} private static volatile BluetoothServiceManager sBluetoothServiceManager; + private static volatile Consumer<Context> sBinderCallsStatsInitializer; /** * Sets an instance of {@link BluetoothServiceManager} that allows @@ -48,7 +51,7 @@ public class BluetoothFrameworkInitializer { } if (bluetoothServiceManager == null) { - throw new NullPointerException("bluetoothServiceManager is null"); + throw new IllegalArgumentException("bluetoothServiceManager must not be null"); } sBluetoothServiceManager = bluetoothServiceManager; @@ -60,6 +63,34 @@ public class BluetoothFrameworkInitializer { } /** + * Called by {@link ActivityThread}'s static initializer to set the callback enabling Bluetooth + * {@link BinderCallsStats} registeration. + * + * @param binderCallsStatsConsumer called by bluetooth service to create a new binder calls + * stats observer + */ + public static void setBinderCallsStatsInitializer( + @NonNull Consumer<Context> binderCallsStatsConsumer) { + if (sBinderCallsStatsInitializer != null) { + throw new IllegalStateException("setBinderCallsStatsInitializer called twice!"); + } + + if (binderCallsStatsConsumer == null) { + throw new IllegalArgumentException("binderCallsStatsConsumer must not be null"); + } + + sBinderCallsStatsInitializer = binderCallsStatsConsumer; + } + + /** @hide */ + public static void initializeBinderCallsStats(Context context) { + if (sBinderCallsStatsInitializer == null) { + throw new IllegalStateException("sBinderCallsStatsInitializer has not been set"); + } + sBinderCallsStatsInitializer.accept(context); + } + + /** * Called by {@link SystemServiceRegistry}'s static initializer and registers BT service * to {@link Context}, so that {@link Context#getSystemService} can return them. * |