[Provider Model] Update internet preference icon and summary
- Airplane mode icon/summary - Airplane mode networks icon/summary - Wi-Fi network connected icon/SSID - Cellular network connected icon/carrier-name - Ethernet network connected icon/summary - Screenshot: https://screenshot.googleplex.com/AzhCEX2HjwYUMtJ https://screenshot.googleplex.com/9BRfQLMW4UvHqqq https://screenshot.googleplex.com/5jdi8oEjMPUURdT Bug: 176796623 Test: manual test - atest -c InternetUpdaterTest \ InternetPreferenceControllerTest Change-Id: Icc8944dabdac597f12b67cffa72cb0be02d9671d
This commit is contained in:
@@ -16,41 +16,107 @@
|
||||
|
||||
package com.android.settings.network;
|
||||
|
||||
import android.content.Context;
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
||||
|
||||
import static com.android.settings.network.InternetUpdater.INTERNET_APM;
|
||||
import static com.android.settings.network.InternetUpdater.INTERNET_APM_NETWORKS;
|
||||
import static com.android.settings.network.InternetUpdater.INTERNET_CELLULAR;
|
||||
import static com.android.settings.network.InternetUpdater.INTERNET_ETHERNET;
|
||||
import static com.android.settings.network.InternetUpdater.INTERNET_WIFI;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.SummaryUpdater;
|
||||
import com.android.settings.wifi.WifiSummaryUpdater;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
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.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* PreferenceController to update the internet state.
|
||||
*/
|
||||
public class InternetPreferenceController extends AbstractPreferenceController implements
|
||||
PreferenceControllerMixin, SummaryUpdater.OnSummaryChangeListener,
|
||||
LifecycleObserver, OnResume, OnPause {
|
||||
LifecycleObserver, SummaryUpdater.OnSummaryChangeListener,
|
||||
InternetUpdater.OnInternetTypeChangedListener {
|
||||
|
||||
public static final String KEY_INTERNET_SETTINGS = "internet_settings";
|
||||
public static final String KEY = "internet_settings";
|
||||
|
||||
private Preference mPreference;
|
||||
private final WifiSummaryUpdater mSummaryHelper;
|
||||
private InternetUpdater mInternetUpdater;
|
||||
private @InternetUpdater.InternetType int mInternetType;
|
||||
|
||||
public InternetPreferenceController(Context context) {
|
||||
private static Map<Integer, Integer> sIconMap = new HashMap<>();
|
||||
static {
|
||||
sIconMap.put(INTERNET_APM, R.drawable.ic_airplanemode_active);
|
||||
sIconMap.put(INTERNET_APM_NETWORKS, R.drawable.ic_airplane_safe_networks_24dp);
|
||||
sIconMap.put(INTERNET_WIFI, R.drawable.ic_wifi_signal_4);
|
||||
sIconMap.put(INTERNET_CELLULAR, R.drawable.ic_network_cell);
|
||||
sIconMap.put(INTERNET_ETHERNET, R.drawable.ic_settings_ethernet);
|
||||
}
|
||||
|
||||
private static Map<Integer, Integer> sSummaryMap = new HashMap<>();
|
||||
static {
|
||||
sSummaryMap.put(INTERNET_APM, R.string.condition_airplane_title);
|
||||
sSummaryMap.put(INTERNET_APM_NETWORKS, R.string.airplane_mode_network_available);
|
||||
sSummaryMap.put(INTERNET_WIFI, 0);
|
||||
sSummaryMap.put(INTERNET_CELLULAR, 0);
|
||||
sSummaryMap.put(INTERNET_ETHERNET, R.string.to_switch_networks_disconnect_ethernet);
|
||||
}
|
||||
|
||||
public InternetPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context);
|
||||
if (lifecycle == null) {
|
||||
throw new IllegalArgumentException("Lifecycle must be set");
|
||||
}
|
||||
mSummaryHelper = new WifiSummaryUpdater(mContext, this);
|
||||
mInternetUpdater = new InternetUpdater(context, lifecycle, this);
|
||||
mInternetType = mInternetUpdater.getInternetType();
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(KEY_INTERNET_SETTINGS);
|
||||
mPreference = screen.findPreference(KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (mPreference == null) {
|
||||
return;
|
||||
}
|
||||
final @IdRes int icon = sIconMap.get(mInternetType);
|
||||
if (icon != 0) {
|
||||
final Drawable drawable = mContext.getDrawable(icon);
|
||||
if (drawable != null) {
|
||||
drawable.setTintList(
|
||||
Utils.getColorAttr(mContext, android.R.attr.colorControlNormal));
|
||||
mPreference.setIcon(drawable);
|
||||
}
|
||||
}
|
||||
if (mInternetType == INTERNET_CELLULAR) {
|
||||
updateCellularSummary();
|
||||
return;
|
||||
}
|
||||
final @IdRes int summary = sSummaryMap.get(mInternetType);
|
||||
if (summary != 0) {
|
||||
mPreference.setSummary(summary);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,23 +126,45 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_INTERNET_SETTINGS;
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
/** @OnLifecycleEvent(ON_RESUME) */
|
||||
@OnLifecycleEvent(ON_RESUME)
|
||||
public void onResume() {
|
||||
mSummaryHelper.register(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
/** @OnLifecycleEvent(ON_PAUSE) */
|
||||
@OnLifecycleEvent(ON_PAUSE)
|
||||
public void onPause() {
|
||||
mSummaryHelper.register(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when internet type is changed.
|
||||
*
|
||||
* @param internetType the internet type
|
||||
*/
|
||||
public void onInternetTypeChanged(@InternetUpdater.InternetType int internetType) {
|
||||
mInternetType = internetType;
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSummaryChanged(String summary) {
|
||||
if (mPreference != null) {
|
||||
if (mPreference != null && mInternetType == INTERNET_WIFI) {
|
||||
mPreference.setSummary(summary);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCellularSummary() {
|
||||
final SubscriptionManager subscriptionManager =
|
||||
mContext.getSystemService(SubscriptionManager.class);
|
||||
if (subscriptionManager == null) {
|
||||
return;
|
||||
}
|
||||
SubscriptionInfo subInfo = subscriptionManager.getDefaultDataSubscriptionInfo();
|
||||
mPreference.setSummary(subInfo.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user