Loading src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java +10 −1 Original line number Diff line number Diff line Loading @@ -54,11 +54,12 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, private static final String BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY = "persist.bluetooth.showdeviceswithoutnames"; protected final LocalBluetoothManager mLocalManager; protected final DevicePreferenceCallback mDevicePreferenceCallback; protected final Map<BluetoothDevice, Preference> mPreferenceMap; protected Context mPrefContext; protected DashboardFragment mFragment; @VisibleForTesting protected LocalBluetoothManager mLocalManager; private final boolean mShowDeviceWithoutNames; Loading Loading @@ -87,6 +88,10 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, * Register the bluetooth event callback and update the list */ public void registerCallback() { if (mLocalManager == null) { Log.e(TAG, "registerCallback() Bluetooth is not supported on this device"); return; } mLocalManager.setForegroundActivity(mFragment.getContext()); mLocalManager.getEventManager().registerCallback(this); mLocalManager.getProfileManager().addServiceListener(this); Loading @@ -97,6 +102,10 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, * Unregister the bluetooth event callback */ public void unregisterCallback() { if (mLocalManager == null) { Log.e(TAG, "unregisterCallback() Bluetooth is not supported on this device"); return; } mLocalManager.setForegroundActivity(null); mLocalManager.getEventManager().unregisterCallback(this); mLocalManager.getProfileManager().removeServiceListener(this); Loading src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java +12 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import static com.android.settingslib.Utils.isAudioModeOngoingCall; import android.content.Context; import android.content.pm.PackageManager; import android.util.Log; import com.android.settings.R; import com.android.settings.bluetooth.AvailableMediaBluetoothDeviceUpdater; Loading Loading @@ -46,12 +47,14 @@ import androidx.preference.PreferenceScreen; public class AvailableMediaDeviceGroupController extends BasePreferenceController implements LifecycleObserver, OnStart, OnStop, DevicePreferenceCallback, BluetoothCallback { private static final String TAG = "AvailableMediaDeviceGroupController"; private static final String KEY = "available_device_list"; @VisibleForTesting PreferenceGroup mPreferenceGroup; @VisibleForTesting LocalBluetoothManager mLocalBluetoothManager; private BluetoothDeviceUpdater mBluetoothDeviceUpdater; private final LocalBluetoothManager mLocalBluetoothManager; public AvailableMediaDeviceGroupController(Context context) { super(context, KEY); Loading @@ -60,12 +63,20 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle @Override public void onStart() { if (mLocalBluetoothManager == null) { Log.e(TAG, "onStart() Bluetooth is not supported on this device"); return; } mBluetoothDeviceUpdater.registerCallback(); mLocalBluetoothManager.getEventManager().registerCallback(this); } @Override public void onStop() { if (mLocalBluetoothManager == null) { Log.e(TAG, "onStop() Bluetooth is not supported on this device"); return; } mBluetoothDeviceUpdater.unregisterCallback(); mLocalBluetoothManager.getEventManager().unregisterCallback(this); } Loading src/com/android/settings/connecteddevice/DiscoverableFooterPreferenceController.java +8 −1 Original line number Diff line number Diff line Loading @@ -50,9 +50,10 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro @VisibleForTesting BroadcastReceiver mBluetoothChangedReceiver; @VisibleForTesting LocalBluetoothManager mLocalManager; private FooterPreferenceMixin mFooterPreferenceMixin; private FooterPreference mPreference; private LocalBluetoothManager mLocalManager; private LocalBluetoothAdapter mLocalAdapter; private AlwaysDiscoverable mAlwaysDiscoverable; Loading Loading @@ -113,6 +114,9 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro @Override public void onResume() { if (mLocalManager == null) { return; } mContext.registerReceiver(mBluetoothChangedReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)); mAlwaysDiscoverable.start(); Loading @@ -121,6 +125,9 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro @Override public void onPause() { if (mLocalManager == null) { return; } mContext.unregisterReceiver(mBluetoothChangedReceiver); mAlwaysDiscoverable.stop(); } Loading tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -167,4 +167,20 @@ public class BluetoothDeviceUpdaterTest { assertThat(mBluetoothDeviceUpdater.isDeviceConnected(mCachedBluetoothDevice)).isFalse(); } @Test public void registerCallback_localBluetoothManagerNull_shouldNotCrash() { mBluetoothDeviceUpdater.mLocalManager = null; // Shouldn't crash mBluetoothDeviceUpdater.registerCallback(); } @Test public void unregisterCallback_localBluetoothManagerNull_shouldNotCrash() { mBluetoothDeviceUpdater.mLocalManager = null; // Shouldn't crash mBluetoothDeviceUpdater.unregisterCallback(); } } tests/robotests/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupControllerTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -197,4 +197,20 @@ public class AvailableMediaDeviceGroupControllerTest { assertThat(mPreferenceGroup.getTitle()).isEqualTo( mContext.getText(R.string.connected_device_available_media_title)); } @Test public void onStart_localBluetoothManagerNull_shouldNotCrash() { mAvailableMediaDeviceGroupController.mLocalBluetoothManager = null; // Shouldn't crash mAvailableMediaDeviceGroupController.onStart(); } @Test public void onStop_localBluetoothManagerNull_shouldNotCrash() { mAvailableMediaDeviceGroupController.mLocalBluetoothManager = null; // Shouldn't crash mAvailableMediaDeviceGroupController.onStop(); } } Loading
src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java +10 −1 Original line number Diff line number Diff line Loading @@ -54,11 +54,12 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, private static final String BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY = "persist.bluetooth.showdeviceswithoutnames"; protected final LocalBluetoothManager mLocalManager; protected final DevicePreferenceCallback mDevicePreferenceCallback; protected final Map<BluetoothDevice, Preference> mPreferenceMap; protected Context mPrefContext; protected DashboardFragment mFragment; @VisibleForTesting protected LocalBluetoothManager mLocalManager; private final boolean mShowDeviceWithoutNames; Loading Loading @@ -87,6 +88,10 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, * Register the bluetooth event callback and update the list */ public void registerCallback() { if (mLocalManager == null) { Log.e(TAG, "registerCallback() Bluetooth is not supported on this device"); return; } mLocalManager.setForegroundActivity(mFragment.getContext()); mLocalManager.getEventManager().registerCallback(this); mLocalManager.getProfileManager().addServiceListener(this); Loading @@ -97,6 +102,10 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, * Unregister the bluetooth event callback */ public void unregisterCallback() { if (mLocalManager == null) { Log.e(TAG, "unregisterCallback() Bluetooth is not supported on this device"); return; } mLocalManager.setForegroundActivity(null); mLocalManager.getEventManager().unregisterCallback(this); mLocalManager.getProfileManager().removeServiceListener(this); Loading
src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java +12 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import static com.android.settingslib.Utils.isAudioModeOngoingCall; import android.content.Context; import android.content.pm.PackageManager; import android.util.Log; import com.android.settings.R; import com.android.settings.bluetooth.AvailableMediaBluetoothDeviceUpdater; Loading Loading @@ -46,12 +47,14 @@ import androidx.preference.PreferenceScreen; public class AvailableMediaDeviceGroupController extends BasePreferenceController implements LifecycleObserver, OnStart, OnStop, DevicePreferenceCallback, BluetoothCallback { private static final String TAG = "AvailableMediaDeviceGroupController"; private static final String KEY = "available_device_list"; @VisibleForTesting PreferenceGroup mPreferenceGroup; @VisibleForTesting LocalBluetoothManager mLocalBluetoothManager; private BluetoothDeviceUpdater mBluetoothDeviceUpdater; private final LocalBluetoothManager mLocalBluetoothManager; public AvailableMediaDeviceGroupController(Context context) { super(context, KEY); Loading @@ -60,12 +63,20 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle @Override public void onStart() { if (mLocalBluetoothManager == null) { Log.e(TAG, "onStart() Bluetooth is not supported on this device"); return; } mBluetoothDeviceUpdater.registerCallback(); mLocalBluetoothManager.getEventManager().registerCallback(this); } @Override public void onStop() { if (mLocalBluetoothManager == null) { Log.e(TAG, "onStop() Bluetooth is not supported on this device"); return; } mBluetoothDeviceUpdater.unregisterCallback(); mLocalBluetoothManager.getEventManager().unregisterCallback(this); } Loading
src/com/android/settings/connecteddevice/DiscoverableFooterPreferenceController.java +8 −1 Original line number Diff line number Diff line Loading @@ -50,9 +50,10 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro @VisibleForTesting BroadcastReceiver mBluetoothChangedReceiver; @VisibleForTesting LocalBluetoothManager mLocalManager; private FooterPreferenceMixin mFooterPreferenceMixin; private FooterPreference mPreference; private LocalBluetoothManager mLocalManager; private LocalBluetoothAdapter mLocalAdapter; private AlwaysDiscoverable mAlwaysDiscoverable; Loading Loading @@ -113,6 +114,9 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro @Override public void onResume() { if (mLocalManager == null) { return; } mContext.registerReceiver(mBluetoothChangedReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)); mAlwaysDiscoverable.start(); Loading @@ -121,6 +125,9 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro @Override public void onPause() { if (mLocalManager == null) { return; } mContext.unregisterReceiver(mBluetoothChangedReceiver); mAlwaysDiscoverable.stop(); } Loading
tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -167,4 +167,20 @@ public class BluetoothDeviceUpdaterTest { assertThat(mBluetoothDeviceUpdater.isDeviceConnected(mCachedBluetoothDevice)).isFalse(); } @Test public void registerCallback_localBluetoothManagerNull_shouldNotCrash() { mBluetoothDeviceUpdater.mLocalManager = null; // Shouldn't crash mBluetoothDeviceUpdater.registerCallback(); } @Test public void unregisterCallback_localBluetoothManagerNull_shouldNotCrash() { mBluetoothDeviceUpdater.mLocalManager = null; // Shouldn't crash mBluetoothDeviceUpdater.unregisterCallback(); } }
tests/robotests/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupControllerTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -197,4 +197,20 @@ public class AvailableMediaDeviceGroupControllerTest { assertThat(mPreferenceGroup.getTitle()).isEqualTo( mContext.getText(R.string.connected_device_available_media_title)); } @Test public void onStart_localBluetoothManagerNull_shouldNotCrash() { mAvailableMediaDeviceGroupController.mLocalBluetoothManager = null; // Shouldn't crash mAvailableMediaDeviceGroupController.onStart(); } @Test public void onStop_localBluetoothManagerNull_shouldNotCrash() { mAvailableMediaDeviceGroupController.mLocalBluetoothManager = null; // Shouldn't crash mAvailableMediaDeviceGroupController.onStop(); } }