Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 07335994 authored by Etienne Ruffieux's avatar Etienne Ruffieux
Browse files

Adding system API to set the BindeCallsStats Consumer.

Tag: #feature
Bug: 195146428
Test: build
Change-Id: Id7a27eaedfaebfa0748a948ee04d1227ddb9f979
parent cbb7b0f2
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -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;
@@ -59,6 +62,34 @@ public class BluetoothFrameworkInitializer {
    return sBluetoothServiceManager;
  }

  /**
   * 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.