new SystemAPI for setCarrierDataEnabled
Bug: 116138716 Test: Telephony unit test Change-Id: I6fba04dab8fd067f49b17afa2a640b7d00092a3f Merged-in: I6fba04dab8fd067f49b17afa2a640b7d00092a3f
This commit is contained in:
@@ -5287,6 +5287,7 @@ package android.telephony {
|
||||
method public deprecated boolean isVisualVoicemailEnabled(android.telecom.PhoneAccountHandle);
|
||||
method public boolean needsOtaServiceProvisioning();
|
||||
method public int setAllowedCarriers(int, java.util.List<android.service.carrier.CarrierIdentifier>);
|
||||
method public void setCarrierDataEnabled(boolean);
|
||||
method public void setDataActivationState(int);
|
||||
method public deprecated void setDataEnabled(int, boolean);
|
||||
method public void setDataRoamingEnabled(boolean);
|
||||
|
||||
@@ -30,7 +30,7 @@ import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.carrierdefaultapp.R;
|
||||
|
||||
/**
|
||||
* This util class provides common logic for carrier actions
|
||||
*/
|
||||
@@ -102,7 +102,7 @@ public class CarrierActionUtils {
|
||||
SubscriptionManager.getDefaultVoiceSubscriptionId());
|
||||
logd("onDisableAllMeteredApns subId: " + subId);
|
||||
final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
|
||||
telephonyMgr.carrierActionSetMeteredApnsEnabled(subId, !ENABLE);
|
||||
telephonyMgr.createForSubscriptionId(subId).setCarrierDataEnabled(!ENABLE);
|
||||
}
|
||||
|
||||
private static void onEnableAllMeteredApns(Intent intent, Context context) {
|
||||
@@ -110,7 +110,7 @@ public class CarrierActionUtils {
|
||||
SubscriptionManager.getDefaultVoiceSubscriptionId());
|
||||
logd("onEnableAllMeteredApns subId: " + subId);
|
||||
final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
|
||||
telephonyMgr.carrierActionSetMeteredApnsEnabled(subId, ENABLE);
|
||||
telephonyMgr.createForSubscriptionId(subId).setCarrierDataEnabled(ENABLE);
|
||||
}
|
||||
|
||||
private static void onEnableDefaultURLHandler(Context context) {
|
||||
|
||||
@@ -104,6 +104,6 @@ public class CarrierDefaultReceiverTest extends InstrumentationTestCase {
|
||||
assertNotNull(pendingIntent);
|
||||
|
||||
Rlog.d(TAG, "verify carrier action: disable all metered apns");
|
||||
verify(mTelephonyMgr).carrierActionSetMeteredApnsEnabled(eq(subId), eq(false));
|
||||
verify(mTelephonyMgr).setCarrierDataEnabled(eq(false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8319,20 +8319,31 @@ public class TelephonyManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Action set from carrier signalling broadcast receivers to enable/disable metered apns
|
||||
* Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required
|
||||
* @param subId the subscription ID that this action applies to.
|
||||
* @param enabled control enable or disable metered apns.
|
||||
* Used to enable or disable carrier data by the system based on carrier signalling or
|
||||
* carrier privileged apps. Different from {@link #setDataEnabled(boolean)} which is linked to
|
||||
* user settings, carrier data on/off won't affect user settings but will bypass the
|
||||
* settings and turns off data internally if set to {@code false}.
|
||||
*
|
||||
* <p>If this object has been created with {@link #createForSubscriptionId}, applies to the
|
||||
* given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()}
|
||||
*
|
||||
* <p>Requires Permission:
|
||||
* {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
|
||||
*
|
||||
* @param enabled control enable or disable carrier data.
|
||||
* @hide
|
||||
*/
|
||||
public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
|
||||
@SystemApi
|
||||
@RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
|
||||
public void setCarrierDataEnabled(boolean enabled) {
|
||||
try {
|
||||
ITelephony service = getITelephony();
|
||||
if (service != null) {
|
||||
service.carrierActionSetMeteredApnsEnabled(subId, enabled);
|
||||
service.carrierActionSetMeteredApnsEnabled(
|
||||
getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enabled);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error calling ITelephony#carrierActionSetMeteredApnsEnabled", e);
|
||||
Log.e(TAG, "Error calling ITelephony#setCarrierDataEnabled", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user