Adjust UX for toggles when active scorer is not set.

This change fixes two issues: when wakeup is not available, update the
number of items to show above the fold in wifi preferences. When scorer
is not set, grey out wakeup toggle and set summary to reflect the
status.

Bug: 62410973
Bug: 62343859
Test: make RunSettingsRoboTests -j40

Change-Id: I5f4131c6a86eab6c0fb03ea2b5101ba107a9189f
This commit is contained in:
Stephen Chen
2017-06-23 15:14:14 -07:00
parent f0398e1294
commit 7e27006a7b
6 changed files with 166 additions and 45 deletions

View File

@@ -8,7 +8,6 @@ import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
import android.net.NetworkScoreManager;
import android.net.NetworkScorerAppData;
import android.net.Uri;
import android.os.Handler;
@@ -20,14 +19,17 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import com.android.settings.network.NetworkScoreManagerWrapper;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.network.NetworkScoreManagerWrapper;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
import java.util.List;
/**
* {@link AbstractPreferenceController} that controls whether a user wants to enable the "use open
* networks automatically" feature provider by the current network recommendation provider.
@@ -45,6 +47,7 @@ public class UseOpenWifiPreferenceController extends AbstractPreferenceControlle
private Preference mPreference;
private ComponentName mEnableUseWifiComponentName;
private boolean mDoFeatureSupportedScorersExist;
public UseOpenWifiPreferenceController(Context context, Fragment fragment,
NetworkScoreManagerWrapper networkScoreManagerWrapper, Lifecycle lifecycle) {
@@ -54,6 +57,7 @@ public class UseOpenWifiPreferenceController extends AbstractPreferenceControlle
mNetworkScoreManagerWrapper = networkScoreManagerWrapper;
mSettingObserver = new SettingObserver();
updateEnableUseWifiComponentName();
checkForFeatureSupportedScorers();
lifecycle.addObserver(this);
}
@@ -63,6 +67,21 @@ public class UseOpenWifiPreferenceController extends AbstractPreferenceControlle
appData == null ? null : appData.getEnableUseOpenWifiActivity();
}
private void checkForFeatureSupportedScorers() {
if (mEnableUseWifiComponentName != null) {
mDoFeatureSupportedScorersExist = true;
return;
}
List<NetworkScorerAppData> scorers = mNetworkScoreManagerWrapper.getAllValidScorers();
for (NetworkScorerAppData scorer : scorers) {
if (scorer.getEnableUseOpenWifiActivity() != null) {
mDoFeatureSupportedScorersExist = true;
return;
}
}
mDoFeatureSupportedScorersExist = false;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
@@ -81,7 +100,7 @@ public class UseOpenWifiPreferenceController extends AbstractPreferenceControlle
@Override
public boolean isAvailable() {
return mEnableUseWifiComponentName != null;
return mDoFeatureSupportedScorersExist;
}
@Override
@@ -95,8 +114,23 @@ public class UseOpenWifiPreferenceController extends AbstractPreferenceControlle
return;
}
final SwitchPreference useOpenWifiPreference = (SwitchPreference) preference;
useOpenWifiPreference.setVisible(isAvailable());
boolean isScorerSet = mNetworkScoreManagerWrapper.getActiveScorerPackage() != null;
boolean doesActiveScorerSupportFeature = mEnableUseWifiComponentName != null;
useOpenWifiPreference.setChecked(isSettingEnabled());
useOpenWifiPreference.setVisible(isAvailable());
useOpenWifiPreference.setEnabled(isScorerSet && doesActiveScorerSupportFeature);
if (!isScorerSet) {
useOpenWifiPreference.setSummary(
R.string.use_open_wifi_automatically_summary_scoring_disabled);
} else if (!doesActiveScorerSupportFeature) {
useOpenWifiPreference.setSummary(
R.string.use_open_wifi_automatically_summary_scorer_unsupported_disabled);
} else {
useOpenWifiPreference.setSummary(R.string.use_open_wifi_automatically_summary);
}
}
@Override