Merge "[Settings] Avoid from accessing createManageSubscriptionIntent(int)"
am: d792d20001
Change-Id: I40195cc5643262d310a45c89d1751aa8f6c89f1e
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
index 600b9e8..a26e359 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
@@ -19,8 +19,11 @@
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;
@@ -296,12 +299,51 @@
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)) {