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

Commit 1f3cf67a authored by William Escande's avatar William Escande
Browse files

24Q4: Removal of respect_ble_scan_setting

Bug: 341783936
Fix: 341783936
Flag: com.android.bluetooth.flags.respect_ble_scan_setting
Test: atest ServiceBluetoothRoboTests
Change-Id: I8e9fd57087e4d7cd19566d0356863cea2c24b732
parent fde407b0
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -51,16 +51,6 @@ flag {
    bug: "368120237"
}

flag {
    name: "respect_ble_scan_setting"
    namespace: "bluetooth"
    description: "No longer allow BLE_ON mode when the settings is explicitly disable"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
    bug: "341783936"
}

flag {
    name: "system_server_messenger"
    namespace: "bluetooth"
+7 −55
Original line number Diff line number Diff line
@@ -62,7 +62,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.ContentObserver;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
@@ -79,7 +78,6 @@ import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.sysprop.BluetoothProperties;
import android.util.proto.ProtoOutputStream;

@@ -589,11 +587,7 @@ class BluetoothManagerService {
        mHandler = new BluetoothHandler(mLooper);

        // Observe BLE scan only mode settings change.
        if (Flags.respectBleScanSetting()) {
        BleScanSettingListener.initialize(mLooper, mContentResolver, this::onBleScanDisabled);
        } else {
            registerForBleScanModeChange();
        }

        // Disable ASHA if BLE is not supported, overriding any system property
        if (!isBleSupported(mContext)) {
@@ -861,21 +855,11 @@ class BluetoothManagerService {
        if (AirplaneModeListener.isOn() && !mEnable) {
            return false;
        }
        if (Flags.respectBleScanSetting()) {
        if (SatelliteModeListener.isOn()) {
            return false;
        }
        return BleScanSettingListener.isScanAllowed();
    }
        try {
            return Settings.Global.getInt(
                            mContentResolver, BleScanSettingListener.BLE_SCAN_ALWAYS_AVAILABLE)
                    != 0;
        } catch (SettingNotFoundException e) {
            // The settings is considered as false by default.
            return false;
        }
    }

    boolean isHearingAidProfileSupported() {
        return mIsHearingAidProfileSupported;
@@ -892,32 +876,6 @@ class BluetoothManagerService {
        return mAdapter.isMediaProfileConnected(mContext.getAttributionSource());
    }

    // Monitor change of BLE scan only mode settings.
    private void registerForBleScanModeChange() {
        ContentObserver contentObserver =
                new ContentObserver(new Handler(mLooper)) {
                    @Override
                    public void onChange(boolean selfChange) {
                        if (isBleScanAvailable()) {
                            // Nothing to do
                            return;
                        }
                        // BLE scan is not available.
                        disableBleScanMode();
                        clearBleApps();
                        if (mState.oneOf(STATE_BLE_ON)) {
                            ActiveLogs.add(ENABLE_DISABLE_REASON_APPLICATION_REQUEST, false);
                            bleOnToOff();
                        }
                    }
                };

        mContentResolver.registerContentObserver(
                Settings.Global.getUriFor(BleScanSettingListener.BLE_SCAN_ALWAYS_AVAILABLE),
                false,
                contentObserver);
    }

    // Disable ble scan only mode.
    private void disableBleScanMode() {
        if (mState.oneOf(STATE_ON)) {
@@ -972,7 +930,7 @@ class BluetoothManagerService {
            return false;
        }

        if (Flags.respectBleScanSetting() && !BleScanSettingListener.isScanAllowed()) {
        if (!BleScanSettingListener.isScanAllowed()) {
            Log.d(TAG, "enableBle: not enabling - Scan mode is not allowed.");
            return false;
        }
@@ -1005,12 +963,6 @@ class BluetoothManagerService {
                        + (" isBinding=" + isBinding())
                        + (" mState=" + mState));

        // Remove this with flag, preventing a "disable" make no sense, even in satellite mode
        if (!Flags.respectBleScanSetting() && isSatelliteModeOn()) {
            Log.d(TAG, "disableBle: not disabling - satellite mode is on.");
            return false;
        }

        if (mState.oneOf(STATE_OFF)) {
            Log.i(TAG, "disableBle: Already disabled");
            return false;
@@ -1075,9 +1027,9 @@ class BluetoothManagerService {
            Log.d(TAG, "sendBrEdrDownCallback: mAdapter is null");
            return;
        }
        boolean scanIsAllowed =
                !Flags.respectBleScanSetting() || BleScanSettingListener.isScanAllowed();
        if (!AirplaneModeListener.isOn() && isBleAppPresent() && scanIsAllowed) {
        if (BleScanSettingListener.isScanAllowed()
                && !AirplaneModeListener.isOn()
                && isBleAppPresent()) {
            // Need to stay at BLE ON. Disconnect all Gatt connections
            Log.i(TAG, "sendBrEdrDownCallback: Staying in BLE_ON");
            try {