Merge "wifi data usage: Query wifi usage per configuration"

This commit is contained in:
Weng Su
2022-02-11 07:34:21 +00:00
committed by Android (Google) Code Review
4 changed files with 114 additions and 19 deletions

View File

@@ -123,13 +123,13 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
mDataUsageController = null;
}
private void updateConfiguration(Context context,
protected void updateConfiguration(Context context,
int subscriptionId, SubscriptionInfo subInfo) {
final NetworkPolicyManager policyManager =
context.getSystemService(NetworkPolicyManager.class);
mPolicyEditor = new NetworkPolicyEditor(policyManager);
mDataUsageController = new DataUsageController(context);
mDataUsageController = createDataUsageController(context);
mDataUsageController.setSubscriptionId(subscriptionId);
mDataInfoController = new DataUsageInfoController();
@@ -145,6 +145,11 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
}
}
@VisibleForTesting
DataUsageController createDataUsageController(Context context) {
return new DataUsageController(context);
}
@VisibleForTesting
DataUsageSummaryPreferenceController(
DataUsageController dataUsageController,
@@ -186,8 +191,7 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
.getSubscriptionPlans(subscriptionId);
}
@VisibleForTesting
SubscriptionInfo getSubscriptionInfo(int subscriptionId) {
protected SubscriptionInfo getSubscriptionInfo(int subscriptionId) {
if (!mHasMobileData) {
return null;
}

View File

@@ -26,23 +26,19 @@ import androidx.preference.PreferenceFragmentCompat;
import com.android.settingslib.core.lifecycle.Lifecycle;
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 String mNetworkId;
final Set<String> mAllNetworkKeys;
public WifiDataUsageSummaryPreferenceController(Activity activity,
Lifecycle lifecycle, PreferenceFragmentCompat fragment, CharSequence networkId) {
public WifiDataUsageSummaryPreferenceController(Activity activity, Lifecycle lifecycle,
PreferenceFragmentCompat fragment, Set<String> allNetworkKeys) {
super(activity, lifecycle, fragment, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
if (networkId == null) {
mNetworkId = null;
} else {
mNetworkId = String.valueOf(networkId);
}
mAllNetworkKeys = new HashSet<>(allNetworkKeys);
}
@Override
@@ -52,10 +48,11 @@ public class WifiDataUsageSummaryPreferenceController extends DataUsageSummaryPr
}
final DataUsageSummaryPreference mPreference = (DataUsageSummaryPreference) preference;
// TODO(b/126299427): Currently gets data usage of whole Wi-Fi networks, but should get
// specified one.
final NetworkTemplate template = new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI)
.setWifiNetworkKeys(Set.of(mNetworkId)).build();
.setWifiNetworkKeys(mAllNetworkKeys).build();
if (mDataUsageController == null) {
updateConfiguration(mContext, mSubId, getSubscriptionInfo(mSubId));
}
final DataUsageController.DataUsageInfo info = mDataUsageController.getDataUsageInfo(
template);
mDataInfoController.updateDataLimit(info, mPolicyEditor.getPolicy(template));