use of android.telephony.SubscriptionPlan in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DataUsageSummaryPreferenceController method getPrimaryPlan.
public static SubscriptionPlan getPrimaryPlan(SubscriptionManager subManager, int primaryId) {
List<SubscriptionPlan> plans = subManager.getSubscriptionPlans(primaryId);
if (CollectionUtils.isEmpty(plans)) {
return null;
}
// First plan in the list is the primary plan
SubscriptionPlan plan = plans.get(0);
return plan.getDataLimitBytes() > 0 && saneSize(plan.getDataUsageBytes()) && plan.getCycleRule() != null ? plan : null;
}
use of android.telephony.SubscriptionPlan in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DataUsageSummaryPreferenceController method refreshDataplanInfo.
// TODO(b/70950124) add test for this method once the robolectric shadow run script is
// completed (b/3526807)
private void refreshDataplanInfo(DataUsageController.DataUsageInfo info) {
// reset data before overwriting
mCarrierName = null;
mDataplanCount = 0;
mDataplanSize = -1L;
mDataBarSize = mDataInfoController.getSummaryLimit(info);
mDataplanUse = info.usageLevel;
mCycleStart = info.cycleStart;
mCycleEnd = info.cycleEnd;
mSnapshotTime = -1L;
SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(mSubscriptionId);
if (subInfo == null) {
subInfo = mSubscriptionManager.getAllSubscriptionInfoList().stream().filter(i -> i.getSubscriptionId() == mSubscriptionId).findFirst().orElse(null);
}
if (subInfo != null && mHasMobileData) {
mCarrierName = subInfo.getCarrierName();
List<SubscriptionPlan> plans = mSubscriptionManager.getSubscriptionPlans(mSubscriptionId);
final SubscriptionPlan primaryPlan = getPrimaryPlan(mSubscriptionManager, mSubscriptionId);
if (primaryPlan != null) {
mDataplanCount = plans.size();
mDataplanSize = primaryPlan.getDataLimitBytes();
if (unlimited(mDataplanSize)) {
mDataplanSize = -1L;
}
mDataBarSize = mDataplanSize;
mDataplanUse = primaryPlan.getDataUsageBytes();
RecurrenceRule rule = primaryPlan.getCycleRule();
if (rule != null && rule.start != null && rule.end != null) {
mCycleStart = rule.start.toEpochSecond() * 1000L;
mCycleEnd = rule.end.toEpochSecond() * 1000L;
}
mSnapshotTime = primaryPlan.getDataUsageTime();
}
}
mManageSubscriptionIntent = mSubscriptionManager.createManageSubscriptionIntent(mSubscriptionId);
Log.i(TAG, "Have " + mDataplanCount + " plans, dflt sub-id " + mSubscriptionId + ", intent " + mManageSubscriptionIntent);
}
use of android.telephony.SubscriptionPlan in project android_packages_apps_Settings by omnirom.
the class DataUsageSummaryPreferenceController method createManageSubscriptionIntent.
/**
* 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;
}
use of android.telephony.SubscriptionPlan in project android_packages_apps_Settings by omnirom.
the class DataUsageSummaryPreferenceController method refreshDataplanInfo.
// TODO(b/70950124) add test for this method once the robolectric shadow run script is
// completed (b/3526807)
private void refreshDataplanInfo(DataUsageController.DataUsageInfo info, SubscriptionInfo subInfo) {
// reset data before overwriting
mCarrierName = null;
mDataplanCount = 0;
mDataplanSize = -1L;
mDataBarSize = mDataInfoController.getSummaryLimit(info);
mDataplanUse = info.usageLevel;
mCycleStart = info.cycleStart;
mCycleEnd = info.cycleEnd;
mSnapshotTime = -1L;
if (subInfo != null && mHasMobileData) {
mCarrierName = subInfo.getCarrierName();
final List<SubscriptionPlan> plans = getSubscriptionPlans(mSubId);
final SubscriptionPlan primaryPlan = getPrimaryPlan(plans);
if (primaryPlan != null) {
mDataplanCount = plans.size();
mDataplanSize = primaryPlan.getDataLimitBytes();
if (unlimited(mDataplanSize)) {
mDataplanSize = -1L;
}
mDataBarSize = mDataplanSize;
mDataplanUse = primaryPlan.getDataUsageBytes();
RecurrenceRule rule = primaryPlan.getCycleRule();
if (rule != null && rule.start != null && rule.end != null) {
mCycleStart = rule.start.toEpochSecond() * 1000L;
mCycleEnd = rule.end.toEpochSecond() * 1000L;
}
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);
}
use of android.telephony.SubscriptionPlan in project android_frameworks_opt_telephony by LineageOS.
the class DcTracker method isNetworkTypeUnmetered.
private boolean isNetworkTypeUnmetered(@NetworkType int networkType) {
if (mSubscriptionPlans == null || mSubscriptionPlans.size() == 0) {
// safe return false if unable to get subscription plans or plans don't exist
return false;
}
boolean isGeneralUnmetered = true;
Set<Integer> allNetworkTypes = Arrays.stream(TelephonyManager.getAllNetworkTypes()).boxed().collect(Collectors.toSet());
for (SubscriptionPlan plan : mSubscriptionPlans) {
// check plan is general (applies to all network types) or specific
if (Arrays.stream(plan.getNetworkTypes()).boxed().collect(Collectors.toSet()).containsAll(allNetworkTypes)) {
if (!isPlanUnmetered(plan)) {
// metered takes precedence over unmetered for safety
isGeneralUnmetered = false;
}
} else {
// check plan applies to given network type
if (networkType != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
for (int planNetworkType : plan.getNetworkTypes()) {
if (planNetworkType == networkType) {
return isPlanUnmetered(plan);
}
}
}
}
}
return isGeneralUnmetered;
}
Aggregations