Merge changes from topic "planz" into pi-dev

* changes:
  Tests for SubscriptionManager APIs.
  Obtain NPMS through helper method.
This commit is contained in:
TreeHugger Robot
2018-04-02 21:56:59 +00:00
committed by Android (Google) Code Review
4 changed files with 59 additions and 11 deletions

View File

@@ -149,7 +149,6 @@ import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.BestClock;
import android.os.Binder;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
@@ -367,6 +366,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
private static final int UID_MSG_STATE_CHANGED = 100;
private static final int UID_MSG_GONE = 101;
private static final String PROP_SUB_PLAN_OWNER = "persist.sys.sub_plan_owner";
private final Context mContext;
private final IActivityManager mActivityManager;
private NetworkStatsManagerInternal mNetworkStats;
@@ -2796,10 +2797,17 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
return;
}
// Fourth check: is caller a testing app on a debug build?
final boolean enableDebug = Build.IS_USERDEBUG || Build.IS_ENG;
if (enableDebug && callingPackage
.equals(SystemProperties.get("fw.sub_plan_owner." + subId, null))) {
// Fourth check: is caller a testing app?
final String testPackage = SystemProperties.get(PROP_SUB_PLAN_OWNER + "." + subId, null);
if (!TextUtils.isEmpty(testPackage)
&& Objects.equals(testPackage, callingPackage)) {
return;
}
// Fifth check: is caller a legacy testing app?
final String legacyTestPackage = SystemProperties.get("fw.sub_plan_owner." + subId, null);
if (!TextUtils.isEmpty(legacyTestPackage)
&& Objects.equals(legacyTestPackage, callingPackage)) {
return;
}
@@ -3000,6 +3008,14 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
}
}
/**
* Only visible for testing purposes. This doesn't give any access to
* existing plans; it simply lets the debug package define new plans.
*/
void setSubscriptionPlansOwner(int subId, String packageName) {
SystemProperties.set(PROP_SUB_PLAN_OWNER + "." + subId, packageName);
}
@Override
public String getSubscriptionPlansOwner(int subId) {
if (UserHandle.getCallingAppId() != android.os.Process.SYSTEM_UID) {

View File

@@ -21,7 +21,6 @@ import static android.net.NetworkPolicyManager.POLICY_NONE;
import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
import android.content.Context;
import android.net.INetworkPolicyManager;
import android.net.NetworkPolicyManager;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
@@ -33,10 +32,10 @@ import java.util.List;
class NetworkPolicyManagerShellCommand extends ShellCommand {
private final INetworkPolicyManager mInterface;
private final NetworkPolicyManagerService mInterface;
private final WifiManager mWifiManager;
NetworkPolicyManagerShellCommand(Context context, INetworkPolicyManager service) {
NetworkPolicyManagerShellCommand(Context context, NetworkPolicyManagerService service) {
mInterface = service;
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
}
@@ -97,6 +96,8 @@ class NetworkPolicyManagerShellCommand extends ShellCommand {
pw.println(" Toggles whether the given wi-fi network is metered.");
pw.println(" set restrict-background BOOLEAN");
pw.println(" Sets the global restrict background usage status.");
pw.println(" set sub-plan-owner subId [packageName]");
pw.println(" Sets the data plan owner package for subId.");
}
private int runGet() throws RemoteException {
@@ -126,6 +127,8 @@ class NetworkPolicyManagerShellCommand extends ShellCommand {
return setMeteredWifiNetwork();
case "restrict-background":
return setRestrictBackground();
case "sub-plan-owner":
return setSubPlanOwner();
}
pw.println("Error: unknown set type '" + type + "'");
return -1;
@@ -227,6 +230,13 @@ class NetworkPolicyManagerShellCommand extends ShellCommand {
return 0;
}
private int setSubPlanOwner() throws RemoteException {
final int subId = Integer.parseInt(getNextArgRequired());
final String packageName = getNextArg();
mInterface.setSubscriptionPlansOwner(subId, packageName);
return 0;
}
private int setUidPolicy(int policy) throws RemoteException {
final int uid = getUidFromNextArg();
if (uid < 0) {

View File

@@ -505,7 +505,7 @@ public class SubscriptionManager {
public static final String EXTRA_SUBSCRIPTION_INDEX = "android.telephony.extra.SUBSCRIPTION_INDEX";
private final Context mContext;
private INetworkPolicyManager mNetworkPolicy;
private volatile INetworkPolicyManager mNetworkPolicy;
/**
* A listener class for monitoring changes to {@link SubscriptionInfo} records.
@@ -1794,7 +1794,7 @@ public class SubscriptionManager {
@DurationMillisLong long timeoutMillis) {
try {
final int overrideValue = overrideUnmetered ? OVERRIDE_UNMETERED : 0;
mNetworkPolicy.setSubscriptionOverride(subId, OVERRIDE_UNMETERED, overrideValue,
getNetworkPolicy().setSubscriptionOverride(subId, OVERRIDE_UNMETERED, overrideValue,
timeoutMillis, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
@@ -1828,7 +1828,7 @@ public class SubscriptionManager {
@DurationMillisLong long timeoutMillis) {
try {
final int overrideValue = overrideCongested ? OVERRIDE_CONGESTED : 0;
mNetworkPolicy.setSubscriptionOverride(subId, OVERRIDE_CONGESTED, overrideValue,
getNetworkPolicy().setSubscriptionOverride(subId, OVERRIDE_CONGESTED, overrideValue,
timeoutMillis, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();

View File

@@ -34,6 +34,7 @@ import java.lang.annotation.RetentionPolicy;
import java.time.Period;
import java.time.ZonedDateTime;
import java.util.Iterator;
import java.util.Objects;
/**
* Description of a billing relationship plan between a carrier and a specific
@@ -124,6 +125,27 @@ public final class SubscriptionPlan implements Parcelable {
.append("}").toString();
}
@Override
public int hashCode() {
return Objects.hash(cycleRule, title, summary, dataLimitBytes, dataLimitBehavior,
dataUsageBytes, dataUsageTime);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof SubscriptionPlan) {
final SubscriptionPlan other = (SubscriptionPlan) obj;
return Objects.equals(cycleRule, other.cycleRule)
&& Objects.equals(title, other.title)
&& Objects.equals(summary, other.summary)
&& dataLimitBytes == other.dataLimitBytes
&& dataLimitBehavior == other.dataLimitBehavior
&& dataUsageBytes == other.dataUsageBytes
&& dataUsageTime == other.dataUsageTime;
}
return false;
}
public static final Parcelable.Creator<SubscriptionPlan> CREATOR = new Parcelable.Creator<SubscriptionPlan>() {
@Override
public SubscriptionPlan createFromParcel(Parcel source) {