Final UX for Wi-Fi assistant platform settings.
When one app is available, the toggle works as before. When multiple apps are available, we allow the user to choose the app in a dialog before turning on the setting. Bug: 13780935 Change-Id: I1c4391bf97a53febe580fb2b896b4850372062e7
This commit is contained in:
@@ -42,6 +42,7 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.settings.AppListSwitchPreference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
@@ -66,6 +67,7 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
|
||||
private WifiManager mWifiManager;
|
||||
private NetworkScoreManager mNetworkScoreManager;
|
||||
private AppListSwitchPreference mWifiAssistantPreference;
|
||||
|
||||
private IntentFilter mFilter;
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@@ -130,18 +132,14 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
pref.setIntent(intent);
|
||||
|
||||
final Context context = getActivity();
|
||||
SwitchPreference wifiAssistant = (SwitchPreference)findPreference(KEY_WIFI_ASSISTANT);
|
||||
NetworkScorerAppData scorer = getWifiAssistantApp(context);
|
||||
if (UserHandle.myUserId() == UserHandle.USER_OWNER && scorer != null) {
|
||||
final boolean checked = NetworkScorerAppManager.getActiveScorer(context) != null;
|
||||
wifiAssistant.setSummary(getResources().getString(
|
||||
R.string.wifi_automatically_manage_summary, scorer.mScorerName));
|
||||
wifiAssistant.setOnPreferenceChangeListener(this);
|
||||
wifiAssistant.setChecked(checked);
|
||||
} else {
|
||||
if (wifiAssistant != null) {
|
||||
getPreferenceScreen().removePreference(wifiAssistant);
|
||||
}
|
||||
mWifiAssistantPreference = (AppListSwitchPreference) findPreference(KEY_WIFI_ASSISTANT);
|
||||
Collection<NetworkScorerAppData> scorers =
|
||||
NetworkScorerAppManager.getAllValidScorers(context);
|
||||
if (UserHandle.myUserId() == UserHandle.USER_OWNER && !scorers.isEmpty()) {
|
||||
mWifiAssistantPreference.setOnPreferenceChangeListener(this);
|
||||
initWifiAssistantPreference(scorers);
|
||||
} else if (mWifiAssistantPreference != null) {
|
||||
getPreferenceScreen().removePreference(mWifiAssistantPreference);
|
||||
}
|
||||
|
||||
Intent wifiDirectIntent = new Intent(context,
|
||||
@@ -202,6 +200,18 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void initWifiAssistantPreference(Collection<NetworkScorerAppData> scorers) {
|
||||
int count = scorers.size();
|
||||
String[] packageNames = new String[count];
|
||||
int i = 0;
|
||||
for (NetworkScorerAppData scorer : scorers) {
|
||||
packageNames[i] = scorer.mPackageName;
|
||||
i++;
|
||||
}
|
||||
mWifiAssistantPreference.setPackageNames(packageNames,
|
||||
mNetworkScoreManager.getActiveScorerPackage());
|
||||
}
|
||||
|
||||
private void updateSleepPolicySummary(Preference sleepPolicyPref, String value) {
|
||||
if (value != null) {
|
||||
String[] values = getResources().getStringArray(R.array.wifi_sleep_policy_values);
|
||||
@@ -261,12 +271,13 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
return false;
|
||||
}
|
||||
} else if (KEY_WIFI_ASSISTANT.equals(key)) {
|
||||
if (((Boolean)newValue).booleanValue() == false) {
|
||||
NetworkScorerAppData wifiAssistant =
|
||||
NetworkScorerAppManager.getScorer(context, (String) newValue);
|
||||
if (wifiAssistant == null) {
|
||||
mNetworkScoreManager.setActiveScorer(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
NetworkScorerAppData wifiAssistant = getWifiAssistantApp(context);
|
||||
Intent intent = new Intent();
|
||||
if (wifiAssistant.mConfigurationActivityClassName != null) {
|
||||
// App has a custom configuration activity; launch that.
|
||||
@@ -282,6 +293,9 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
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)) {
|
||||
@@ -317,22 +331,6 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
wifiIpAddressPref.setSelectable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Network Scorer for the Wifi Assistant App.
|
||||
*/
|
||||
public static NetworkScorerAppData getWifiAssistantApp(Context context) {
|
||||
Collection<NetworkScorerAppData> scorers =
|
||||
NetworkScorerAppManager.getAllValidScorers(context);
|
||||
|
||||
if (scorers.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: b/13780935 - Implement proper scorer selection. Rather than pick the first
|
||||
// scorer on the system, we should allow the user to select one.
|
||||
return scorers.iterator().next();
|
||||
}
|
||||
|
||||
/* Wrapper class for the WPS dialog to properly handle life cycle events like rotation. */
|
||||
public static class WpsFragment extends DialogFragment {
|
||||
private static int mWpsSetup;
|
||||
|
Reference in New Issue
Block a user