Merge "Add error handle for device that not support Bluetooth"
This commit is contained in:
committed by
Android (Google) Code Review
commit
7ec809192c
@@ -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;
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
@@ -121,6 +125,9 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (mLocalManager == null) {
|
||||
return;
|
||||
}
|
||||
mContext.unregisterReceiver(mBluetoothChangedReceiver);
|
||||
mAlwaysDiscoverable.stop();
|
||||
}
|
||||
|
Reference in New Issue
Block a user