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

Commit 90489b7d authored by William Escande's avatar William Escande
Browse files

AdapterService: Set RemoteCallbackList final

Bug: 323672160
Test: m Bluetooth | no-op change
Flag: Exempt, no-op change
Change-Id: I501bcb52ad6e3f4c9ce1fa5b105f6665026d8ace
parent 71684a61
Loading
Loading
Loading
Loading
+47 −66
Original line number Diff line number Diff line
@@ -340,15 +340,15 @@ public class AdapterService extends Service {
            mMetadataListeners = new HashMap<>();
    private final HashMap<String, Integer> mProfileServicesState = new HashMap<String, Integer>();
    private Set<IBluetoothConnectionCallback> mBluetoothConnectionCallbacks = new HashSet<>();
    private RemoteCallbackList<IBluetoothPreferredAudioProfilesCallback>
            mPreferredAudioProfilesCallbacks;
    private RemoteCallbackList<IBluetoothQualityReportReadyCallback>
            mBluetoothQualityReportReadyCallbacks;
    private final RemoteCallbackList<IBluetoothPreferredAudioProfilesCallback>
            mPreferredAudioProfilesCallbacks = new RemoteCallbackList<>();
    private final RemoteCallbackList<IBluetoothQualityReportReadyCallback>
            mBluetoothQualityReportReadyCallbacks = new RemoteCallbackList<>();
    // Map<groupId, PendingAudioProfilePreferenceRequest>
    private final Map<Integer, PendingAudioProfilePreferenceRequest>
            mCsipGroupsPendingAudioProfileChanges = new HashMap<>();
    // Only BluetoothManagerService should be registered
    private RemoteCallbackList<IBluetoothCallback> mRemoteCallbacks;
    private final RemoteCallbackList<IBluetoothCallback>
            mRemoteCallbacks = new RemoteCallbackList<>();
    private final Map<BluetoothStateCallback, Executor> mLocalCallbacks = new ConcurrentHashMap<>();
    private int mCurrentRequestId;
    private boolean mQuietmode = false;
@@ -669,11 +669,6 @@ public class AdapterService extends Service {
                isAtvDevice,
                getApplicationInfo().dataDir);
        mNativeAvailable = true;
        mPreferredAudioProfilesCallbacks =
                new RemoteCallbackList<IBluetoothPreferredAudioProfilesCallback>();
        mBluetoothQualityReportReadyCallbacks =
                new RemoteCallbackList<IBluetoothQualityReportReadyCallback>();
        mRemoteCallbacks = new RemoteCallbackList<IBluetoothCallback>();
        // Load the name and address
        mNativeInterface.getAdapterProperty(AbstractionLayer.BT_PROPERTY_BDADDR);
        mNativeInterface.getAdapterProperty(AbstractionLayer.BT_PROPERTY_BDNAME);
@@ -1107,7 +1102,7 @@ public class AdapterService extends Service {
        mAdapterProperties.setState(newState);
        invalidateBluetoothGetStateCache();

        if (mRemoteCallbacks != null) {
        // Only BluetoothManagerService should be registered
        int n = mRemoteCallbacks.beginBroadcast();
        debugLog(
                "updateAdapterState() - Broadcasting state "
@@ -1125,7 +1120,6 @@ public class AdapterService extends Service {
            }
        }
        mRemoteCallbacks.finishBroadcast();
        }

        for (Map.Entry<BluetoothStateCallback, Executor> e : mLocalCallbacks.entrySet()) {
            e.getValue().execute(() -> e.getKey().onBluetoothStateChange(prevState, newState));
@@ -1247,7 +1241,6 @@ public class AdapterService extends Service {
    public int bluetoothQualityReportReadyCallback(
            BluetoothDevice device, BluetoothQualityReport bluetoothQualityReport) {
        synchronized (mBluetoothQualityReportReadyCallbacks) {
            if (mBluetoothQualityReportReadyCallbacks != null) {
            int n = mBluetoothQualityReportReadyCallbacks.beginBroadcast();
            debugLog(
                    "bluetoothQualityReportReadyCallback() - "
@@ -1273,7 +1266,6 @@ public class AdapterService extends Service {
            }
            mBluetoothQualityReportReadyCallbacks.finishBroadcast();
        }
        }

        return BluetoothStatusCodes.SUCCESS;
    }
@@ -1410,18 +1402,12 @@ public class AdapterService extends Service {
            mBinder = null; // Do not remove. Otherwise Binder leak!
        }

        if (mPreferredAudioProfilesCallbacks != null) {
        mPreferredAudioProfilesCallbacks.kill();
        }

        if (mBluetoothQualityReportReadyCallbacks != null) {
        mBluetoothQualityReportReadyCallbacks.kill();
        }

        if (mRemoteCallbacks != null) {
        mRemoteCallbacks.kill();
    }
    }

    private void invalidateBluetoothCaches() {
        BluetoothAdapter.invalidateGetProfileConnectionStateCache();
@@ -4270,7 +4256,6 @@ public class AdapterService extends Service {
        private void unregisterCallback(IBluetoothCallback callback, AttributionSource source) {
            AdapterService service = getService();
            if (service == null
                    || service.mRemoteCallbacks == null
                    || !callerIsSystemOrActiveOrManagedUser(service, TAG, "unregisterCallback")
                    || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) {
                return;
@@ -5853,10 +5838,6 @@ public class AdapterService extends Service {

    private void sendPreferredAudioProfilesCallbackToApps(
            BluetoothDevice device, Bundle preferredAudioProfiles, int status) {
        if (mPreferredAudioProfilesCallbacks == null) {
            return;
        }

        int n = mPreferredAudioProfilesCallbacks.beginBroadcast();
        debugLog(
                "sendPreferredAudioProfilesCallbackToApps() - Broadcasting audio profile "