Loading src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java +44 −2 Original line number Diff line number Diff line Loading @@ -19,8 +19,11 @@ 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.NetworkPolicyManager; import android.net.NetworkTemplate; import android.os.ServiceManager; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.SubscriptionPlan; Loading Loading @@ -296,12 +299,51 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll mSnapshotTime = primaryPlan.getDataUsageTime(); } } mManageSubscriptionIntent = mSubscriptionManager.createManageSubscriptionIntent(mSubscriptionId); mManageSubscriptionIntent = createManageSubscriptionIntent(mSubscriptionId); Log.i(TAG, "Have " + mDataplanCount + " plans, dflt sub-id " + mSubscriptionId + ", 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. */ private 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 = mSubscriptionManager.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 (mActivity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) { return null; } return intent; } public static SubscriptionPlan getPrimaryPlan(SubscriptionManager subManager, int primaryId) { List<SubscriptionPlan> plans = subManager.getSubscriptionPlans(primaryId); if (CollectionUtils.isEmpty(plans)) { Loading Loading
src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java +44 −2 Original line number Diff line number Diff line Loading @@ -19,8 +19,11 @@ 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.NetworkPolicyManager; import android.net.NetworkTemplate; import android.os.ServiceManager; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.SubscriptionPlan; Loading Loading @@ -296,12 +299,51 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll mSnapshotTime = primaryPlan.getDataUsageTime(); } } mManageSubscriptionIntent = mSubscriptionManager.createManageSubscriptionIntent(mSubscriptionId); mManageSubscriptionIntent = createManageSubscriptionIntent(mSubscriptionId); Log.i(TAG, "Have " + mDataplanCount + " plans, dflt sub-id " + mSubscriptionId + ", 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. */ private 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 = mSubscriptionManager.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 (mActivity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) { return null; } return intent; } public static SubscriptionPlan getPrimaryPlan(SubscriptionManager subManager, int primaryId) { List<SubscriptionPlan> plans = subManager.getSubscriptionPlans(primaryId); if (CollectionUtils.isEmpty(plans)) { Loading