From e92ed6fbb3d3c0761da6faced69f968495c8fa09 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 10 Jan 2018 20:47:42 -0700 Subject: [PATCH] Define broadcasts for refreshing data plans. We don't hand the Intent out to the Settings app, since we need to carefully set whitelisting to allow the carrier app to wake up and respond if it's dozing. Define new "changed" broadcast that we'll send out whenever plans are changed internally. Test: builds, boots Bug: 64133169 Change-Id: Iacdd06d8e273fd52c8fc83edab13c9c8453b28eb --- api/system-current.txt | 1 + .../net/NetworkPolicyManagerService.java | 5 + .../telephony/SubscriptionManager.java | 96 ++++++++++++++++++- 3 files changed, 98 insertions(+), 4 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index b2d5a49c822c6..a36f027c7b05b 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -4275,6 +4275,7 @@ package android.telephony { method public java.util.List getSubscriptionPlans(int); method public void setSubscriptionPlans(int, java.util.List); field public static final java.lang.String ACTION_MANAGE_SUBSCRIPTION_PLANS = "android.telephony.action.MANAGE_SUBSCRIPTION_PLANS"; + field public static final java.lang.String ACTION_REFRESH_SUBSCRIPTION_PLANS = "android.telephony.action.REFRESH_SUBSCRIPTION_PLANS"; } public final class SubscriptionPlan implements android.os.Parcelable { diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java index 3c47e8523e06d..5d7256d8a22b5 100644 --- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java +++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java @@ -2793,6 +2793,11 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { handleNetworkPoliciesUpdateAL(true); } } + + final Intent intent = new Intent(SubscriptionManager.ACTION_SUBSCRIPTION_PLANS_CHANGED); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId); + mContext.sendBroadcast(intent, android.Manifest.permission.MANAGE_SUBSCRIPTION_PLANS); } finally { Binder.restoreCallingIdentity(token); } diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 2396a9eee92fa..2fafdf5c46930 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -18,10 +18,12 @@ package android.telephony; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.RequiresPermission; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; import android.annotation.SystemService; +import android.app.BroadcastOptions; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -36,6 +38,7 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.os.ServiceManager.ServiceNotFoundException; import android.util.DisplayMetrics; +import android.util.Log; import com.android.internal.telephony.IOnSubscriptionsChangedListener; import com.android.internal.telephony.ISub; @@ -46,6 +49,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.concurrent.TimeUnit; /** * SubscriptionManager is the application interface to SubscriptionController @@ -454,6 +458,39 @@ public class SubscriptionManager { public static final String ACTION_MANAGE_SUBSCRIPTION_PLANS = "android.telephony.action.MANAGE_SUBSCRIPTION_PLANS"; + /** + * Broadcast Action: Request a refresh of the billing relationship plans + * between a carrier and a specific subscriber. + *

+ * Carrier apps are encouraged to implement this receiver, and the OS will + * provide an affordance to request a refresh. This affordance will only be + * shown when the carrier app is actively providing subscription plan + * information via {@link #setSubscriptionPlans(int, List)}. + *

+ * Contains {@link #EXTRA_SUBSCRIPTION_INDEX} to indicate which subscription + * the user is interested in. + * + * @hide + */ + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + @SystemApi + public static final String ACTION_REFRESH_SUBSCRIPTION_PLANS + = "android.telephony.action.REFRESH_SUBSCRIPTION_PLANS"; + + /** + * Broadcast Action: The billing relationship plans between a carrier and a + * specific subscriber has changed. + *

+ * Contains {@link #EXTRA_SUBSCRIPTION_INDEX} to indicate which subscription + * changed. + * + * @hide + */ + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + @RequiresPermission(android.Manifest.permission.MANAGE_SUBSCRIPTION_PLANS) + public static final String ACTION_SUBSCRIPTION_PLANS_CHANGED + = "android.telephony.action.SUBSCRIPTION_PLANS_CHANGED"; + /** * Integer extra used with {@link #ACTION_DEFAULT_SUBSCRIPTION_CHANGED} and * {@link #ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED} to indicate the subscription @@ -1637,7 +1674,7 @@ public class SubscriptionManager { * This method is only accessible to the following narrow set of apps: *

    *
  • The carrier app for this subscriberId, as determined by - * {@link TelephonyManager#hasCarrierPrivileges(int)}. + * {@link TelephonyManager#hasCarrierPrivileges()}. *
  • The carrier app explicitly delegated access through * {@link CarrierConfigManager#KEY_CONFIG_PLANS_PACKAGE_OVERRIDE_STRING}. *
@@ -1664,7 +1701,7 @@ public class SubscriptionManager { * This method is only accessible to the following narrow set of apps: *
    *
  • The carrier app for this subscriberId, as determined by - * {@link TelephonyManager#hasCarrierPrivileges(int)}. + * {@link TelephonyManager#hasCarrierPrivileges()}. *
  • The carrier app explicitly delegated access through * {@link CarrierConfigManager#KEY_CONFIG_PLANS_PACKAGE_OVERRIDE_STRING}. *
@@ -1695,8 +1732,8 @@ public class SubscriptionManager { } /** - * Create an {@link Intent} that will launch towards the carrier app that is - * currently defining the billing relationship plan through + * Create an {@link Intent} that can be launched towards the carrier app + * that is currently defining the billing relationship plan through * {@link #setSubscriptionPlans(int, List)}. * * @return ready to launch Intent targeted towards the carrier app, or @@ -1725,4 +1762,55 @@ public class SubscriptionManager { return intent; } + + /** @hide */ + private @Nullable Intent createRefreshSubscriptionIntent(int subId) { + // Bail if no owner + final String owner = getSubscriptionPlansOwner(subId); + if (owner == null) return null; + + // Bail if no plans + final List plans = getSubscriptionPlans(subId); + if (plans.isEmpty()) return null; + + final Intent intent = new Intent(ACTION_REFRESH_SUBSCRIPTION_PLANS); + intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); + intent.setPackage(owner); + intent.putExtra(EXTRA_SUBSCRIPTION_INDEX, subId); + + // Bail if not implemented + if (mContext.getPackageManager().queryBroadcastReceivers(intent, 0).isEmpty()) { + return null; + } + + return intent; + } + + /** + * Check if there is a carrier app that is currently defining the billing + * relationship plan through {@link #setSubscriptionPlans(int, List)} that + * supports refreshing of subscription plans. + * + * @hide + */ + public boolean isSubscriptionPlansRefreshSupported(int subId) { + return createRefreshSubscriptionIntent(subId) != null; + } + + /** + * Request that the carrier app that is currently defining the billing + * relationship plan through {@link #setSubscriptionPlans(int, List)} + * refresh its subscription plans. + *

+ * If the app is able to successfully update the plans, you'll expect to + * receive the {@link #ACTION_SUBSCRIPTION_PLANS_CHANGED} broadcast. + * + * @hide + */ + public void requestSubscriptionPlansRefresh(int subId) { + final Intent intent = createRefreshSubscriptionIntent(subId); + final BroadcastOptions options = BroadcastOptions.makeBasic(); + options.setTemporaryAppWhitelistDuration(TimeUnit.MINUTES.toMillis(1)); + mContext.sendBroadcast(intent, null, options.toBundle()); + } }