Loading flags/system_service.aconfig +0 −8 Original line number Diff line number Diff line Loading @@ -22,11 +22,3 @@ flag { description: "Remove complexity and non necessary initialization when simply binding" bug: "328698375" } flag { name: "use_new_satellite_mode" namespace: "bluetooth" description: "Use the new implemention of satellite mode" bug: "289584302" } service/src/com/android/server/bluetooth/BluetoothManagerService.java +2 −22 Original line number Diff line number Diff line Loading @@ -204,11 +204,6 @@ class BluetoothManagerService { private List<Integer> mSupportedProfileList = new ArrayList<>(); // TODO(b/289584302): remove BluetoothSatelliteModeListener once use_new_satellite_mode ship private BluetoothSatelliteModeListener mBluetoothSatelliteModeListener; private final boolean mUseNewSatelliteMode; // used inside handler thread private boolean mQuietEnable = false; private boolean mEnable = false; Loading Loading @@ -711,15 +706,6 @@ class BluetoothManagerService { mEnableExternal = true; } // Caching is necessary to prevent caller requiring the READ_DEVICE_CONFIG permission mUseNewSatelliteMode = mFeatureFlags.useNewSatelliteMode(); if (!mUseNewSatelliteMode) { // Only instantiate the legacy listener // New implementation is instantiated during onBootPhase on correct thread mBluetoothSatelliteModeListener = new BluetoothSatelliteModeListener(this, mLooper, mContext); } { // AutoOn feature initialization of flag guarding final boolean autoOnFlag = Flags.autoOnFeature(); final boolean autoOnProperty = Loading @@ -744,11 +730,8 @@ class BluetoothManagerService { /** Returns true if satellite mode is turned on. */ private boolean isSatelliteModeOn() { if (mUseNewSatelliteMode) { return SatelliteModeListener.isOn(); } return mBluetoothSatelliteModeListener.isSatelliteModeOn(); } /** Returns true if the Bluetooth saved state is "on" */ private boolean isBluetoothPersistedStateOn() { Loading Loading @@ -1294,10 +1277,7 @@ class BluetoothManagerService { this::getCurrentUserContext, TimeSource.Monotonic.INSTANCE); if (mUseNewSatelliteMode) { SatelliteModeListener.initialize( mLooper, mContentResolver, this::onSatelliteModeChanged); } SatelliteModeListener.initialize(mLooper, mContentResolver, this::onSatelliteModeChanged); } private void internalHandleOnBootPhase(UserHandle userHandle) { Loading service/src/com/android/server/bluetooth/BluetoothSatelliteModeListener.javadeleted 100644 → 0 +0 −114 Original line number Diff line number Diff line /* * Copyright 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.bluetooth; import android.content.Context; import android.database.ContentObserver; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.provider.Settings; import com.android.internal.annotations.VisibleForTesting; /** * The SatelliteModeListener handles system satellite mode change callback and inform * BluetoothManagerService on this change. */ public class BluetoothSatelliteModeListener { private static final String TAG = BluetoothSatelliteModeListener.class.getSimpleName(); private final BluetoothManagerService mBluetoothManagerService; private final BluetoothSatelliteModeHandler mHandler; private final Context mContext; private static final int MSG_SATELLITE_MODE_CHANGED = 0; /** * @hide constant copied from {@link Settings.Global} TODO(b/274636414): Migrate to official API * in Android V. */ @VisibleForTesting static final String SETTINGS_SATELLITE_MODE_RADIOS = "satellite_mode_radios"; /** * @hide constant copied from {@link Settings.Global} TODO(b/274636414): Migrate to official API * in Android V. */ @VisibleForTesting static final String SETTINGS_SATELLITE_MODE_ENABLED = "satellite_mode_enabled"; BluetoothSatelliteModeListener(BluetoothManagerService service, Looper looper, Context context) { Log.d(TAG, " BluetoothSatelliteModeListener"); mBluetoothManagerService = service; mHandler = new BluetoothSatelliteModeHandler(looper); mContext = context; context.getContentResolver() .registerContentObserver( Settings.Global.getUriFor(SETTINGS_SATELLITE_MODE_RADIOS), false, mSatelliteModeObserver); context.getContentResolver() .registerContentObserver( Settings.Global.getUriFor(SETTINGS_SATELLITE_MODE_ENABLED), false, mSatelliteModeObserver); } private final ContentObserver mSatelliteModeObserver = new ContentObserver(null) { @Override public void onChange(boolean unused) { // Post from system main thread to android_io thread. mHandler.sendEmptyMessage(MSG_SATELLITE_MODE_CHANGED); } }; private class BluetoothSatelliteModeHandler extends Handler { BluetoothSatelliteModeHandler(Looper looper) { super(looper); } @Override public void handleMessage(Message msg) { if (msg.what != MSG_SATELLITE_MODE_CHANGED) { Log.e(TAG, "Invalid message: " + msg.what); return; } handleSatelliteModeChange(); } } @VisibleForTesting public void handleSatelliteModeChange() { mBluetoothManagerService.onSatelliteModeChanged(isSatelliteModeOn()); } boolean isSatelliteModeSensitive() { final String satelliteRadios = Settings.Global.getString( mContext.getContentResolver(), SETTINGS_SATELLITE_MODE_RADIOS); return satelliteRadios != null && satelliteRadios.contains(Settings.Global.RADIO_BLUETOOTH); } boolean isSatelliteModeOn() { if (!isSatelliteModeSensitive()) return false; return Settings.Global.getInt( mContext.getContentResolver(), SETTINGS_SATELLITE_MODE_ENABLED, 0) == 1; } } service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java +2 −65 Original line number Diff line number Diff line Loading @@ -29,8 +29,6 @@ import static com.android.server.bluetooth.BluetoothManagerService.MESSAGE_TIMEO import static com.google.common.truth.Truth.assertThat; import static org.junit.runners.Parameterized.Parameter; import static org.junit.runners.Parameterized.Parameters; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.any; Loading Loading @@ -60,30 +58,22 @@ import android.os.test.TestLooper; import android.provider.Settings; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.flags.FakeFeatureFlagsImpl; import com.android.bluetooth.flags.Flags; import com.google.common.collect.Lists; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; @RunWith(Parameterized.class) @RunWith(AndroidJUnit4.class) public class BluetoothManagerServiceTest { private static final String TAG = BluetoothManagerServiceTest.class.getSimpleName(); private static final int STATE_BLE_TURNING_ON = 14; // can't find the symbol because hidden api Loading @@ -106,58 +96,6 @@ public class BluetoothManagerServiceTest { @Mock AdapterBinder mAdapterBinder; private FakeFeatureFlagsImpl mFakeFlagsImpl; @Parameter public FlagsValue mFlagsValue; static class FlagsValue { final Map<String, Boolean> mFlagsValue; FlagsValue(Map<String, Boolean> flagsValue) { mFlagsValue = flagsValue; } private static String formatFlag(String key) { return key.substring(key.lastIndexOf(".") + 1); } @Override public String toString() { return mFlagsValue.entrySet().stream() .filter(Map.Entry::getValue) .map(Map.Entry::getKey) .map(FlagsValue::formatFlag) .sorted() .collect(Collectors.joining(", ")); } } private static boolean filterFlags(Map<String, Boolean> map) { return true; } /** Generate the Map of flag for this test Suite */ @Parameters(name = "{0}") public static Iterable<? extends Object> generateParameterizedFlagsValue() { final String[] flags = { Flags.FLAG_USE_NEW_SATELLITE_MODE, }; final Boolean[] values = {true, false}; List<List<Map.Entry<String, Boolean>>> flagValues = Arrays.stream(flags) .map(flag -> Arrays.stream(values).map(val -> Map.entry(flag, val))) .map(Stream::toList) .toList(); return Lists.cartesianProduct(flagValues).stream() .map(list -> list.toArray(new Map.Entry[0])) .map(Map::ofEntries) .filter(BluetoothManagerServiceTest::filterFlags) .map(FlagsValue::new) .map(List::of) .map(List::toArray) .toList(); } TestLooper mLooper; boolean mHasException = false; Loading Loading @@ -221,7 +159,6 @@ public class BluetoothManagerServiceTest { mLooper = new TestLooper(); mFakeFlagsImpl = new FakeFeatureFlagsImpl(); mFlagsValue.mFlagsValue.forEach(mFakeFlagsImpl::setFlag); mManagerService = new BluetoothManagerService(mContext, mLooper.getLooper(), mFakeFlagsImpl); Loading Loading
flags/system_service.aconfig +0 −8 Original line number Diff line number Diff line Loading @@ -22,11 +22,3 @@ flag { description: "Remove complexity and non necessary initialization when simply binding" bug: "328698375" } flag { name: "use_new_satellite_mode" namespace: "bluetooth" description: "Use the new implemention of satellite mode" bug: "289584302" }
service/src/com/android/server/bluetooth/BluetoothManagerService.java +2 −22 Original line number Diff line number Diff line Loading @@ -204,11 +204,6 @@ class BluetoothManagerService { private List<Integer> mSupportedProfileList = new ArrayList<>(); // TODO(b/289584302): remove BluetoothSatelliteModeListener once use_new_satellite_mode ship private BluetoothSatelliteModeListener mBluetoothSatelliteModeListener; private final boolean mUseNewSatelliteMode; // used inside handler thread private boolean mQuietEnable = false; private boolean mEnable = false; Loading Loading @@ -711,15 +706,6 @@ class BluetoothManagerService { mEnableExternal = true; } // Caching is necessary to prevent caller requiring the READ_DEVICE_CONFIG permission mUseNewSatelliteMode = mFeatureFlags.useNewSatelliteMode(); if (!mUseNewSatelliteMode) { // Only instantiate the legacy listener // New implementation is instantiated during onBootPhase on correct thread mBluetoothSatelliteModeListener = new BluetoothSatelliteModeListener(this, mLooper, mContext); } { // AutoOn feature initialization of flag guarding final boolean autoOnFlag = Flags.autoOnFeature(); final boolean autoOnProperty = Loading @@ -744,11 +730,8 @@ class BluetoothManagerService { /** Returns true if satellite mode is turned on. */ private boolean isSatelliteModeOn() { if (mUseNewSatelliteMode) { return SatelliteModeListener.isOn(); } return mBluetoothSatelliteModeListener.isSatelliteModeOn(); } /** Returns true if the Bluetooth saved state is "on" */ private boolean isBluetoothPersistedStateOn() { Loading Loading @@ -1294,10 +1277,7 @@ class BluetoothManagerService { this::getCurrentUserContext, TimeSource.Monotonic.INSTANCE); if (mUseNewSatelliteMode) { SatelliteModeListener.initialize( mLooper, mContentResolver, this::onSatelliteModeChanged); } SatelliteModeListener.initialize(mLooper, mContentResolver, this::onSatelliteModeChanged); } private void internalHandleOnBootPhase(UserHandle userHandle) { Loading
service/src/com/android/server/bluetooth/BluetoothSatelliteModeListener.javadeleted 100644 → 0 +0 −114 Original line number Diff line number Diff line /* * Copyright 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.bluetooth; import android.content.Context; import android.database.ContentObserver; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.provider.Settings; import com.android.internal.annotations.VisibleForTesting; /** * The SatelliteModeListener handles system satellite mode change callback and inform * BluetoothManagerService on this change. */ public class BluetoothSatelliteModeListener { private static final String TAG = BluetoothSatelliteModeListener.class.getSimpleName(); private final BluetoothManagerService mBluetoothManagerService; private final BluetoothSatelliteModeHandler mHandler; private final Context mContext; private static final int MSG_SATELLITE_MODE_CHANGED = 0; /** * @hide constant copied from {@link Settings.Global} TODO(b/274636414): Migrate to official API * in Android V. */ @VisibleForTesting static final String SETTINGS_SATELLITE_MODE_RADIOS = "satellite_mode_radios"; /** * @hide constant copied from {@link Settings.Global} TODO(b/274636414): Migrate to official API * in Android V. */ @VisibleForTesting static final String SETTINGS_SATELLITE_MODE_ENABLED = "satellite_mode_enabled"; BluetoothSatelliteModeListener(BluetoothManagerService service, Looper looper, Context context) { Log.d(TAG, " BluetoothSatelliteModeListener"); mBluetoothManagerService = service; mHandler = new BluetoothSatelliteModeHandler(looper); mContext = context; context.getContentResolver() .registerContentObserver( Settings.Global.getUriFor(SETTINGS_SATELLITE_MODE_RADIOS), false, mSatelliteModeObserver); context.getContentResolver() .registerContentObserver( Settings.Global.getUriFor(SETTINGS_SATELLITE_MODE_ENABLED), false, mSatelliteModeObserver); } private final ContentObserver mSatelliteModeObserver = new ContentObserver(null) { @Override public void onChange(boolean unused) { // Post from system main thread to android_io thread. mHandler.sendEmptyMessage(MSG_SATELLITE_MODE_CHANGED); } }; private class BluetoothSatelliteModeHandler extends Handler { BluetoothSatelliteModeHandler(Looper looper) { super(looper); } @Override public void handleMessage(Message msg) { if (msg.what != MSG_SATELLITE_MODE_CHANGED) { Log.e(TAG, "Invalid message: " + msg.what); return; } handleSatelliteModeChange(); } } @VisibleForTesting public void handleSatelliteModeChange() { mBluetoothManagerService.onSatelliteModeChanged(isSatelliteModeOn()); } boolean isSatelliteModeSensitive() { final String satelliteRadios = Settings.Global.getString( mContext.getContentResolver(), SETTINGS_SATELLITE_MODE_RADIOS); return satelliteRadios != null && satelliteRadios.contains(Settings.Global.RADIO_BLUETOOTH); } boolean isSatelliteModeOn() { if (!isSatelliteModeSensitive()) return false; return Settings.Global.getInt( mContext.getContentResolver(), SETTINGS_SATELLITE_MODE_ENABLED, 0) == 1; } }
service/tests/src/com/android/server/bluetooth/BluetoothManagerServiceTest.java +2 −65 Original line number Diff line number Diff line Loading @@ -29,8 +29,6 @@ import static com.android.server.bluetooth.BluetoothManagerService.MESSAGE_TIMEO import static com.google.common.truth.Truth.assertThat; import static org.junit.runners.Parameterized.Parameter; import static org.junit.runners.Parameterized.Parameters; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.any; Loading Loading @@ -60,30 +58,22 @@ import android.os.test.TestLooper; import android.provider.Settings; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.flags.FakeFeatureFlagsImpl; import com.android.bluetooth.flags.Flags; import com.google.common.collect.Lists; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; @RunWith(Parameterized.class) @RunWith(AndroidJUnit4.class) public class BluetoothManagerServiceTest { private static final String TAG = BluetoothManagerServiceTest.class.getSimpleName(); private static final int STATE_BLE_TURNING_ON = 14; // can't find the symbol because hidden api Loading @@ -106,58 +96,6 @@ public class BluetoothManagerServiceTest { @Mock AdapterBinder mAdapterBinder; private FakeFeatureFlagsImpl mFakeFlagsImpl; @Parameter public FlagsValue mFlagsValue; static class FlagsValue { final Map<String, Boolean> mFlagsValue; FlagsValue(Map<String, Boolean> flagsValue) { mFlagsValue = flagsValue; } private static String formatFlag(String key) { return key.substring(key.lastIndexOf(".") + 1); } @Override public String toString() { return mFlagsValue.entrySet().stream() .filter(Map.Entry::getValue) .map(Map.Entry::getKey) .map(FlagsValue::formatFlag) .sorted() .collect(Collectors.joining(", ")); } } private static boolean filterFlags(Map<String, Boolean> map) { return true; } /** Generate the Map of flag for this test Suite */ @Parameters(name = "{0}") public static Iterable<? extends Object> generateParameterizedFlagsValue() { final String[] flags = { Flags.FLAG_USE_NEW_SATELLITE_MODE, }; final Boolean[] values = {true, false}; List<List<Map.Entry<String, Boolean>>> flagValues = Arrays.stream(flags) .map(flag -> Arrays.stream(values).map(val -> Map.entry(flag, val))) .map(Stream::toList) .toList(); return Lists.cartesianProduct(flagValues).stream() .map(list -> list.toArray(new Map.Entry[0])) .map(Map::ofEntries) .filter(BluetoothManagerServiceTest::filterFlags) .map(FlagsValue::new) .map(List::of) .map(List::toArray) .toList(); } TestLooper mLooper; boolean mHasException = false; Loading Loading @@ -221,7 +159,6 @@ public class BluetoothManagerServiceTest { mLooper = new TestLooper(); mFakeFlagsImpl = new FakeFeatureFlagsImpl(); mFlagsValue.mFlagsValue.forEach(mFakeFlagsImpl::setFlag); mManagerService = new BluetoothManagerService(mContext, mLooper.getLooper(), mFakeFlagsImpl); Loading