New pref toggle for network recommendations.

Adding a new toggle to control whether network
recommendations are enabled.

Removed the "Use open networks" pref and its associated strings
and components as it's no longer needed.

Test: Built and ran.
BUG: 33549591
BUG: 33270391
Change-Id: I7248ac32e0598d82107c150372c1fe4e9e2243a5
This commit is contained in:
Jeremy Joslin
2016-12-13 14:14:45 -08:00
parent af71eb20c8
commit 66e6027da0
4 changed files with 19 additions and 87 deletions

View File

@@ -2565,16 +2565,6 @@
</intent-filter>
</activity>
<activity android:name=".ActiveNetworkScorerDialog"
android:label="@string/wifi_assistant_title"
android:excludeFromRecents="true"
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert">
<intent-filter android:priority="1">
<action android:name="android.net.scoring.CHANGE_ACTIVE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="Settings$NotificationAccessSettingsActivity"
android:label="@string/manage_notification_access_title"
android:taskAffinity="">

View File

@@ -1471,9 +1471,6 @@
<!-- Bluetooth settings. Dock Setting Dialog - Remember setting and don't ask user again -->
<string name="bluetooth_dock_settings_remember">Remember settings</string>
<!-- Wifi Assistant title. [CHAR LIMIT=40] -->
<string name="wifi_assistant_title">Wi\u2011Fi Assistant</string>
<!-- Wifi Display settings. The title of the screen. [CHAR LIMIT=40] -->
<string name="wifi_display_settings_title">Cast</string>
<!-- Wifi Display settings. The title of a menu item to enable wireless display [CHAR LIMIT=40] -->
@@ -1592,12 +1589,12 @@
<string name="wifi_poor_network_detection_summary">Don\u2019t use a Wi\u2011Fi network unless it has a good Internet connection</string>
<!-- Checkbox summary for option to toggle poor network detection [CHAR LIMIT=60] -->
<string name="wifi_avoid_poor_network_detection_summary">Only use networks that have a good Internet connection</string>
<!-- Checkbox title for option to connect to open Wi-Fi automatically [CHAR LIMIT=40] -->
<string name="wifi_automatically_connect_title">Use open Wi\u2011Fi automatically</string>
<!-- Checkbox summary for option to connect to open Wi-Fi automatically [CHAR LIMIT=100] -->
<string name="wifi_automatically_connect_summary">Let a Wi\u2011Fi assistant automatically connect to open networks determined to be high quality</string>
<!-- Dialog title for option to select an app which connects to open Wi-Fi automatically [CHAR LIMIT=40] -->
<string name="wifi_select_assistant_dialog_title">Choose assistant</string>
<!-- Network recommendations toggle -->
<!--TODO(jjoslin): Provide final strings and mark for translation. BUG: 32913919 -->
<string translatable="false" name="networking_allow_recommendations_title">Use network recommendations</string>
<string translatable="false" name="networking_allow_recommendations_summary">When enabled, use network recommendations when selecting the Wi\u2011Fi network to connect to</string>
<!-- Preference title for option to install certificates -->
<string name="wifi_install_credentials">Install certificates</string>
<!-- Message to describe "Wi-Fi scan always available feature" when Wi-Fi is off. The

View File

@@ -35,11 +35,10 @@
android:entries="@array/wifi_sleep_policy_entries"
android:entryValues="@array/wifi_sleep_policy_values" />
<com.android.settings.AppListSwitchPreference
android:key="wifi_assistant"
android:title="@string/wifi_automatically_connect_title"
android:summary="@string/wifi_automatically_connect_summary"
android:dialogTitle="@string/wifi_select_assistant_dialog_title" />
<SwitchPreference
android:key="allow_recommendations"
android:title="@string/networking_allow_recommendations_title"
android:summary="@string/networking_allow_recommendations_summary"/>
<SwitchPreference
android:key="wifi_cellular_data_fallback"

View File

@@ -19,14 +19,10 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.net.NetworkScoreManager;
import android.net.NetworkScorerAppManager;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.UserManager;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.ListPreference;
@@ -35,12 +31,9 @@ import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.AppListSwitchPreference;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import java.util.Collection;
import java.util.List;
public class ConfigureWifiSettings extends SettingsPreferenceFragment
@@ -53,12 +46,9 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
private static final String KEY_NOTIFY_OPEN_NETWORKS = "notify_open_networks";
private static final String KEY_SLEEP_POLICY = "sleep_policy";
private static final String KEY_CELLULAR_FALLBACK = "wifi_cellular_data_fallback";
private static final String KEY_WIFI_ASSISTANT = "wifi_assistant";
private static final String KEY_ALLOW_RECOMMENDATIONS = "allow_recommendations";
private WifiManager mWifiManager;
private NetworkScoreManager mNetworkScoreManager;
private AppListSwitchPreference mWifiAssistantPreference;
private IntentFilter mFilter;
@Override
@@ -74,8 +64,6 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
mFilter = new IntentFilter();
mFilter.addAction(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION);
mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
mNetworkScoreManager =
(NetworkScoreManager) getSystemService(Context.NETWORK_SCORE_SERVICE);
}
@Override
@@ -119,15 +107,10 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
}
}
mWifiAssistantPreference = (AppListSwitchPreference) findPreference(KEY_WIFI_ASSISTANT);
Collection<NetworkScorerAppManager.NetworkScorerAppData> scorers =
new NetworkScorerAppManager(context).getAllValidScorers();
if (UserManager.get(context).isAdminUser() && !scorers.isEmpty()) {
mWifiAssistantPreference.setOnPreferenceChangeListener(this);
initWifiAssistantPreference(scorers);
} else if (mWifiAssistantPreference != null) {
getPreferenceScreen().removePreference(mWifiAssistantPreference);
}
SwitchPreference allowRecommendations =
(SwitchPreference) findPreference(KEY_ALLOW_RECOMMENDATIONS);
allowRecommendations.setChecked(Settings.Global.getInt(getContentResolver(),
Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1);
ListPreference sleepPolicyPref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
if (sleepPolicyPref != null) {
@@ -187,6 +170,10 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
String settingName = Settings.Global.NETWORK_AVOID_BAD_WIFI;
Settings.Global.putString(getContentResolver(), settingName,
((SwitchPreference) preference).isChecked() ? "1" : null);
} else if (KEY_ALLOW_RECOMMENDATIONS.equals(key)) {
Settings.Global.putInt(getActivity().getContentResolver(),
Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED,
((SwitchPreference) preference).isChecked() ? 1 : 0);
} else {
return super.onPreferenceTreeClick(preference);
}
@@ -198,34 +185,6 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
final Context context = getActivity();
String key = preference.getKey();
if (KEY_WIFI_ASSISTANT.equals(key)) {
NetworkScorerAppManager.NetworkScorerAppData wifiAssistant =
new NetworkScorerAppManager(context).getScorer((String) newValue);
if (wifiAssistant == null) {
mNetworkScoreManager.setActiveScorer(null);
return true;
}
Intent intent = new Intent();
if (wifiAssistant.mConfigurationActivityClassName != null) {
// App has a custom configuration activity; launch that.
// This custom activity will be responsible for launching the system
// dialog.
intent.setClassName(wifiAssistant.mPackageName,
wifiAssistant.mConfigurationActivityClassName);
} else {
// Fall back on the system dialog.
intent.setAction(NetworkScoreManager.ACTION_CHANGE_ACTIVE);
intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME,
wifiAssistant.mPackageName);
}
startActivity(intent);
// Don't update the preference widget state until the child activity returns.
// It will be updated in onResume after the activity finishes.
return false;
}
if (KEY_SLEEP_POLICY.equals(key)) {
try {
String stringValue = (String) newValue;
@@ -259,19 +218,6 @@ public class ConfigureWifiSettings extends SettingsPreferenceFragment
wifiIpAddressPref.setSelectable(false);
}
private void initWifiAssistantPreference(
Collection<NetworkScorerAppManager.NetworkScorerAppData> scorers) {
int count = scorers.size();
String[] packageNames = new String[count];
int i = 0;
for (NetworkScorerAppManager.NetworkScorerAppData scorer : scorers) {
packageNames[i] = scorer.mPackageName;
i++;
}
mWifiAssistantPreference.setPackageNames(packageNames,
mNetworkScoreManager.getActiveScorerPackage());
}
@Override
public int getMetricsCategory() {
return MetricsEvent.CONFIGURE_WIFI;