Search in sources :

Example 1 with SubscriptionPlan

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;
}
Also used : SubscriptionPlan(android.telephony.SubscriptionPlan)

Example 2 with SubscriptionPlan

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);
}
Also used : Context(android.content.Context) PreferenceControllerMixin(com.android.settings.core.PreferenceControllerMixin) Intent(android.content.Intent) PreferenceFragmentCompat(androidx.preference.PreferenceFragmentCompat) SubscriptionManager(android.telephony.SubscriptionManager) BasePreferenceController(com.android.settings.core.BasePreferenceController) NetworkPolicyEditor(com.android.settingslib.NetworkPolicyEditor) RecurrenceRule(android.util.RecurrenceRule) Settings(android.provider.Settings) SubscriptionPlan(android.telephony.SubscriptionPlan) RecyclerView(androidx.recyclerview.widget.RecyclerView) SubscriptionInfo(android.telephony.SubscriptionInfo) Log(android.util.Log) CollectionUtils(com.android.internal.util.CollectionUtils) R(com.android.settings.R) NetworkPolicyManager(android.net.NetworkPolicyManager) LifecycleObserver(com.android.settingslib.core.lifecycle.LifecycleObserver) TextUtils(android.text.TextUtils) DataUsageController(com.android.settingslib.net.DataUsageController) Preference(androidx.preference.Preference) List(java.util.List) EntityHeaderController(com.android.settings.widget.EntityHeaderController) Activity(android.app.Activity) VisibleForTesting(androidx.annotation.VisibleForTesting) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) OnStart(com.android.settingslib.core.lifecycle.events.OnStart) NetworkTemplate(android.net.NetworkTemplate) RecurrenceRule(android.util.RecurrenceRule) SubscriptionPlan(android.telephony.SubscriptionPlan) SubscriptionInfo(android.telephony.SubscriptionInfo)

Example 3 with SubscriptionPlan

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;
}
Also used : SubscriptionPlan(android.telephony.SubscriptionPlan) Intent(android.content.Intent) INetworkPolicyManager(android.net.INetworkPolicyManager) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 4 with SubscriptionPlan

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);
}
Also used : RecurrenceRule(android.util.RecurrenceRule) SubscriptionPlan(android.telephony.SubscriptionPlan)

Example 5 with SubscriptionPlan

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SubscriptionPlan(android.telephony.SubscriptionPlan)

Aggregations

SubscriptionPlan (android.telephony.SubscriptionPlan)5 Intent (android.content.Intent)2 RecurrenceRule (android.util.RecurrenceRule)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 Activity (android.app.Activity)1 Context (android.content.Context)1 INetworkPolicyManager (android.net.INetworkPolicyManager)1 NetworkPolicyManager (android.net.NetworkPolicyManager)1 NetworkTemplate (android.net.NetworkTemplate)1 Settings (android.provider.Settings)1 SubscriptionInfo (android.telephony.SubscriptionInfo)1 SubscriptionManager (android.telephony.SubscriptionManager)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 Preference (androidx.preference.Preference)1 PreferenceFragmentCompat (androidx.preference.PreferenceFragmentCompat)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 CollectionUtils (com.android.internal.util.CollectionUtils)1 R (com.android.settings.R)1 BasePreferenceController (com.android.settings.core.BasePreferenceController)1