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

Commit 98983a28 authored by William Escande's avatar William Escande
Browse files

SystemServer: One unique method to call StartBrEdr

Bug: 311772251
Test: None
Flag: Exempt refactor
Change-Id: I078a195b3b81c2e943a082cc404f40335cf0fd43
parent 2dd0f6ca
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -225,8 +225,8 @@ interface IBluetooth
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    oneway void requestActivityInfo(in IBluetoothActivityEnergyInfoListener listener, in AttributionSource attributionSource);

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    oneway void startBrEdr(in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    oneway void bleOnToOn(in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    oneway void bleOnToOff(in AttributionSource attributionSource);

+4 −5
Original line number Diff line number Diff line
@@ -3800,17 +3800,16 @@ public class AdapterService extends Service {
        }

        @Override
        public void startBrEdr(AttributionSource source) {
        public void bleOnToOn(AttributionSource source) {
            AdapterService service = getService();
            if (service == null
                    || !callerIsSystemOrActiveOrManagedUser(service, TAG, "startBrEdr")
                    || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) {
                    || !callerIsSystemOrActiveOrManagedUser(service, TAG, "bleOnToOn")) {
                return;
            }

            service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);

            service.startBrEdr();
            service.bleOnToOn();
        }

        @Override
@@ -5761,7 +5760,7 @@ public class AdapterService extends Service {
    }

    @VisibleForTesting
    void startBrEdr() {
    void bleOnToOn() {
        mAdapterStateMachine.sendMessage(AdapterState.USER_TURN_ON);
    }

+3 −3
Original line number Diff line number Diff line
@@ -486,7 +486,7 @@ public class AdapterServiceTest {

        offToBleOn(looper, gattService, adapter, ctx, callback, nativeInterface);

        adapter.startBrEdr();
        adapter.bleOnToOn();
        TestUtils.syncHandler(looper, AdapterState.USER_TURN_ON);
        verifyStateChange(callback, STATE_BLE_ON, STATE_TURNING_ON);

@@ -766,7 +766,7 @@ public class AdapterServiceTest {
        assertThat(mAdapterService.getBluetoothScan()).isNotNull();
        assertThat(mAdapterService.getBluetoothGatt()).isNull();

        mAdapterService.startBrEdr();
        mAdapterService.bleOnToOn();
        TestUtils.syncHandler(mLooper, AdapterState.USER_TURN_ON);
        verifyStateChange(callback, STATE_BLE_ON, STATE_TURNING_ON);

@@ -823,7 +823,7 @@ public class AdapterServiceTest {
                mIBluetoothCallback,
                mNativeInterface);

        mAdapterService.startBrEdr();
        mAdapterService.bleOnToOn();
        syncHandler(AdapterState.USER_TURN_ON);
        verifyStateChange(STATE_BLE_ON, STATE_TURNING_ON);
        assertThat(mAdapterService.mSetProfileServiceStateCounter).isEqualTo(2);
+2 −2
Original line number Diff line number Diff line
@@ -59,8 +59,8 @@ class AdapterBinder(rawBinder: IBinder) {
    }

    @Throws(RemoteException::class)
    fun startBrEdr(source: AttributionSource) {
        adapterBinder.startBrEdr(source)
    fun bleOnToOn(source: AttributionSource) {
        adapterBinder.bleOnToOn(source)
    }

    @Throws(RemoteException::class)
+15 −6
Original line number Diff line number Diff line
@@ -1069,13 +1069,11 @@ class BluetoothManagerService {
            if (isBluetoothPersistedStateOnBluetooth() || !isBleAppPresent()) {
                Log.i(TAG, "continueFromBleOnState: Starting br edr");
                // This triggers transition to STATE_ON
                mAdapter.startBrEdr(mContext.getAttributionSource());
                bleOnToOn();
                setBluetoothPersistedState(BLUETOOTH_ON_BLUETOOTH);
            } else {
                Log.i(TAG, "continueFromBleOnState: Staying in BLE_ON");
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to call onServiceUp", e);
        } finally {
            mAdapterLock.readLock().unlock();
        }
@@ -1907,7 +1905,7 @@ class BluetoothManagerService {
                            Log.i(TAG, "Already at BLE_ON State");
                        } else {
                            Log.w(TAG, "BT Enable in BLE_ON State, going to ON");
                            mAdapter.startBrEdr(mContext.getAttributionSource());
                            bleOnToOn();
                        }
                        break;
                    case STATE_BLE_TURNING_ON:
@@ -1921,8 +1919,6 @@ class BluetoothManagerService {
                }
                if (isHandled) return;
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mAdapterLock.readLock().unlock();
        }
@@ -2036,6 +2032,19 @@ class BluetoothManagerService {
        }
    }

    private void bleOnToOn() {
        if (!mState.oneOf(STATE_BLE_ON)) {
            Log.d(TAG, "bleOnToOn: Impossible transition from " + mState);
            return;
        }
        Log.d(TAG, "bleOnToOn: sending request");
        try {
            mAdapter.bleOnToOn(mContext.getAttributionSource());
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to call bleOnToOn()", e);
        }
    }

    private void bleOnToOff() {
        if (!mState.oneOf(STATE_BLE_ON)) {
            Log.d(TAG, "bleOnToOff: Impossible transition from " + mState);
Loading