Update context on resume calls for BluetoothAdvertisingEnabler and BluetoothEnabler

The saved context could be invalid if not updated
bug 12991455

Change-Id: I93abb8420d0fa53add1f0e843a5069d59743891c
This commit is contained in:
Matthew Xie
2014-02-14 16:32:32 -08:00
parent b05f1d0081
commit a504c4dcdf
5 changed files with 20 additions and 11 deletions

View File

@@ -732,7 +732,7 @@ public class SettingsActivity extends Activity
mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
mDevelopmentPreferencesListener);
mHeaderAdapter.resume();
mHeaderAdapter.resume(this);
invalidateHeaders();
registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
@@ -1624,9 +1624,9 @@ public class SettingsActivity extends Activity
holder.mIcon.setImageDrawable(icon);
}
public void resume() {
public void resume(Context context) {
mWifiEnabler.resume();
mBluetoothEnabler.resume();
mBluetoothEnabler.resume(context);
}
public void pause() {

View File

@@ -26,7 +26,7 @@ import com.android.settings.R;
*/
final class BluetoothAdvertisingEnabler {
private final Context mContext;
private Context mContext;
private final PreferenceScreen mBluetoothAdvertisingPreference;
public BluetoothAdvertisingEnabler(Context context, PreferenceScreen bluetoothBroadcast) {
@@ -34,7 +34,10 @@ final class BluetoothAdvertisingEnabler {
mBluetoothAdvertisingPreference = bluetoothBroadcast;
}
public void resume() {
public void resume(Context context) {
if (mContext != context) {
mContext = context;
}
boolean isBroadcastingEnable = LocalBluetoothPreferences.isAdvertisingEnabled(mContext);
handleAdvertisingStateChange(isBroadcastingEnable);
}

View File

@@ -35,7 +35,7 @@ import com.android.settings.WirelessSettings;
* preference reflects the current state.
*/
public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeListener {
private final Context mContext;
private Context mContext;
private Switch mSwitch;
private boolean mValidListener;
private final LocalBluetoothAdapter mLocalAdapter;
@@ -67,12 +67,16 @@ public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeLis
mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
}
public void resume() {
public void resume(Context context) {
if (mLocalAdapter == null) {
mSwitch.setEnabled(false);
return;
}
if (mContext != context) {
mContext = context;
}
// Bluetooth state is not sticky, so set it manually
handleStateChanged(mLocalAdapter.getBluetoothState());

View File

@@ -151,7 +151,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
// resume BluetoothEnabler before calling super.onResume() so we don't get
// any onDeviceAdded() callbacks before setting up view in updateContent()
if (mBluetoothEnabler != null) {
mBluetoothEnabler.resume();
mBluetoothEnabler.resume(getActivity());
}
super.onResume();

View File

@@ -16,6 +16,7 @@
package com.android.settings.bluetooth;
import android.app.Activity;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
@@ -80,9 +81,10 @@ public final class LocalDeviceProfilesSettings extends SettingsPreferenceFragmen
@Override
public void onResume() {
super.onResume();
mManager.setForegroundActivity(getActivity());
mAdvertisingEnabler.resume();
mDiscoverableEnabler.resume(getActivity());
final Activity activity = getActivity();
mManager.setForegroundActivity(activity);
mAdvertisingEnabler.resume(activity);
mDiscoverableEnabler.resume(activity);
}
@Override