Update datausage for DataUsagePreferenceController

Data usage number was wrong because we didn't set correct
subId, this CL fixes this issue.

Bug: 132113657
Test: RunSettingsRoboTests
Change-Id: If7c9cf2f4709d9a8e5f9a154c02de9484800d6d5
This commit is contained in:
Lei Yu
2019-05-06 16:35:19 -07:00
parent 65a258e2a2
commit 9bc3273489
3 changed files with 13 additions and 14 deletions

View File

@@ -21,9 +21,7 @@ import android.content.Intent;
import android.net.NetworkTemplate;
import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.text.format.Formatter;
import androidx.preference.Preference;
@@ -87,9 +85,10 @@ public class DataUsagePreferenceController extends TelephonyBasePreferenceContro
mSubId = subId;
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
mTemplate = getNetworkTemplate(mContext, subId);
mTemplate = DataUsageUtils.getDefaultTemplate(mContext, mSubId);
final DataUsageController controller = new DataUsageController(mContext);
controller.setSubscriptionId(mSubId);
mDataUsageInfo = controller.getDataUsageInfo(mTemplate);
mIntent = new Intent(Settings.ACTION_MOBILE_DATA_USAGE);
@@ -97,12 +96,4 @@ public class DataUsagePreferenceController extends TelephonyBasePreferenceContro
mIntent.putExtra(Settings.EXTRA_SUB_ID, mSubId);
}
}
private NetworkTemplate getNetworkTemplate(Context context, int subId) {
final TelephonyManager tm = TelephonyManager.from(context).createForSubscriptionId(subId);
NetworkTemplate mobileAll = NetworkTemplate.buildTemplateMobileAll(tm.getSubscriberId());
return NetworkTemplate.normalize(mobileAll, tm.getMergedSubscriberIds());
}
}