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

Commit 618c9faa authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I8b9fb050,I6a7d18f5,I4e06a724 into main

* changes:
  Revert "Flag: broadcast_adapter_state_with_callback"
  Revert "Stop calling app to know its state. Use Callback"
  Revert "Wait for state callback before ending constructor"
parents c8c8cdf2 992f3bc2
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.os.ResultReceiver;
 */
interface IBluetooth
{
    // TODO: b/357645528 - delete aidl method
    @JavaPassthrough(annotation="@android.annotation.RequiresNoPermission")
    int getState();

+4 −13
Original line number Diff line number Diff line
@@ -1153,10 +1153,8 @@ public class AdapterService extends Service {
    }

    private void invalidateBluetoothGetStateCache() {
        if (!Flags.broadcastAdapterStateWithCallback()) {
        BluetoothAdapter.invalidateBluetoothGetStateCache();
    }
    }

    void updateLeAudioProfileServiceState() {
        Set<Integer> nonSupportedProfiles = new HashSet<>();
@@ -1186,9 +1184,7 @@ public class AdapterService extends Service {

    void updateAdapterState(int prevState, int newState) {
        mAdapterProperties.setState(newState);
        if (!Flags.broadcastAdapterStateWithCallback()) {
        invalidateBluetoothGetStateCache();
        }

        // Only BluetoothManagerService should be registered
        int n = mRemoteCallbacks.beginBroadcast();
@@ -1486,9 +1482,7 @@ public class AdapterService extends Service {
        BluetoothAdapter.invalidateGetProfileConnectionStateCache();
        BluetoothAdapter.invalidateIsOffloadedFilteringSupportedCache();
        BluetoothDevice.invalidateBluetoothGetBondStateCache();
        if (!Flags.broadcastAdapterStateWithCallback()) {
        BluetoothAdapter.invalidateBluetoothGetStateCache();
        }
        BluetoothAdapter.invalidateGetAdapterConnectionStateCache();
        BluetoothMap.invalidateBluetoothGetConnectionStateCache();
        BluetoothSap.invalidateBluetoothGetConnectionStateCache();
@@ -2246,9 +2240,7 @@ public class AdapterService extends Service {

        AdapterServiceBinder(AdapterService svc) {
            mService = svc;
            if (!Flags.broadcastAdapterStateWithCallback()) {
            mService.invalidateBluetoothGetStateCache();
            }
            BluetoothAdapter.getDefaultAdapter().disableBluetoothGetStateCache();
        }

@@ -2259,7 +2251,6 @@ public class AdapterService extends Service {
            return mService;
        }

        // TODO: b/357645528 - delete getState method
        @Override
        public int getState() {
            AdapterService service = getService();
+0 −10
Original line number Diff line number Diff line
@@ -29,16 +29,6 @@ flag {
    bug: "339554081"
}

flag {
    name: "broadcast_adapter_state_with_callback"
    namespace: "bluetooth"
    description: "Instead of caching the value with an IPC cache, we directly broadcast the state to each app so they can store it locally"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
    bug: "357645528"
}

flag {
    name: "fast_bind_to_app"
    namespace: "bluetooth"
+0 −48
Original line number Diff line number Diff line
@@ -96,12 +96,8 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.BiFunction;
import java.util.function.Consumer;
@@ -877,9 +873,6 @@ public final class BluetoothAdapter {
    @GuardedBy("mServiceLock")
    private IBluetooth mService;

    private static CompletableFuture<Void> sAdapterStateFuture = null;
    private static int sAdapterState = BluetoothAdapter.STATE_OFF;

    private final ReentrantReadWriteLock mServiceLock = new ReentrantReadWriteLock();

    @GuardedBy("sServiceLock")
@@ -1178,20 +1171,6 @@ public final class BluetoothAdapter {
                new CallbackWrapper(
                        registerBluetoothConnectionCallbackConsumer,
                        unregisterBluetoothConnectionCallbackConsumer);

        if (!Flags.broadcastAdapterStateWithCallback()) {
            return;
        }
        // Make sure that we are waiting on the state callback prior to returning from constructor
        CompletableFuture<Void> futureState = sAdapterStateFuture;
        if (futureState != null) {
            try {
                futureState.get(1_000, TimeUnit.MILLISECONDS);
            } catch (InterruptedException | ExecutionException | TimeoutException e) {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
        }
        Log.i(TAG, "Adapter created with state: " + nameForState(sAdapterState));
    }

    /**
@@ -1531,9 +1510,6 @@ public final class BluetoothAdapter {

    /** Fetch the current bluetooth state. If the service is down, return OFF. */
    private @InternalAdapterState int getStateInternal() {
        if (Flags.broadcastAdapterStateWithCallback()) {
            return sAdapterState;
        }
        mServiceLock.readLock().lock();
        try {
            if (mService != null) {
@@ -3800,17 +3776,6 @@ public final class BluetoothAdapter {
                        }
                    }
                }

                @RequiresNoPermission
                public void onBluetoothAdapterStateChange(int newState) {
                    Log.v(TAG, "onBluetoothAdapterStateChange(" + nameForState(newState) + ")");
                    CompletableFuture<Void> future = sAdapterStateFuture;
                    sAdapterStateFuture = null;
                    if (future != null) {
                        future.complete(null);
                    }
                    sAdapterState = newState;
                }
            };

    private final IBluetoothManagerCallback mManagerCallback =
@@ -3908,11 +3873,6 @@ public final class BluetoothAdapter {
                                        });
                            });
                }

                @RequiresNoPermission
                public void onBluetoothAdapterStateChange(int newState) {
                    // Nothing to do, this is entirely handled by sManagerCallback.
                }
            };

    /**
@@ -4243,11 +4203,6 @@ public final class BluetoothAdapter {
            return;
        }
        if (wantRegistered) {
            if (Flags.broadcastAdapterStateWithCallback()
                    && sAdapterState == BluetoothAdapter.STATE_OFF
                    && sAdapterStateFuture == null) {
                sAdapterStateFuture = new CompletableFuture<>();
            }
            try {
                sService =
                        IBluetooth.Stub.asInterface(
@@ -4262,9 +4217,6 @@ public final class BluetoothAdapter {
            } catch (RemoteException e) {
                throw e.rethrowAsRuntimeException();
            }
            if (Flags.broadcastAdapterStateWithCallback()) {
                sAdapterState = BluetoothAdapter.STATE_OFF;
            }
        }
        sServiceRegistered = wantRegistered;
    }
+0 −1
Original line number Diff line number Diff line
@@ -26,5 +26,4 @@ oneway interface IBluetoothManagerCallback {
    void onBluetoothServiceDown();
    void onBluetoothOn();
    void onBluetoothOff();
    void onBluetoothAdapterStateChange(int newState);
}
Loading