Merge "Made setPolicyDataEnabled a SystemApi"
This commit is contained in:
committed by
Android (Google) Code Review
commit
61b4e7136e
@@ -10131,6 +10131,7 @@ package android.telephony {
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataRoamingEnabled(boolean);
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMultiSimCarrierRestriction(boolean);
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setOpportunisticNetworkState(boolean);
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setPolicyDataEnabled(boolean);
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setPreferredNetworkTypeBitmask(long);
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setRadio(boolean);
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setRadioEnabled(boolean);
|
||||
|
||||
@@ -1780,7 +1780,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
final TelephonyManager tm = mContext.getSystemService(TelephonyManager.class);
|
||||
for (int i = 0; i < matchingSubIds.size(); i++) {
|
||||
final int subId = matchingSubIds.get(i);
|
||||
tm.setPolicyDataEnabled(enabled, subId);
|
||||
tm.createForSubscriptionId(subId).setPolicyDataEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1819,7 +1819,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
|
||||
final List<String[]> mergedSubscriberIdsList = new ArrayList();
|
||||
final SparseArray<String> subIdToSubscriberId = new SparseArray<>(subList.size());
|
||||
for (SubscriptionInfo sub : subList) {
|
||||
for (final SubscriptionInfo sub : subList) {
|
||||
final TelephonyManager tmSub = tm.createForSubscriptionId(sub.getSubscriptionId());
|
||||
final String subscriberId = tmSub.getSubscriberId();
|
||||
if (!TextUtils.isEmpty(subscriberId)) {
|
||||
|
||||
@@ -1138,11 +1138,11 @@ public class NetworkPolicyManagerServiceTest {
|
||||
new NetworkStats.Entry(DataUnit.MEGABYTES.toBytes(360), 0L, 0L, 0L, 0));
|
||||
|
||||
reset(mTelephonyManager, mNetworkManager, mNotifManager);
|
||||
expectMobileDefaults();
|
||||
TelephonyManager tmSub = expectMobileDefaults();
|
||||
|
||||
mService.updateNetworks();
|
||||
|
||||
verify(mTelephonyManager, atLeastOnce()).setPolicyDataEnabled(true, TEST_SUB_ID);
|
||||
verify(tmSub, atLeastOnce()).setPolicyDataEnabled(true);
|
||||
verify(mNetworkManager, atLeastOnce()).setInterfaceQuota(TEST_IFACE,
|
||||
DataUnit.MEGABYTES.toBytes(1800 - 360));
|
||||
verify(mNotifManager, never()).notifyAsUser(any(), anyInt(), any(), any());
|
||||
@@ -1155,11 +1155,11 @@ public class NetworkPolicyManagerServiceTest {
|
||||
new NetworkStats.Entry(DataUnit.MEGABYTES.toBytes(1799), 0L, 0L, 0L, 0));
|
||||
|
||||
reset(mTelephonyManager, mNetworkManager, mNotifManager);
|
||||
expectMobileDefaults();
|
||||
TelephonyManager tmSub = expectMobileDefaults();
|
||||
|
||||
mService.updateNetworks();
|
||||
|
||||
verify(mTelephonyManager, atLeastOnce()).setPolicyDataEnabled(true, TEST_SUB_ID);
|
||||
verify(tmSub, atLeastOnce()).setPolicyDataEnabled(true);
|
||||
verify(mNetworkManager, atLeastOnce()).setInterfaceQuota(TEST_IFACE,
|
||||
DataUnit.MEGABYTES.toBytes(1800 - 1799));
|
||||
verify(mNotifManager, atLeastOnce()).notifyAsUser(any(), eq(TYPE_WARNING),
|
||||
@@ -1173,12 +1173,12 @@ public class NetworkPolicyManagerServiceTest {
|
||||
new NetworkStats.Entry(DataUnit.MEGABYTES.toBytes(1799), 0L, 0L, 0L, 0));
|
||||
|
||||
reset(mTelephonyManager, mNetworkManager, mNotifManager);
|
||||
expectMobileDefaults();
|
||||
TelephonyManager tmSub = expectMobileDefaults();
|
||||
expectDefaultCarrierConfig();
|
||||
|
||||
mService.updateNetworks();
|
||||
|
||||
verify(mTelephonyManager, atLeastOnce()).setPolicyDataEnabled(true, TEST_SUB_ID);
|
||||
verify(tmSub, atLeastOnce()).setPolicyDataEnabled(true);
|
||||
verify(mNetworkManager, atLeastOnce()).setInterfaceQuota(TEST_IFACE,
|
||||
DataUnit.MEGABYTES.toBytes(1800 - 1799));
|
||||
// Since this isn't from the identified carrier, there should be no notifications
|
||||
@@ -1192,11 +1192,11 @@ public class NetworkPolicyManagerServiceTest {
|
||||
new NetworkStats.Entry(DataUnit.MEGABYTES.toBytes(1810), 0L, 0L, 0L, 0));
|
||||
|
||||
reset(mTelephonyManager, mNetworkManager, mNotifManager);
|
||||
expectMobileDefaults();
|
||||
TelephonyManager tmSub = expectMobileDefaults();
|
||||
|
||||
mService.updateNetworks();
|
||||
|
||||
verify(mTelephonyManager, atLeastOnce()).setPolicyDataEnabled(false, TEST_SUB_ID);
|
||||
verify(tmSub, atLeastOnce()).setPolicyDataEnabled(false);
|
||||
verify(mNetworkManager, atLeastOnce()).setInterfaceQuota(TEST_IFACE, 1);
|
||||
verify(mNotifManager, atLeastOnce()).notifyAsUser(any(), eq(TYPE_LIMIT),
|
||||
isA(Notification.class), eq(UserHandle.ALL));
|
||||
@@ -1205,12 +1205,12 @@ public class NetworkPolicyManagerServiceTest {
|
||||
// Snooze limit
|
||||
{
|
||||
reset(mTelephonyManager, mNetworkManager, mNotifManager);
|
||||
expectMobileDefaults();
|
||||
TelephonyManager tmSub = expectMobileDefaults();
|
||||
|
||||
mService.snoozeLimit(NetworkTemplate.buildTemplateMobileAll(TEST_IMSI));
|
||||
mService.updateNetworks();
|
||||
|
||||
verify(mTelephonyManager, atLeastOnce()).setPolicyDataEnabled(true, TEST_SUB_ID);
|
||||
verify(tmSub, atLeastOnce()).setPolicyDataEnabled(true);
|
||||
verify(mNetworkManager, atLeastOnce()).setInterfaceQuota(TEST_IFACE,
|
||||
Long.MAX_VALUE);
|
||||
verify(mNotifManager, atLeastOnce()).notifyAsUser(any(), eq(TYPE_LIMIT_SNOOZED),
|
||||
@@ -1928,10 +1928,11 @@ public class NetworkPolicyManagerServiceTest {
|
||||
.thenReturn(CarrierConfigManager.getDefaultConfig());
|
||||
}
|
||||
|
||||
private void expectMobileDefaults() throws Exception {
|
||||
setupTelephonySubscriptionManagers(TEST_SUB_ID, TEST_IMSI);
|
||||
doNothing().when(mTelephonyManager).setPolicyDataEnabled(anyBoolean(), anyInt());
|
||||
private TelephonyManager expectMobileDefaults() throws Exception {
|
||||
TelephonyManager tmSub = setupTelephonySubscriptionManagers(TEST_SUB_ID, TEST_IMSI);
|
||||
doNothing().when(tmSub).setPolicyDataEnabled(anyBoolean());
|
||||
expectNetworkState(false /* roaming */);
|
||||
return tmSub;
|
||||
}
|
||||
|
||||
private void verifyAdvisePersistThreshold() throws Exception {
|
||||
@@ -2090,8 +2091,10 @@ public class NetworkPolicyManagerServiceTest {
|
||||
|
||||
/**
|
||||
* Creates a mock {@link TelephonyManager} and {@link SubscriptionManager}.
|
||||
*
|
||||
*/
|
||||
private void setupTelephonySubscriptionManagers(int subscriptionId, String subscriberId) {
|
||||
private TelephonyManager setupTelephonySubscriptionManagers(int subscriptionId,
|
||||
String subscriberId) {
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
|
||||
createSubscriptionInfoList(subscriptionId));
|
||||
|
||||
@@ -2101,6 +2104,7 @@ public class NetworkPolicyManagerServiceTest {
|
||||
when(subTelephonyManager.getSubscriberId()).thenReturn(subscriberId);
|
||||
when(mTelephonyManager.createForSubscriptionId(subscriptionId))
|
||||
.thenReturn(subTelephonyManager);
|
||||
return subTelephonyManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10520,14 +10520,15 @@ public class TelephonyManager {
|
||||
/**
|
||||
* Policy control of data connection. Usually used when data limit is passed.
|
||||
* @param enabled True if enabling the data, otherwise disabling.
|
||||
* @param subId sub id
|
||||
* @hide
|
||||
*/
|
||||
public void setPolicyDataEnabled(boolean enabled, int subId) {
|
||||
@SystemApi
|
||||
@RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
|
||||
public void setPolicyDataEnabled(boolean enabled) {
|
||||
try {
|
||||
ITelephony service = getITelephony();
|
||||
if (service != null) {
|
||||
service.setPolicyDataEnabled(enabled, subId);
|
||||
service.setPolicyDataEnabled(enabled, getSubId());
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error calling ITelephony#setPolicyDataEnabled", e);
|
||||
|
||||
Reference in New Issue
Block a user