Use BluetoothAdapter instead of LocalBluetoothAdapter
LocalBluetoothAdapter only has a few APIs that is not supported by BluetoothAdapter, and lots of LocalBluetoothAdapter function pass parameter to BluetoothAdapter directly. Do the refactor in Settings, use BluetoothAdapter instead of LocalBluetoothAdapter. Bug: 111769754 Test: make -j42 RunSettingsRoboTests Change-Id: I88e5a8377b5d1106c7679e6a8c3fd1ca1a80ea6f
This commit is contained in:
@@ -22,8 +22,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
/** Helper class, intended to be used by an Activity, to keep the local Bluetooth adapter in
|
||||
@@ -35,15 +33,15 @@ public class AlwaysDiscoverable extends BroadcastReceiver {
|
||||
private static final String TAG = "AlwaysDiscoverable";
|
||||
|
||||
private Context mContext;
|
||||
private LocalBluetoothAdapter mLocalAdapter;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private IntentFilter mIntentFilter;
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mStarted;
|
||||
|
||||
public AlwaysDiscoverable(Context context, LocalBluetoothAdapter localAdapter) {
|
||||
public AlwaysDiscoverable(Context context) {
|
||||
mContext = context;
|
||||
mLocalAdapter = localAdapter;
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mIntentFilter = new IntentFilter();
|
||||
mIntentFilter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
|
||||
}
|
||||
@@ -56,8 +54,9 @@ public class AlwaysDiscoverable extends BroadcastReceiver {
|
||||
}
|
||||
mContext.registerReceiver(this, mIntentFilter);
|
||||
mStarted = true;
|
||||
if (mLocalAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
if (mBluetoothAdapter.getScanMode()
|
||||
!= BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
mBluetoothAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +66,7 @@ public class AlwaysDiscoverable extends BroadcastReceiver {
|
||||
}
|
||||
mContext.unregisterReceiver(this);
|
||||
mStarted = false;
|
||||
mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
|
||||
mBluetoothAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,8 +75,9 @@ public class AlwaysDiscoverable extends BroadcastReceiver {
|
||||
if (action != BluetoothAdapter.ACTION_SCAN_MODE_CHANGED) {
|
||||
return;
|
||||
}
|
||||
if (mLocalAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
if (mBluetoothAdapter.getScanMode()
|
||||
!= BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
mBluetoothAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -27,8 +27,6 @@ import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
@@ -46,8 +44,7 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
|
||||
|
||||
@VisibleForTesting
|
||||
Preference mPreference;
|
||||
private LocalBluetoothManager mLocalManager;
|
||||
protected LocalBluetoothAdapter mLocalAdapter;
|
||||
protected BluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
/**
|
||||
* Constructor exclusively used for Slice.
|
||||
@@ -55,19 +52,11 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
|
||||
public BluetoothDeviceNamePreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
|
||||
mLocalManager = Utils.getLocalBtManager(context);
|
||||
if (mLocalManager == null) {
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (mBluetoothAdapter == null) {
|
||||
Log.e(TAG, "Bluetooth is not supported on this device");
|
||||
return;
|
||||
}
|
||||
mLocalAdapter = mLocalManager.getBluetoothAdapter();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BluetoothDeviceNamePreferenceController(Context context, LocalBluetoothAdapter localAdapter,
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mLocalAdapter = localAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,7 +80,7 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mLocalAdapter != null ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
return mBluetoothAdapter != null ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -138,7 +127,7 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
|
||||
}
|
||||
|
||||
protected String getDeviceName() {
|
||||
return mLocalAdapter.getName();
|
||||
return mBluetoothAdapter.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +141,8 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
|
||||
final String action = intent.getAction();
|
||||
|
||||
if (TextUtils.equals(action, BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED)) {
|
||||
if (mPreference != null && mLocalAdapter != null && mLocalAdapter.isEnabled()) {
|
||||
if (mPreference != null && mBluetoothAdapter != null
|
||||
&& mBluetoothAdapter.isEnabled()) {
|
||||
updatePreferenceState(mPreference);
|
||||
}
|
||||
} else if (TextUtils.equals(action, BluetoothAdapter.ACTION_STATE_CHANGED)) {
|
||||
|
@@ -16,12 +16,12 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -42,13 +42,6 @@ public class BluetoothDeviceRenamePreferenceController extends
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BluetoothDeviceRenamePreferenceController(Context context, LocalBluetoothAdapter localAdapter,
|
||||
String preferenceKey) {
|
||||
super(context, localAdapter, preferenceKey);
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link Fragment} that used to show {@link LocalDeviceNameDialogFragment}
|
||||
* in {@code handlePreferenceTreeClick}
|
||||
@@ -61,7 +54,7 @@ public class BluetoothDeviceRenamePreferenceController extends
|
||||
@Override
|
||||
protected void updatePreferenceState(final Preference preference) {
|
||||
preference.setSummary(getSummary());
|
||||
preference.setVisible(mLocalAdapter != null && mLocalAdapter.isEnabled());
|
||||
preference.setVisible(mBluetoothAdapter != null && mBluetoothAdapter.isEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -28,7 +28,6 @@ import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.bluetooth.BluetoothDiscoverableTimeoutReceiver;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
@@ -64,7 +63,7 @@ final class BluetoothDiscoverableEnabler implements Preference.OnPreferenceClick
|
||||
private final Handler mUiHandler;
|
||||
private final Preference mDiscoveryPreference;
|
||||
|
||||
private final LocalBluetoothAdapter mLocalAdapter;
|
||||
private final BluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
private final SharedPreferences mSharedPreferences;
|
||||
|
||||
@@ -92,17 +91,16 @@ final class BluetoothDiscoverableEnabler implements Preference.OnPreferenceClick
|
||||
}
|
||||
};
|
||||
|
||||
BluetoothDiscoverableEnabler(LocalBluetoothAdapter adapter,
|
||||
Preference discoveryPreference) {
|
||||
BluetoothDiscoverableEnabler(Preference discoveryPreference) {
|
||||
mUiHandler = new Handler();
|
||||
mLocalAdapter = adapter;
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mDiscoveryPreference = discoveryPreference;
|
||||
mSharedPreferences = discoveryPreference.getSharedPreferences();
|
||||
discoveryPreference.setPersistent(false);
|
||||
}
|
||||
|
||||
public void resume(Context context) {
|
||||
if (mLocalAdapter == null) {
|
||||
if (mBluetoothAdapter == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -113,11 +111,11 @@ final class BluetoothDiscoverableEnabler implements Preference.OnPreferenceClick
|
||||
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
|
||||
mContext.registerReceiver(mReceiver, filter);
|
||||
mDiscoveryPreference.setOnPreferenceClickListener(this);
|
||||
handleModeChanged(mLocalAdapter.getScanMode());
|
||||
handleModeChanged(mBluetoothAdapter.getScanMode());
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
if (mLocalAdapter == null) {
|
||||
if (mBluetoothAdapter == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -139,7 +137,8 @@ final class BluetoothDiscoverableEnabler implements Preference.OnPreferenceClick
|
||||
long endTimestamp = System.currentTimeMillis() + timeout * 1000L;
|
||||
LocalBluetoothPreferences.persistDiscoverableEndTimestamp(mContext, endTimestamp);
|
||||
|
||||
mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, timeout);
|
||||
mBluetoothAdapter
|
||||
.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, timeout);
|
||||
updateCountdownSummary();
|
||||
|
||||
Log.d(TAG, "setEnabled(): enabled = " + enable + "timeout = " + timeout);
|
||||
@@ -151,7 +150,7 @@ final class BluetoothDiscoverableEnabler implements Preference.OnPreferenceClick
|
||||
}
|
||||
|
||||
} else {
|
||||
mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
|
||||
mBluetoothAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
|
||||
BluetoothDiscoverableTimeoutReceiver.cancelDiscoverableAlarm(mContext);
|
||||
}
|
||||
}
|
||||
@@ -250,7 +249,7 @@ final class BluetoothDiscoverableEnabler implements Preference.OnPreferenceClick
|
||||
|
||||
void setNumberOfPairedDevices(int pairedDevices) {
|
||||
mNumberOfPairedDevices = pairedDevices;
|
||||
handleModeChanged(mLocalAdapter.getScanMode());
|
||||
handleModeChanged(mBluetoothAdapter.getScanMode());
|
||||
}
|
||||
|
||||
void handleModeChanged(int mode) {
|
||||
@@ -273,7 +272,7 @@ final class BluetoothDiscoverableEnabler implements Preference.OnPreferenceClick
|
||||
}
|
||||
|
||||
private void updateCountdownSummary() {
|
||||
int mode = mLocalAdapter.getScanMode();
|
||||
int mode = mBluetoothAdapter.getScanMode();
|
||||
if (mode != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
return;
|
||||
}
|
||||
|
@@ -29,8 +29,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.widget.SwitchWidgetController;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.WirelessUtils;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -45,7 +43,7 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private Context mContext;
|
||||
private boolean mValidListener;
|
||||
private final LocalBluetoothAdapter mLocalAdapter;
|
||||
private final BluetoothAdapter mBluetoothAdapter;
|
||||
private final IntentFilter mIntentFilter;
|
||||
private final RestrictionUtils mRestrictionUtils;
|
||||
private SwitchWidgetController.OnSwitchChangeListener mCallback;
|
||||
@@ -65,15 +63,14 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
||||
};
|
||||
|
||||
public BluetoothEnabler(Context context, SwitchWidgetController switchController,
|
||||
MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
|
||||
int metricsEvent) {
|
||||
this(context, switchController, metricsFeatureProvider, manager, metricsEvent,
|
||||
MetricsFeatureProvider metricsFeatureProvider, int metricsEvent) {
|
||||
this(context, switchController, metricsFeatureProvider, metricsEvent,
|
||||
new RestrictionUtils());
|
||||
}
|
||||
|
||||
public BluetoothEnabler(Context context, SwitchWidgetController switchController,
|
||||
MetricsFeatureProvider metricsFeatureProvider, LocalBluetoothManager manager,
|
||||
int metricsEvent, RestrictionUtils restrictionUtils) {
|
||||
MetricsFeatureProvider metricsFeatureProvider, int metricsEvent,
|
||||
RestrictionUtils restrictionUtils) {
|
||||
mContext = context;
|
||||
mMetricsFeatureProvider = metricsFeatureProvider;
|
||||
mSwitchController = switchController;
|
||||
@@ -81,12 +78,10 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
||||
mValidListener = false;
|
||||
mMetricsEvent = metricsEvent;
|
||||
|
||||
if (manager == null) {
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (mBluetoothAdapter == null) {
|
||||
// Bluetooth is not supported
|
||||
mLocalAdapter = null;
|
||||
mSwitchController.setEnabled(false);
|
||||
} else {
|
||||
mLocalAdapter = manager.getBluetoothAdapter();
|
||||
}
|
||||
mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
mRestrictionUtils = restrictionUtils;
|
||||
@@ -107,14 +102,14 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
||||
|
||||
final boolean restricted = maybeEnforceRestrictions();
|
||||
|
||||
if (mLocalAdapter == null) {
|
||||
if (mBluetoothAdapter == null) {
|
||||
mSwitchController.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Bluetooth state is not sticky, so set it manually
|
||||
if (!restricted) {
|
||||
handleStateChanged(mLocalAdapter.getBluetoothState());
|
||||
handleStateChanged(mBluetoothAdapter.getState());
|
||||
}
|
||||
|
||||
mSwitchController.startListening();
|
||||
@@ -123,7 +118,7 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
if (mLocalAdapter == null) {
|
||||
if (mBluetoothAdapter == null) {
|
||||
return;
|
||||
}
|
||||
if (mValidListener) {
|
||||
@@ -188,8 +183,8 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
||||
|
||||
mMetricsFeatureProvider.action(mContext, mMetricsEvent, isChecked);
|
||||
|
||||
if (mLocalAdapter != null) {
|
||||
boolean status = mLocalAdapter.setBluetoothEnabled(isChecked);
|
||||
if (mBluetoothAdapter != null) {
|
||||
boolean status = setBluetoothEnabled(isChecked);
|
||||
// If we cannot toggle it ON then reset the UI assets:
|
||||
// a) The switch should be OFF but it should still be togglable (enabled = True)
|
||||
// b) The switch bar should have OFF text.
|
||||
@@ -249,4 +244,8 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
||||
mCallback.onSwitchToggled(isChecked);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setBluetoothEnabled(boolean isEnabled) {
|
||||
return isEnabled ? mBluetoothAdapter.enable() : mBluetoothAdapter.disable();
|
||||
}
|
||||
}
|
||||
|
@@ -63,7 +63,7 @@ public class BluetoothPairingDetail extends DeviceListPreferenceFragment impleme
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mInitialScanStarted = false;
|
||||
mAlwaysDiscoverable = new AlwaysDiscoverable(getContext(), mLocalAdapter);
|
||||
mAlwaysDiscoverable = new AlwaysDiscoverable(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,7 +74,7 @@ public class BluetoothPairingDetail extends DeviceListPreferenceFragment impleme
|
||||
return;
|
||||
}
|
||||
updateBluetooth();
|
||||
mAvailableDevicesCategory.setProgress(mLocalAdapter.isDiscovering());
|
||||
mAvailableDevicesCategory.setProgress(mBluetoothAdapter.isDiscovering());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,11 +85,11 @@ public class BluetoothPairingDetail extends DeviceListPreferenceFragment impleme
|
||||
|
||||
@VisibleForTesting
|
||||
void updateBluetooth() {
|
||||
if (mLocalAdapter.isEnabled()) {
|
||||
updateContent(mLocalAdapter.getBluetoothState());
|
||||
if (mBluetoothAdapter.isEnabled()) {
|
||||
updateContent(mBluetoothAdapter.getState());
|
||||
} else {
|
||||
// Turn on bluetooth if it is disabled
|
||||
mLocalAdapter.enable();
|
||||
mBluetoothAdapter.enable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ public class BluetoothPairingDetail extends DeviceListPreferenceFragment impleme
|
||||
switch (bluetoothState) {
|
||||
case BluetoothAdapter.STATE_ON:
|
||||
mDevicePreferenceMap.clear();
|
||||
mLocalAdapter.setBluetoothEnabled(true);
|
||||
mBluetoothAdapter.enable();
|
||||
|
||||
addDeviceCategory(mAvailableDevicesCategory,
|
||||
R.string.bluetooth_preference_found_media_devices,
|
||||
|
@@ -33,8 +33,6 @@ import com.android.settings.SubSettings;
|
||||
import com.android.settings.connecteddevice.BluetoothDashboardFragment;
|
||||
import com.android.settings.slices.SliceBroadcastReceiver;
|
||||
import com.android.settings.slices.SliceBuilderUtils;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
import androidx.slice.Slice;
|
||||
@@ -119,10 +117,13 @@ public class BluetoothSliceBuilder {
|
||||
*/
|
||||
public static void handleUriChange(Context context, Intent intent) {
|
||||
final boolean newBluetoothState = intent.getBooleanExtra(EXTRA_TOGGLE_STATE, false);
|
||||
final LocalBluetoothAdapter adapter = LocalBluetoothManager.getInstance(context,
|
||||
null /* callback */).getBluetoothAdapter();
|
||||
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
|
||||
adapter.setBluetoothEnabled(newBluetoothState);
|
||||
if (newBluetoothState) {
|
||||
adapter.enable();
|
||||
} else {
|
||||
adapter.disable();
|
||||
}
|
||||
// Do not notifyChange on Uri. The service takes longer to update the current value than it
|
||||
// does for the Slice to check the current value again. Let {@link SliceBroadcastRelay}
|
||||
// handle it.
|
||||
|
@@ -25,7 +25,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.widget.SummaryUpdater;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -39,15 +38,14 @@ import androidx.annotation.VisibleForTesting;
|
||||
public final class BluetoothSummaryUpdater extends SummaryUpdater implements BluetoothCallback {
|
||||
private static final String TAG = "BluetoothSummaryUpdater";
|
||||
|
||||
private final BluetoothAdapter mBluetoothAdapter;
|
||||
private final LocalBluetoothManager mBluetoothManager;
|
||||
private final LocalBluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
public BluetoothSummaryUpdater(Context context, OnSummaryChangeListener listener,
|
||||
LocalBluetoothManager bluetoothManager) {
|
||||
super(context, listener);
|
||||
mBluetoothManager = bluetoothManager;
|
||||
mBluetoothAdapter = mBluetoothManager != null
|
||||
? mBluetoothManager.getBluetoothAdapter() : null;
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -26,8 +26,6 @@ import com.android.settings.location.ScanningSettings;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.utils.AnnotationSpan;
|
||||
import com.android.settings.widget.SwitchWidgetController;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
@@ -43,10 +41,6 @@ public class BluetoothSwitchPreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop,
|
||||
SwitchWidgetController.OnSwitchChangeListener, View.OnClickListener {
|
||||
|
||||
@VisibleForTesting
|
||||
LocalBluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
private LocalBluetoothManager mBluetoothManager;
|
||||
private BluetoothEnabler mBluetoothEnabler;
|
||||
private RestrictionUtils mRestrictionUtils;
|
||||
private SwitchWidgetController mSwitch;
|
||||
@@ -56,15 +50,12 @@ public class BluetoothSwitchPreferenceController
|
||||
public BluetoothSwitchPreferenceController(Context context,
|
||||
SwitchWidgetController switchController,
|
||||
FooterPreference footerPreference) {
|
||||
this(context, Utils.getLocalBtManager(context), new RestrictionUtils(), switchController,
|
||||
footerPreference);
|
||||
this(context, new RestrictionUtils(), switchController, footerPreference);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public BluetoothSwitchPreferenceController(Context context,
|
||||
LocalBluetoothManager bluetoothManager, RestrictionUtils restrictionUtils,
|
||||
public BluetoothSwitchPreferenceController(Context context, RestrictionUtils restrictionUtils,
|
||||
SwitchWidgetController switchController, FooterPreference footerPreference) {
|
||||
mBluetoothManager = bluetoothManager;
|
||||
mRestrictionUtils = restrictionUtils;
|
||||
mSwitch = switchController;
|
||||
mContext = context;
|
||||
@@ -73,12 +64,9 @@ public class BluetoothSwitchPreferenceController
|
||||
mSwitch.setupView();
|
||||
updateText(mSwitch.isChecked());
|
||||
|
||||
if (mBluetoothManager != null) {
|
||||
mBluetoothAdapter = mBluetoothManager.getBluetoothAdapter();
|
||||
}
|
||||
mBluetoothEnabler = new BluetoothEnabler(context,
|
||||
switchController,
|
||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider(), mBluetoothManager,
|
||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider(),
|
||||
MetricsEvent.ACTION_SETTINGS_MASTER_SWITCH_BLUETOOTH_TOGGLE,
|
||||
mRestrictionUtils);
|
||||
mBluetoothEnabler.setToggleCallback(this);
|
||||
|
@@ -28,7 +28,6 @@ import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -64,7 +63,7 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
|
||||
BluetoothDevice mSelectedDevice;
|
||||
|
||||
LocalBluetoothAdapter mLocalAdapter;
|
||||
BluetoothAdapter mBluetoothAdapter;
|
||||
LocalBluetoothManager mLocalManager;
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -97,7 +96,7 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
Log.e(TAG, "Bluetooth is not supported on this device");
|
||||
return;
|
||||
}
|
||||
mLocalAdapter = mLocalManager.getBluetoothAdapter();
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mShowDevicesWithoutNames = SystemProperties.getBoolean(
|
||||
BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, false);
|
||||
|
||||
@@ -146,7 +145,7 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
if (KEY_BT_SCAN.equals(preference.getKey())) {
|
||||
mLocalAdapter.startScanning(true);
|
||||
startScanning();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -172,7 +171,7 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
}
|
||||
|
||||
// Prevent updates while the list shows one of the state messages
|
||||
if (mLocalAdapter.getBluetoothState() != BluetoothAdapter.STATE_ON) return;
|
||||
if (mBluetoothAdapter.getState() != BluetoothAdapter.STATE_ON) return;
|
||||
|
||||
if (mFilter.matches(cachedDevice.getDevice())) {
|
||||
createDevicePreference(cachedDevice);
|
||||
@@ -214,7 +213,7 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
|
||||
myDevicePreference.setTitle(getString(
|
||||
R.string.bluetooth_footer_mac_message,
|
||||
bidiFormatter.unicodeWrap(mLocalAdapter.getAddress())));
|
||||
bidiFormatter.unicodeWrap(mBluetoothAdapter.getAddress())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -227,21 +226,21 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
|
||||
@VisibleForTesting
|
||||
void enableScanning() {
|
||||
// LocalBluetoothAdapter already handles repeated scan requests
|
||||
mLocalAdapter.startScanning(true);
|
||||
// BluetoothAdapter already handles repeated scan requests
|
||||
startScanning();
|
||||
mScanEnabled = true;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void disableScanning() {
|
||||
mLocalAdapter.stopScanning();
|
||||
stopScanning();
|
||||
mScanEnabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanningStateChanged(boolean started) {
|
||||
if (!started && mScanEnabled) {
|
||||
mLocalAdapter.startScanning(true);
|
||||
startScanning();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,4 +286,16 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
public boolean shouldShowDevicesWithoutNames() {
|
||||
return mShowDevicesWithoutNames;
|
||||
}
|
||||
|
||||
void startScanning() {
|
||||
if (!mBluetoothAdapter.isDiscovering()) {
|
||||
mBluetoothAdapter.startDiscovery();
|
||||
}
|
||||
}
|
||||
|
||||
void stopScanning() {
|
||||
if (mBluetoothAdapter.isDiscovering()) {
|
||||
mBluetoothAdapter.cancelDiscovery();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -94,7 +94,7 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment {
|
||||
mSelectedDevice = null;
|
||||
if (mScanAllowed) {
|
||||
enableScanning();
|
||||
mAvailableDevicesCategory.setProgress(mLocalAdapter.isDiscovering());
|
||||
mAvailableDevicesCategory.setProgress(mBluetoothAdapter.isDiscovering());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -16,13 +16,13 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,7 @@ final class LocalBluetoothPreferences {
|
||||
}
|
||||
|
||||
// If the device was discoverING recently
|
||||
LocalBluetoothAdapter adapter = manager.getBluetoothAdapter();
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (adapter != null) {
|
||||
if (adapter.isDiscovering()) {
|
||||
return true;
|
||||
|
@@ -25,13 +25,11 @@ import android.os.Bundle;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
/** Provides a dialog for changing the advertised name of the local bluetooth adapter. */
|
||||
public class LocalDeviceNameDialogFragment extends BluetoothNameDialogFragment {
|
||||
public static final String TAG = "LocalAdapterName";
|
||||
private LocalBluetoothAdapter mLocalAdapter;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
public static LocalDeviceNameDialogFragment newInstance() {
|
||||
return new LocalDeviceNameDialogFragment();
|
||||
@@ -53,8 +51,7 @@ public class LocalDeviceNameDialogFragment extends BluetoothNameDialogFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
LocalBluetoothManager localManager = Utils.getLocalBtManager(getActivity());
|
||||
mLocalAdapter = localManager.getBluetoothAdapter();
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,14 +81,14 @@ public class LocalDeviceNameDialogFragment extends BluetoothNameDialogFragment {
|
||||
|
||||
@Override
|
||||
protected String getDeviceName() {
|
||||
if (mLocalAdapter != null && mLocalAdapter.isEnabled()) {
|
||||
return mLocalAdapter.getName();
|
||||
if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) {
|
||||
return mBluetoothAdapter.getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setDeviceName(String deviceName) {
|
||||
mLocalAdapter.setName(deviceName);
|
||||
mBluetoothAdapter.setName(deviceName);
|
||||
}
|
||||
}
|
||||
|
@@ -34,8 +34,6 @@ import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.bluetooth.BluetoothDiscoverableTimeoutReceiver;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
@@ -58,7 +56,7 @@ public class RequestPermissionActivity extends Activity implements
|
||||
static final int REQUEST_ENABLE_DISCOVERABLE = 2;
|
||||
static final int REQUEST_DISABLE = 3;
|
||||
|
||||
private LocalBluetoothAdapter mLocalAdapter;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
private int mTimeout = BluetoothDiscoverableEnabler.DEFAULT_DISCOVERABLE_TIMEOUT;
|
||||
|
||||
@@ -76,13 +74,13 @@ public class RequestPermissionActivity extends Activity implements
|
||||
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
|
||||
// Note: initializes mLocalAdapter and returns true on error
|
||||
// Note: initializes mBluetoothAdapter and returns true on error
|
||||
if (parseIntent()) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
int btState = mLocalAdapter.getState();
|
||||
int btState = mBluetoothAdapter.getState();
|
||||
|
||||
if (mRequest == REQUEST_DISABLE) {
|
||||
switch (btState) {
|
||||
@@ -204,7 +202,7 @@ public class RequestPermissionActivity extends Activity implements
|
||||
switch (mRequest) {
|
||||
case REQUEST_ENABLE:
|
||||
case REQUEST_ENABLE_DISCOVERABLE: {
|
||||
if (mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON) {
|
||||
if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
|
||||
proceedAndFinish();
|
||||
} else {
|
||||
// If BT is not up yet, show "Turning on Bluetooth..."
|
||||
@@ -216,7 +214,7 @@ public class RequestPermissionActivity extends Activity implements
|
||||
} break;
|
||||
|
||||
case REQUEST_DISABLE: {
|
||||
if (mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_OFF) {
|
||||
if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) {
|
||||
proceedAndFinish();
|
||||
} else {
|
||||
// If BT is not up yet, show "Turning off Bluetooth..."
|
||||
@@ -252,7 +250,7 @@ public class RequestPermissionActivity extends Activity implements
|
||||
if (mRequest == REQUEST_ENABLE || mRequest == REQUEST_DISABLE) {
|
||||
// BT toggled. Done
|
||||
returnCode = RESULT_OK;
|
||||
} else if (mLocalAdapter.setScanMode(
|
||||
} else if (mBluetoothAdapter.setScanMode(
|
||||
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, mTimeout)) {
|
||||
// If already in discoverable mode, this will extend the timeout.
|
||||
long endTime = System.currentTimeMillis() + (long) mTimeout * 1000;
|
||||
@@ -284,7 +282,7 @@ public class RequestPermissionActivity extends Activity implements
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the received Intent and initialize mLocalBluetoothAdapter.
|
||||
* Parse the received Intent and initialize mBluetoothAdapter.
|
||||
* @return true if an error occurred; false otherwise
|
||||
*/
|
||||
private boolean parseIntent() {
|
||||
@@ -314,13 +312,6 @@ public class RequestPermissionActivity extends Activity implements
|
||||
return true;
|
||||
}
|
||||
|
||||
LocalBluetoothManager manager = Utils.getLocalBtManager(this);
|
||||
if (manager == null) {
|
||||
Log.e(TAG, "Error: there's a problem starting Bluetooth");
|
||||
setResult(RESULT_CANCELED);
|
||||
return true;
|
||||
}
|
||||
|
||||
String packageName = getCallingPackage();
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
packageName = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME);
|
||||
@@ -340,7 +331,12 @@ public class RequestPermissionActivity extends Activity implements
|
||||
}
|
||||
}
|
||||
|
||||
mLocalAdapter = manager.getBluetoothAdapter();
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (mBluetoothAdapter == null) {
|
||||
Log.e(TAG, "Error: there's a problem starting Bluetooth");
|
||||
setResult(RESULT_CANCELED);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@@ -28,8 +28,6 @@ import android.util.Log;
|
||||
import com.android.internal.app.AlertActivity;
|
||||
import com.android.internal.app.AlertController;
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
/**
|
||||
* RequestPermissionHelperActivity asks the user whether to toggle Bluetooth.
|
||||
@@ -49,7 +47,7 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
|
||||
public static final String EXTRA_APP_LABEL =
|
||||
"com.android.settings.bluetooth.extra.APP_LABEL";
|
||||
|
||||
private LocalBluetoothAdapter mLocalAdapter;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
private CharSequence mAppLabel;
|
||||
|
||||
@@ -63,7 +61,7 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
|
||||
|
||||
setResult(RESULT_CANCELED);
|
||||
|
||||
// Note: initializes mLocalAdapter and returns true on error
|
||||
// Note: initializes mBluetoothAdapter and returns true on error
|
||||
if (!parseIntent()) {
|
||||
finish();
|
||||
return;
|
||||
@@ -131,20 +129,20 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
|
||||
startActivity(intent);
|
||||
}
|
||||
} else {
|
||||
mLocalAdapter.enable();
|
||||
mBluetoothAdapter.enable();
|
||||
setResult(Activity.RESULT_OK);
|
||||
}
|
||||
} break;
|
||||
|
||||
case RequestPermissionActivity.REQUEST_DISABLE: {
|
||||
mLocalAdapter.disable();
|
||||
mBluetoothAdapter.disable();
|
||||
setResult(Activity.RESULT_OK);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the received Intent and initialize mLocalBluetoothAdapter.
|
||||
* Parse the received Intent and initialize mBluetoothAdapter.
|
||||
* @return true if an error occurred; false otherwise
|
||||
*/
|
||||
private boolean parseIntent() {
|
||||
@@ -167,16 +165,14 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
|
||||
return false;
|
||||
}
|
||||
|
||||
LocalBluetoothManager manager = Utils.getLocalBtManager(this);
|
||||
if (manager == null) {
|
||||
mAppLabel = getIntent().getCharSequenceExtra(EXTRA_APP_LABEL);
|
||||
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (mBluetoothAdapter == null) {
|
||||
Log.e(TAG, "Error: there's a problem starting Bluetooth");
|
||||
return false;
|
||||
}
|
||||
|
||||
mAppLabel = getIntent().getCharSequenceExtra(EXTRA_APP_LABEL);
|
||||
|
||||
mLocalAdapter = manager.getBluetoothAdapter();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -30,7 +30,6 @@ import com.android.settings.bluetooth.AlwaysDiscoverable;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
@@ -54,7 +53,7 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
|
||||
LocalBluetoothManager mLocalManager;
|
||||
private FooterPreferenceMixinCompat mFooterPreferenceMixin;
|
||||
private FooterPreference mPreference;
|
||||
private LocalBluetoothAdapter mLocalAdapter;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private AlwaysDiscoverable mAlwaysDiscoverable;
|
||||
|
||||
public DiscoverableFooterPreferenceController(Context context) {
|
||||
@@ -63,8 +62,8 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
|
||||
if (mLocalManager == null) {
|
||||
return;
|
||||
}
|
||||
mLocalAdapter = mLocalManager.getBluetoothAdapter();
|
||||
mAlwaysDiscoverable = new AlwaysDiscoverable(context, mLocalAdapter);
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mAlwaysDiscoverable = new AlwaysDiscoverable(context);
|
||||
initReceiver();
|
||||
}
|
||||
|
||||
@@ -121,7 +120,7 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
|
||||
mContext.registerReceiver(mBluetoothChangedReceiver,
|
||||
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
|
||||
mAlwaysDiscoverable.start();
|
||||
updateFooterPreferenceTitle(mLocalAdapter.getState());
|
||||
updateFooterPreferenceTitle(mBluetoothAdapter.getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,7 +141,7 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
|
||||
}
|
||||
|
||||
private CharSequence getPreferenceTitle() {
|
||||
final String deviceName = mLocalAdapter.getName();
|
||||
final String deviceName = mBluetoothAdapter.getName();
|
||||
if (TextUtils.isEmpty(deviceName)) {
|
||||
return null;
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
@@ -29,8 +29,6 @@ import com.android.settings.bluetooth.BluetoothLengthDeviceNameFilter;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||
import com.android.settings.wifi.tether.WifiDeviceNameTextValidator;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnCreate;
|
||||
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
|
||||
@@ -49,10 +47,9 @@ public class DeviceNamePreferenceController extends BasePreferenceController
|
||||
private static final String KEY_PENDING_DEVICE_NAME = "key_pending_device_name";
|
||||
private String mDeviceName;
|
||||
protected WifiManager mWifiManager;
|
||||
private final BluetoothAdapter mBluetoothAdapter;
|
||||
private final WifiDeviceNameTextValidator mWifiDeviceNameTextValidator;
|
||||
private ValidatedEditTextPreference mPreference;
|
||||
@Nullable
|
||||
private LocalBluetoothManager mBluetoothManager;
|
||||
private DeviceNamePreferenceHost mHost;
|
||||
private String mPendingDeviceName;
|
||||
|
||||
@@ -61,6 +58,7 @@ public class DeviceNamePreferenceController extends BasePreferenceController
|
||||
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
mWifiDeviceNameTextValidator = new WifiDeviceNameTextValidator();
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
|
||||
initializeDeviceName();
|
||||
}
|
||||
@@ -115,10 +113,6 @@ public class DeviceNamePreferenceController extends BasePreferenceController
|
||||
return mWifiDeviceNameTextValidator.isTextValid(deviceName);
|
||||
}
|
||||
|
||||
public void setLocalBluetoothManager(LocalBluetoothManager localBluetoothManager) {
|
||||
mBluetoothManager = localBluetoothManager;
|
||||
}
|
||||
|
||||
public void confirmDeviceName() {
|
||||
if (mPendingDeviceName != null) {
|
||||
setDeviceName(mPendingDeviceName);
|
||||
@@ -146,14 +140,8 @@ public class DeviceNamePreferenceController extends BasePreferenceController
|
||||
}
|
||||
|
||||
private void setBluetoothDeviceName(String deviceName) {
|
||||
// Bluetooth manager doesn't exist for certain devices.
|
||||
if (mBluetoothManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final LocalBluetoothAdapter localBluetoothAdapter = mBluetoothManager.getBluetoothAdapter();
|
||||
if (localBluetoothAdapter != null) {
|
||||
localBluetoothAdapter.setName(getFilteredBluetoothString(deviceName));
|
||||
if (mBluetoothAdapter != null) {
|
||||
mBluetoothAdapter.setName(getFilteredBluetoothString(deviceName));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.settings.deviceinfo.aboutphone;
|
||||
|
||||
import static com.android.settings.bluetooth.Utils.getLocalBtManager;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -116,7 +114,6 @@ public class MyDeviceInfoFragment extends DashboardFragment
|
||||
controllers.add(new BrandedAccountPreferenceController(context));
|
||||
DeviceNamePreferenceController deviceNamePreferenceController =
|
||||
new DeviceNamePreferenceController(context);
|
||||
deviceNamePreferenceController.setLocalBluetoothManager(getLocalBtManager(context));
|
||||
deviceNamePreferenceController.setHost(fragment);
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(deviceNamePreferenceController);
|
||||
|
@@ -40,9 +40,6 @@ import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
/**
|
||||
* Provides control of power-related settings from a widget.
|
||||
@@ -54,7 +51,7 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
|
||||
new ComponentName("com.android.settings",
|
||||
"com.android.settings.widget.SettingsAppWidgetProvider");
|
||||
|
||||
private static LocalBluetoothAdapter sLocalBluetoothAdapter = null;
|
||||
private static BluetoothAdapter sBluetoothAdapter = null;
|
||||
|
||||
private static final int BUTTON_WIFI = 0;
|
||||
private static final int BUTTON_BRIGHTNESS = 1;
|
||||
@@ -450,23 +447,19 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
|
||||
|
||||
@Override
|
||||
public int getActualState(Context context) {
|
||||
if (sLocalBluetoothAdapter == null) {
|
||||
LocalBluetoothManager manager = Utils.getLocalBtManager(context);
|
||||
if (manager == null) {
|
||||
return STATE_UNKNOWN; // On emulator?
|
||||
}
|
||||
sLocalBluetoothAdapter = manager.getBluetoothAdapter();
|
||||
if (sLocalBluetoothAdapter == null) {
|
||||
if (sBluetoothAdapter == null) {
|
||||
sBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (sBluetoothAdapter == null) {
|
||||
return STATE_UNKNOWN; // On emulator?
|
||||
}
|
||||
}
|
||||
return bluetoothStateToFiveState(sLocalBluetoothAdapter.getBluetoothState());
|
||||
return bluetoothStateToFiveState(sBluetoothAdapter.getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void requestStateChange(Context context, final boolean desiredState) {
|
||||
if (sLocalBluetoothAdapter == null) {
|
||||
Log.d(TAG, "No LocalBluetoothManager");
|
||||
if (sBluetoothAdapter == null) {
|
||||
Log.d(TAG, "No BluetoothAdapter");
|
||||
return;
|
||||
}
|
||||
// Actually request the Bluetooth change and persistent
|
||||
@@ -476,7 +469,11 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... args) {
|
||||
sLocalBluetoothAdapter.setBluetoothEnabled(desiredState);
|
||||
if (desiredState) {
|
||||
sBluetoothAdapter.enable();
|
||||
} else {
|
||||
sBluetoothAdapter.disable();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.execute();
|
||||
|
Reference in New Issue
Block a user