Clean up WifiDataUsageSummaryPreferenceController
Which is legacy and not finished implemented. Bug: 295260929 Test: unit test Test: robo test Test: manual - on Mobile Settings page Test: manual - on Network details page Change-Id: I30ac639c1ba285a74038d5413b63e2c31c6cc8ba
This commit is contained in:
@@ -17,14 +17,10 @@
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import android.annotation.AttrRes;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.icu.text.MessageFormat;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkTemplate;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
@@ -32,7 +28,6 @@ import android.text.format.Formatter;
|
||||
import android.text.style.AbsoluteSizeSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
@@ -42,7 +37,6 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.net.DataUsageController;
|
||||
import com.android.settingslib.utils.StringUtil;
|
||||
@@ -77,7 +71,6 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
/** Name of carrier, or null if not available */
|
||||
private CharSequence mCarrierName;
|
||||
private CharSequence mLimitInfoText;
|
||||
private Intent mLaunchIntent;
|
||||
|
||||
/** Progress to display on ProgressBar */
|
||||
private float mProgress;
|
||||
@@ -92,11 +85,6 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
/** The number of bytes used since the start of the cycle. */
|
||||
private long mDataplanUse;
|
||||
|
||||
/** WiFi only mode */
|
||||
private boolean mWifiMode;
|
||||
private String mUsagePeriod;
|
||||
private boolean mSingleWifi; // Shows only one specified WiFi network usage
|
||||
|
||||
public DataUsageSummaryPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setLayoutResource(R.layout.data_usage_summary_preference);
|
||||
@@ -115,12 +103,11 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
}
|
||||
|
||||
public void setUsageInfo(long cycleEnd, long snapshotTime, CharSequence carrierName,
|
||||
int numPlans, Intent launchIntent) {
|
||||
int numPlans) {
|
||||
mCycleEndTimeMs = cycleEnd;
|
||||
mSnapshotTimeMs = snapshotTime;
|
||||
mCarrierName = carrierName;
|
||||
mNumPlans = numPlans;
|
||||
mLaunchIntent = launchIntent;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@@ -144,13 +131,6 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
void setWifiMode(boolean isWifiMode, String usagePeriod, boolean isSingleWifi) {
|
||||
mWifiMode = isWifiMode;
|
||||
mUsagePeriod = usagePeriod;
|
||||
mSingleWifi = isSingleWifi;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
@@ -171,66 +151,13 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
|
||||
TextView usageTitle = getUsageTitle(holder);
|
||||
TextView carrierInfo = getCarrierInfo(holder);
|
||||
Button launchButton = getLaunchButton(holder);
|
||||
TextView limitInfo = getDataLimits(holder);
|
||||
|
||||
if (mWifiMode && mSingleWifi) {
|
||||
updateCycleTimeText(holder);
|
||||
|
||||
usageTitle.setVisibility(View.GONE);
|
||||
launchButton.setVisibility(View.GONE);
|
||||
carrierInfo.setVisibility(View.GONE);
|
||||
|
||||
limitInfo.setVisibility(TextUtils.isEmpty(mLimitInfoText) ? View.GONE : View.VISIBLE);
|
||||
limitInfo.setText(mLimitInfoText);
|
||||
} else if (mWifiMode) {
|
||||
usageTitle.setText(R.string.data_usage_wifi_title);
|
||||
usageTitle.setVisibility(View.VISIBLE);
|
||||
TextView cycleTime = getCycleTime(holder);
|
||||
cycleTime.setText(mUsagePeriod);
|
||||
carrierInfo.setVisibility(View.GONE);
|
||||
limitInfo.setVisibility(View.GONE);
|
||||
|
||||
final long usageLevel = getHistoricalUsageLevel();
|
||||
if (usageLevel > 0L) {
|
||||
launchButton.setOnClickListener((view) -> {
|
||||
launchWifiDataUsage(getContext());
|
||||
});
|
||||
} else {
|
||||
launchButton.setEnabled(false);
|
||||
}
|
||||
launchButton.setText(R.string.launch_wifi_text);
|
||||
launchButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
usageTitle.setVisibility(mNumPlans > 1 ? View.VISIBLE : View.GONE);
|
||||
updateCycleTimeText(holder);
|
||||
updateCarrierInfo(carrierInfo);
|
||||
if (mLaunchIntent != null) {
|
||||
launchButton.setOnClickListener((view) -> {
|
||||
getContext().startActivity(mLaunchIntent);
|
||||
});
|
||||
launchButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
launchButton.setVisibility(View.GONE);
|
||||
}
|
||||
limitInfo.setVisibility(
|
||||
TextUtils.isEmpty(mLimitInfoText) ? View.GONE : View.VISIBLE);
|
||||
limitInfo.setText(mLimitInfoText);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static void launchWifiDataUsage(Context context) {
|
||||
final Bundle args = new Bundle(1);
|
||||
args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE,
|
||||
new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI).build());
|
||||
args.putInt(DataUsageList.EXTRA_NETWORK_TYPE, ConnectivityManager.TYPE_WIFI);
|
||||
final SubSettingLauncher launcher = new SubSettingLauncher(context)
|
||||
.setArguments(args)
|
||||
.setDestination(DataUsageList.class.getName())
|
||||
.setSourceMetricsCategory(SettingsEnums.PAGE_UNKNOWN);
|
||||
launcher.setTitleRes(R.string.wifi_data_usage);
|
||||
launcher.launch();
|
||||
usageTitle.setVisibility(mNumPlans > 1 ? View.VISIBLE : View.GONE);
|
||||
updateCycleTimeText(holder);
|
||||
updateCarrierInfo(carrierInfo);
|
||||
limitInfo.setVisibility(TextUtils.isEmpty(mLimitInfoText) ? View.GONE : View.VISIBLE);
|
||||
limitInfo.setText(mLimitInfoText);
|
||||
}
|
||||
|
||||
private void updateDataUsageLabels(PreferenceViewHolder holder) {
|
||||
@@ -403,11 +330,6 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
return (TextView) holder.findViewById(R.id.data_remaining_view);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected Button getLaunchButton(PreferenceViewHolder holder) {
|
||||
return (Button) holder.findViewById(R.id.launch_mdp_app_button);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected LinearLayout getLabelBar(PreferenceViewHolder holder) {
|
||||
return (LinearLayout) holder.findViewById(R.id.label_bar);
|
||||
|
||||
@@ -18,13 +18,8 @@ package com.android.settings.datausage;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.INetworkPolicyManager;
|
||||
import android.net.NetworkTemplate;
|
||||
import android.os.ServiceManager;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.SubscriptionPlan;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -83,8 +78,6 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
|
||||
/** The ending time of the billing cycle in ms since the epoch */
|
||||
private long mCycleEnd;
|
||||
|
||||
private Intent mManageSubscriptionIntent;
|
||||
|
||||
private Future<Long> mHistoricalUsageLevel;
|
||||
|
||||
public DataUsageSummaryPreferenceController(Activity activity, int subscriptionId) {
|
||||
@@ -111,10 +104,6 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
|
||||
|
||||
if (subInfo != null) {
|
||||
mDefaultTemplate = DataUsageLib.getMobileTemplate(context, subscriptionId);
|
||||
} else if (DataUsageUtils.hasWifiRadio(context)) {
|
||||
mDefaultTemplate = new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI).build();
|
||||
} else {
|
||||
mDefaultTemplate = DataUsageUtils.getDefaultTemplate(context, subscriptionId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,8 +143,7 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus(int subId) {
|
||||
return (getSubscriptionInfo(subId) != null)
|
||||
|| DataUsageUtils.hasWifiRadio(mContext) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
return getSubscriptionInfo(subId) != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,6 +151,9 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
|
||||
DataUsageSummaryPreference summaryPreference = (DataUsageSummaryPreference) preference;
|
||||
|
||||
final SubscriptionInfo subInfo = getSubscriptionInfo(mSubId);
|
||||
if (subInfo == null) {
|
||||
return;
|
||||
}
|
||||
if (mDataUsageController == null) {
|
||||
updateConfiguration(mContext, mSubId, subInfo);
|
||||
}
|
||||
@@ -175,25 +166,6 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
|
||||
|
||||
long usageLevel = info.usageLevel;
|
||||
|
||||
if (subInfo != null) {
|
||||
summaryPreference.setWifiMode(/* isWifiMode */ false,
|
||||
/* usagePeriod */ null, /* isSingleWifi */ false);
|
||||
} else {
|
||||
summaryPreference.setWifiMode(/* isWifiMode */ true, /* usagePeriod */
|
||||
info.period, /* isSingleWifi */ false);
|
||||
summaryPreference.setLimitInfo(null);
|
||||
summaryPreference.setUsageNumbers(displayUsageLevel(usageLevel),
|
||||
/* dataPlanSize */ -1L,
|
||||
/* hasMobileData */ true);
|
||||
summaryPreference.setChartEnabled(false);
|
||||
summaryPreference.setUsageInfo(info.cycleEnd,
|
||||
/* snapshotTime */ -1L,
|
||||
/* carrierName */ null,
|
||||
/* numPlans */ 0,
|
||||
/* launchIntent */ null);
|
||||
return;
|
||||
}
|
||||
|
||||
refreshDataplanInfo(info, subInfo);
|
||||
|
||||
if (info.warningLevel > 0 && info.limitLevel > 0) {
|
||||
@@ -229,8 +201,7 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
|
||||
DataUsageUtils.formatDataUsage(mContext, mDataBarSize));
|
||||
summaryPreference.setProgress(mDataplanUse / (float) mDataBarSize);
|
||||
}
|
||||
summaryPreference.setUsageInfo(mCycleEnd, mSnapshotTime, mCarrierName,
|
||||
mDataplanCount, mManageSubscriptionIntent);
|
||||
summaryPreference.setUsageInfo(mCycleEnd, mSnapshotTime, mCarrierName, mDataplanCount);
|
||||
}
|
||||
|
||||
private long displayUsageLevel(long usageLevel) {
|
||||
@@ -278,53 +249,7 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
|
||||
mSnapshotTime = primaryPlan.getDataUsageTime();
|
||||
}
|
||||
}
|
||||
// Temporarily return null, since no current users of SubscriptionPlan have this intent set.
|
||||
// TODO (b/170330084): Remove after refactoring 5G SubscriptionPlan logic.
|
||||
// mManageSubscriptionIntent = createManageSubscriptionIntent(mSubId);
|
||||
mManageSubscriptionIntent = null;
|
||||
Log.i(TAG, "Have " + mDataplanCount + " plans, dflt sub-id " + mSubId
|
||||
+ ", intent " + mManageSubscriptionIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an {@link Intent} that can be launched towards the carrier app
|
||||
* that is currently defining the billing relationship plan through
|
||||
* {@link INetworkPolicyManager#setSubscriptionPlans(int, SubscriptionPlan [], String)}.
|
||||
*
|
||||
* @return ready to launch Intent targeted towards the carrier app, or
|
||||
* {@code null} if no carrier app is defined, or if the defined
|
||||
* carrier app provides no management activity.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
Intent createManageSubscriptionIntent(int subId) {
|
||||
final INetworkPolicyManager iNetPolicyManager = INetworkPolicyManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
|
||||
String owner = "";
|
||||
try {
|
||||
owner = iNetPolicyManager.getSubscriptionPlansOwner(subId);
|
||||
} catch (Exception ex) {
|
||||
Log.w(TAG, "Fail to get subscription plan owner for subId " + subId, ex);
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(owner)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final List<SubscriptionPlan> plans = getSubscriptionPlans(subId);
|
||||
if (plans.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Intent intent = new Intent(SubscriptionManager.ACTION_MANAGE_SUBSCRIPTION_PLANS);
|
||||
intent.setPackage(owner);
|
||||
intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
|
||||
|
||||
if (mContext.getPackageManager().queryIntentActivities(intent,
|
||||
PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return intent;
|
||||
Log.i(TAG, "Have " + mDataplanCount + " plans, dflt sub-id " + mSubId);
|
||||
}
|
||||
|
||||
private static SubscriptionPlan getPrimaryPlan(List<SubscriptionPlan> plans) {
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.net.NetworkTemplate;
|
||||
import android.telephony.SubscriptionManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settingslib.net.DataUsageController;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The controller displays a data usage chart for the specified Wi-Fi network.
|
||||
*/
|
||||
public class WifiDataUsageSummaryPreferenceController extends DataUsageSummaryPreferenceController {
|
||||
final Set<String> mAllNetworkKeys;
|
||||
|
||||
public WifiDataUsageSummaryPreferenceController(Activity activity, Set<String> allNetworkKeys) {
|
||||
super(activity, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
mAllNetworkKeys = new HashSet<>(allNetworkKeys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (preference == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final DataUsageSummaryPreference mPreference = (DataUsageSummaryPreference) preference;
|
||||
final NetworkTemplate template = new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI)
|
||||
.setWifiNetworkKeys(mAllNetworkKeys).build();
|
||||
if (mDataUsageController == null) {
|
||||
updateConfiguration(mContext, mSubId, getSubscriptionInfo(mSubId));
|
||||
}
|
||||
final DataUsageController.DataUsageInfo info = mDataUsageController.getDataUsageInfo(
|
||||
template);
|
||||
|
||||
mPreference.setWifiMode(/* isWifiMode */ true, /* usagePeriod */
|
||||
info.period, /* isSingleWifi */ true);
|
||||
mPreference.setChartEnabled(true);
|
||||
// Treats Wi-Fi network as unlimited network, which has same usage level and limited level.
|
||||
mPreference.setUsageNumbers(info.usageLevel, info.usageLevel, /* hasMobileData */ false);
|
||||
|
||||
// TODO(b/126142293): Passpoint Wi-Fi should have limit of data usage and time remaining
|
||||
mPreference.setProgress(100);
|
||||
mPreference.setLabels(DataUsageUtils.formatDataUsage(mContext, /* sizeBytes */ 0),
|
||||
DataUsageUtils.formatDataUsage(mContext, info.usageLevel));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user