Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7dd38c21 authored by Chen Xu's avatar Chen Xu Committed by Gerrit Code Review
Browse files

Merge "new SystemAPI for setCarrierDataEnabled"

parents a18e0957 3d59fdb7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5304,6 +5304,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);
+3 −3
Original line number Diff line number Diff line
@@ -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) {
+1 −1
Original line number Diff line number Diff line
@@ -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));
    }
}
+18 −7
Original line number Diff line number Diff line
@@ -8317,20 +8317,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);
        }
    }