Do not turn on NFC automatically when airplane mode is off.
- besides checking the value for AIRPLANE_MODE_TOGGLEABLE_RADIOS, also check the value for AIRPLANE_MODE_RADIOS to determine if we should turn off NFC when airplane mode is on. - when user turns off airplane mode, only re-enable the NFC preference and do not enable NFC by default. - remove listening to airplane mode directly from the android beam preference controller, as it is already listening to Nfc state, which handles the beam state already. Change-Id: Id41fef15fb2de873729d20d7f53b1a88b164cf95 Fixes: 80217047 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -20,7 +20,7 @@ import android.content.IntentFilter;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
@@ -37,7 +37,8 @@ public class NfcPreferenceController extends TogglePreferenceController
|
||||
public static final String KEY_TOGGLE_NFC = "toggle_nfc";
|
||||
private final NfcAdapter mNfcAdapter;
|
||||
private NfcEnabler mNfcEnabler;
|
||||
private NfcAirplaneModeObserver mAirplaneModeObserver;
|
||||
@VisibleForTesting
|
||||
NfcAirplaneModeObserver mAirplaneModeObserver;
|
||||
|
||||
public NfcPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
@@ -57,10 +58,10 @@ public class NfcPreferenceController extends TogglePreferenceController
|
||||
|
||||
mNfcEnabler = new NfcEnabler(mContext, switchPreference);
|
||||
|
||||
// Manually set dependencies for NFC when not toggleable.
|
||||
if (!isToggleableInAirplaneMode(mContext)) {
|
||||
mAirplaneModeObserver = new NfcAirplaneModeObserver(mContext,
|
||||
mNfcAdapter, (Preference) switchPreference);
|
||||
// Listen to airplane mode updates if NFC should be turned off when airplane mode is on
|
||||
if (shouldTurnOffNFCInAirplaneMode(mContext) || isToggleableInAirplaneMode(mContext)) {
|
||||
mAirplaneModeObserver =
|
||||
new NfcAirplaneModeObserver(mContext, mNfcAdapter, switchPreference);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +126,12 @@ public class NfcPreferenceController extends TogglePreferenceController
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean shouldTurnOffNFCInAirplaneMode(Context context) {
|
||||
final String airplaneModeRadios = Settings.Global.getString(context.getContentResolver(),
|
||||
Settings.Global.AIRPLANE_MODE_RADIOS);
|
||||
return airplaneModeRadios != null && airplaneModeRadios.contains(Settings.Global.RADIO_NFC);
|
||||
}
|
||||
|
||||
public static boolean isToggleableInAirplaneMode(Context context) {
|
||||
final String toggleable = Settings.Global.getString(context.getContentResolver(),
|
||||
Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
|
||||
|
Reference in New Issue
Block a user