Merge changes from topics "ap_shutdown_timeout_flag", "scan_always_available_API"
* changes: Settings: Use new API for setting wifi scan always on Settings: Use new API for tethering auto shutdown
This commit is contained in:
@@ -24,7 +24,6 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
@@ -80,8 +79,7 @@ public class WifiScanModeActivity extends FragmentActivity {
|
||||
}
|
||||
|
||||
private void doPositiveClick() {
|
||||
Settings.Global.putInt(getContentResolver(),
|
||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
getApplicationContext().getSystemService(WifiManager.class).setScanAlwaysAvailable(true);
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
|
@@ -23,8 +23,8 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
@@ -69,8 +69,7 @@ public class WifiScanningRequiredFragment extends InstrumentedDialogFragment imp
|
||||
ContentResolver contentResolver = context.getContentResolver();
|
||||
switch(which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
Settings.Global.putInt(contentResolver,
|
||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
context.getSystemService(WifiManager.class).setScanAlwaysAvailable(true);
|
||||
Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.wifi_settings_scanning_required_enabled),
|
||||
|
@@ -1048,8 +1048,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
final PowerManager powerManager = context.getSystemService(PowerManager.class);
|
||||
final ContentResolver contentResolver = context.getContentResolver();
|
||||
return mWifiManager.isAutoWakeupEnabled()
|
||||
&& Settings.Global.getInt(contentResolver,
|
||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1
|
||||
&& mWifiManager.isScanAlwaysAvailable()
|
||||
&& Settings.Global.getInt(contentResolver,
|
||||
Settings.Global.AIRPLANE_MODE_ON, 0) == 0
|
||||
&& !powerManager.isPowerSaveMode();
|
||||
@@ -1060,8 +1059,8 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
// Don't use WifiManager.isScanAlwaysAvailable() to check the Wi-Fi scanning mode. Instead,
|
||||
// read the system settings directly. Because when the device is in Airplane mode, even if
|
||||
// Wi-Fi scanning mode is on, WifiManager.isScanAlwaysAvailable() still returns "off".
|
||||
final boolean wifiScanningMode = Settings.Global.getInt(getActivity().getContentResolver(),
|
||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1;
|
||||
// TODO(b/149421497): Fix this?
|
||||
final boolean wifiScanningMode = mWifiManager.isScanAlwaysAvailable();
|
||||
final CharSequence description = wifiScanningMode ? getText(R.string.wifi_scan_notify_text)
|
||||
: getText(R.string.wifi_scan_notify_text_scanning_off);
|
||||
final LinkifyUtils.OnClickListener clickListener =
|
||||
|
@@ -852,8 +852,7 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
||||
final PowerManager powerManager = context.getSystemService(PowerManager.class);
|
||||
final ContentResolver contentResolver = context.getContentResolver();
|
||||
return mWifiManager.isAutoWakeupEnabled()
|
||||
&& Settings.Global.getInt(contentResolver,
|
||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1
|
||||
&& mWifiManager.isScanAlwaysAvailable()
|
||||
&& Settings.Global.getInt(contentResolver,
|
||||
Settings.Global.AIRPLANE_MODE_ON, 0) == 0
|
||||
&& !powerManager.isPowerSaveMode();
|
||||
@@ -864,8 +863,8 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
||||
// Don't use WifiManager.isScanAlwaysAvailable() to check the Wi-Fi scanning mode. Instead,
|
||||
// read the system settings directly. Because when the device is in Airplane mode, even if
|
||||
// Wi-Fi scanning mode is on, WifiManager.isScanAlwaysAvailable() still returns "off".
|
||||
final boolean wifiScanningMode = Settings.Global.getInt(getActivity().getContentResolver(),
|
||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1;
|
||||
// TODO(b/149421497): Fix this?
|
||||
final boolean wifiScanningMode = mWifiManager.isScanAlwaysAvailable();
|
||||
final CharSequence description = wifiScanningMode ? getText(R.string.wifi_scan_notify_text)
|
||||
: getText(R.string.wifi_scan_notify_text_scanning_off);
|
||||
final LinkifyUtils.OnClickListener clickListener =
|
||||
|
@@ -153,8 +153,7 @@ public class WifiWakeupPreferenceController extends TogglePreferenceController i
|
||||
}
|
||||
|
||||
private boolean getWifiScanningEnabled() {
|
||||
return Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1;
|
||||
return mWifiManager.isScanAlwaysAvailable();
|
||||
}
|
||||
|
||||
private void showScanningDialog() {
|
||||
|
@@ -17,7 +17,8 @@
|
||||
package com.android.settings.wifi.tether;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
@@ -27,8 +28,11 @@ import com.android.settings.core.BasePreferenceController;
|
||||
public class WifiTetherAutoOffPreferenceController extends BasePreferenceController implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
|
||||
private final WifiManager mWifiManager;
|
||||
|
||||
public WifiTetherAutoOffPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mWifiManager = context.getSystemService(WifiManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,8 +42,8 @@ public class WifiTetherAutoOffPreferenceController extends BasePreferenceControl
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final boolean settingsOn = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.SOFT_AP_TIMEOUT_ENABLED, 1) != 0;
|
||||
SoftApConfiguration softApConfiguration = mWifiManager.getSoftApConfiguration();
|
||||
final boolean settingsOn = softApConfiguration.isAutoShutdownEnabled();
|
||||
|
||||
((SwitchPreference) preference).setChecked(settingsOn);
|
||||
}
|
||||
@@ -47,8 +51,11 @@ public class WifiTetherAutoOffPreferenceController extends BasePreferenceControl
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean settingsOn = (Boolean) newValue;
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.SOFT_AP_TIMEOUT_ENABLED, settingsOn ? 1 : 0);
|
||||
return true;
|
||||
SoftApConfiguration softApConfiguration = mWifiManager.getSoftApConfiguration();
|
||||
SoftApConfiguration newSoftApConfiguration =
|
||||
new SoftApConfiguration.Builder(softApConfiguration)
|
||||
.setAutoShutdownEnabled(settingsOn)
|
||||
.build();
|
||||
return mWifiManager.setSoftApConfiguration(newSoftApConfiguration);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user