Merge "Create new APIs for overriding APNs"
am: 13beb87783
Change-Id: I523c37c06cb7636775131720c252f06cb2eb152f
This commit is contained in:
@@ -6746,7 +6746,9 @@ package android.provider {
|
||||
public static final class Telephony.Carriers implements android.provider.BaseColumns {
|
||||
field public static final String APN_SET_ID = "apn_set_id";
|
||||
field public static final int CARRIER_EDITED = 4; // 0x4
|
||||
field @NonNull public static final android.net.Uri DPC_URI;
|
||||
field public static final String EDITED_STATUS = "edited";
|
||||
field public static final int INVALID_APN_ID = -1; // 0xffffffff
|
||||
field public static final String MAX_CONNECTIONS = "max_conns";
|
||||
field public static final String MODEM_PERSIST = "modem_cognitive";
|
||||
field public static final String MTU = "mtu";
|
||||
@@ -8942,6 +8944,7 @@ package android.telephony {
|
||||
}
|
||||
|
||||
public class TelephonyManager {
|
||||
method public int addDevicePolicyOverrideApn(@NonNull android.content.Context, @NonNull android.telephony.data.ApnSetting);
|
||||
method @Deprecated @RequiresPermission(android.Manifest.permission.CALL_PHONE) public void call(String, String);
|
||||
method public int checkCarrierPrivilegesForPackage(String);
|
||||
method public int checkCarrierPrivilegesForPackageAnyPhone(String);
|
||||
@@ -8968,6 +8971,7 @@ package android.telephony {
|
||||
method @Deprecated public boolean getDataEnabled();
|
||||
method @Deprecated public boolean getDataEnabled(int);
|
||||
method @Nullable public static android.content.ComponentName getDefaultRespondViaMessageApplication(@NonNull android.content.Context, boolean);
|
||||
method @NonNull public java.util.List<android.telephony.data.ApnSetting> getDevicePolicyOverrideApns(@NonNull android.content.Context);
|
||||
method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getDeviceSoftwareVersion(int);
|
||||
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean getEmergencyCallbackMode();
|
||||
method public int getEmergencyNumberDbVersion();
|
||||
@@ -9011,6 +9015,7 @@ package android.telephony {
|
||||
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isTetheringApnRequired();
|
||||
method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isVideoCallingEnabled();
|
||||
method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public boolean isVisualVoicemailEnabled(android.telecom.PhoneAccountHandle);
|
||||
method public boolean modifyDevicePolicyOverrideApn(@NonNull android.content.Context, int, @NonNull android.telephony.data.ApnSetting);
|
||||
method public boolean needsOtaServiceProvisioning();
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void notifyOtaEmergencyNumberDbInstalled();
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean rebootRadio();
|
||||
|
||||
@@ -3040,14 +3040,17 @@ package android.telephony {
|
||||
}
|
||||
|
||||
public class TelephonyManager {
|
||||
method public int addDevicePolicyOverrideApn(@NonNull android.content.Context, @NonNull android.telephony.data.ApnSetting);
|
||||
method public int checkCarrierPrivilegesForPackage(String);
|
||||
method public int getCarrierIdListVersion();
|
||||
method public java.util.List<java.lang.String> getCarrierPackageNamesForIntent(android.content.Intent);
|
||||
method @Nullable public static android.content.ComponentName getDefaultRespondViaMessageApplication(@NonNull android.content.Context, boolean);
|
||||
method @NonNull public java.util.List<android.telephony.data.ApnSetting> getDevicePolicyOverrideApns(@NonNull android.content.Context);
|
||||
method public int getEmergencyNumberDbVersion();
|
||||
method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getLine1AlphaTag();
|
||||
method @NonNull @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public String getNetworkCountryIso(int);
|
||||
method public android.util.Pair<java.lang.Integer,java.lang.Integer> getRadioHalVersion();
|
||||
method public boolean modifyDevicePolicyOverrideApn(@NonNull android.content.Context, int, @NonNull android.telephony.data.ApnSetting);
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void refreshUiccProfile();
|
||||
method @Deprecated public void setCarrierTestOverride(String, String, String, String, String, String, String);
|
||||
method public void setCarrierTestOverride(String, String, String, String, String, String, String, String, String);
|
||||
|
||||
@@ -3522,7 +3522,8 @@ public final class Telephony {
|
||||
* can manage DPC-owned APNs.
|
||||
* @hide
|
||||
*/
|
||||
public static final Uri DPC_URI = Uri.parse("content://telephony/carriers/dpc");
|
||||
@SystemApi
|
||||
public static final @NonNull Uri DPC_URI = Uri.parse("content://telephony/carriers/dpc");
|
||||
|
||||
/**
|
||||
* The {@code content://} style URL to be called from Telephony to query APNs.
|
||||
@@ -3830,6 +3831,13 @@ public final class Telephony {
|
||||
@SystemApi
|
||||
public static final String USER_EDITABLE = "user_editable";
|
||||
|
||||
/**
|
||||
* Integer value denoting an invalid APN id
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public static final int INVALID_APN_ID = -1;
|
||||
|
||||
/**
|
||||
* {@link #EDITED_STATUS APN edit status} indicates that this APN has not been edited or
|
||||
* fails to edit.
|
||||
|
||||
@@ -206,6 +206,7 @@ import android.provider.ContactsContract.QuickContact;
|
||||
import android.provider.ContactsInternal;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Global;
|
||||
import android.provider.Telephony;
|
||||
import android.security.IKeyChainAliasCallback;
|
||||
import android.security.IKeyChainService;
|
||||
import android.security.KeyChain;
|
||||
@@ -246,6 +247,7 @@ import com.android.internal.telephony.SmsApplication;
|
||||
import com.android.internal.util.DumpUtils;
|
||||
import com.android.internal.util.FastXmlSerializer;
|
||||
import com.android.internal.util.FunctionalUtils.ThrowingRunnable;
|
||||
import com.android.internal.util.FunctionalUtils.ThrowingSupplier;
|
||||
import com.android.internal.util.JournaledFile;
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.internal.util.StatLogger;
|
||||
@@ -2061,6 +2063,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
Binder.withCleanCallingIdentity(action);
|
||||
}
|
||||
|
||||
final <T> T binderWithCleanCallingIdentity(@NonNull ThrowingSupplier<T> action) {
|
||||
return Binder.withCleanCallingIdentity(action);
|
||||
}
|
||||
|
||||
final int userHandleGetCallingUserId() {
|
||||
return UserHandle.getUserId(binderGetCallingUid());
|
||||
}
|
||||
@@ -13936,23 +13942,14 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
Preconditions.checkNotNull(apnSetting, "ApnSetting is null in addOverrideApn");
|
||||
enforceDeviceOwner(who);
|
||||
|
||||
int operatedId = -1;
|
||||
Uri resultUri;
|
||||
final long id = mInjector.binderClearCallingIdentity();
|
||||
try {
|
||||
resultUri = mContext.getContentResolver().insert(DPC_URI, apnSetting.toContentValues());
|
||||
} finally {
|
||||
mInjector.binderRestoreCallingIdentity(id);
|
||||
TelephonyManager tm = mContext.getSystemService(TelephonyManager.class);
|
||||
if (tm != null) {
|
||||
return mInjector.binderWithCleanCallingIdentity(
|
||||
() -> tm.addDevicePolicyOverrideApn(mContext, apnSetting));
|
||||
} else {
|
||||
Log.w(LOG_TAG, "TelephonyManager is null when trying to add override apn");
|
||||
return Telephony.Carriers.INVALID_APN_ID;
|
||||
}
|
||||
if (resultUri != null) {
|
||||
try {
|
||||
operatedId = Integer.parseInt(resultUri.getLastPathSegment());
|
||||
} catch (NumberFormatException e) {
|
||||
Slog.e(LOG_TAG, "Failed to parse inserted override APN id.", e);
|
||||
}
|
||||
}
|
||||
|
||||
return operatedId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -13968,13 +13965,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
if (apnId < 0) {
|
||||
return false;
|
||||
}
|
||||
final long id = mInjector.binderClearCallingIdentity();
|
||||
try {
|
||||
return mContext.getContentResolver().update(
|
||||
Uri.withAppendedPath(DPC_URI, Integer.toString(apnId)),
|
||||
apnSetting.toContentValues(), null, null) > 0;
|
||||
} finally {
|
||||
mInjector.binderRestoreCallingIdentity(id);
|
||||
TelephonyManager tm = mContext.getSystemService(TelephonyManager.class);
|
||||
if (tm != null) {
|
||||
return mInjector.binderWithCleanCallingIdentity(
|
||||
() -> tm.modifyDevicePolicyOverrideApn(mContext, apnId, apnSetting));
|
||||
} else {
|
||||
Log.w(LOG_TAG, "TelephonyManager is null when trying to modify override apn");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14016,28 +14013,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
||||
}
|
||||
|
||||
private List<ApnSetting> getOverrideApnsUnchecked() {
|
||||
final Cursor cursor;
|
||||
final long id = mInjector.binderClearCallingIdentity();
|
||||
try {
|
||||
cursor = mContext.getContentResolver().query(DPC_URI, null, null, null, null);
|
||||
} finally {
|
||||
mInjector.binderRestoreCallingIdentity(id);
|
||||
}
|
||||
|
||||
if (cursor == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
try {
|
||||
List<ApnSetting> apnList = new ArrayList<ApnSetting>();
|
||||
cursor.moveToPosition(-1);
|
||||
while (cursor.moveToNext()) {
|
||||
ApnSetting apn = ApnSetting.makeApnSetting(cursor);
|
||||
apnList.add(apn);
|
||||
}
|
||||
return apnList;
|
||||
} finally {
|
||||
cursor.close();
|
||||
TelephonyManager tm = mContext.getSystemService(TelephonyManager.class);
|
||||
if (tm != null) {
|
||||
return mInjector.binderWithCleanCallingIdentity(
|
||||
() -> tm.getDevicePolicyOverrideApns(mContext));
|
||||
}
|
||||
Log.w(LOG_TAG, "TelephonyManager is null when trying to get override apns");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -217,6 +217,8 @@ public class DpmMockContext extends MockContext {
|
||||
return mMockSystemServices.wifiManager;
|
||||
case Context.ACCOUNT_SERVICE:
|
||||
return mMockSystemServices.accountManager;
|
||||
case Context.TELEPHONY_SERVICE:
|
||||
return mMockSystemServices.telephonyManager;
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package android.telephony;
|
||||
|
||||
import static android.content.Context.TELECOM_SERVICE;
|
||||
import static android.provider.Telephony.Carriers.DPC_URI;
|
||||
import static android.provider.Telephony.Carriers.INVALID_APN_ID;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
|
||||
@@ -44,6 +46,7 @@ import android.compat.annotation.EnabledAfter;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkStats;
|
||||
import android.net.Uri;
|
||||
@@ -75,6 +78,7 @@ import android.telephony.Annotation.NetworkType;
|
||||
import android.telephony.Annotation.RadioPowerState;
|
||||
import android.telephony.Annotation.SimActivationState;
|
||||
import android.telephony.VisualVoicemailService.VisualVoicemailTask;
|
||||
import android.telephony.data.ApnSetting;
|
||||
import android.telephony.emergency.EmergencyNumber;
|
||||
import android.telephony.emergency.EmergencyNumber.EmergencyServiceCategories;
|
||||
import android.telephony.ims.ImsMmTelManager;
|
||||
@@ -11670,6 +11674,88 @@ public class TelephonyManager {
|
||||
return new Pair<Integer, Integer>(-1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of APNs set as overrides by the device policy manager via
|
||||
* {@link #addDevicePolicyOverrideApn}.
|
||||
* This method must only be called from the system or phone processes.
|
||||
*
|
||||
* @param context Context to use.
|
||||
* @return {@link List} of APNs that have been set as overrides.
|
||||
* @throws {@link SecurityException} if the caller is not the system or phone process.
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@TestApi
|
||||
// TODO: add new permission tag indicating that this is system-only.
|
||||
public @NonNull List<ApnSetting> getDevicePolicyOverrideApns(@NonNull Context context) {
|
||||
try (Cursor cursor = context.getContentResolver().query(DPC_URI, null, null, null, null)) {
|
||||
if (cursor == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<ApnSetting> apnList = new ArrayList<ApnSetting>();
|
||||
cursor.moveToPosition(-1);
|
||||
while (cursor.moveToNext()) {
|
||||
ApnSetting apn = ApnSetting.makeApnSetting(cursor);
|
||||
apnList.add(apn);
|
||||
}
|
||||
return apnList;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by the device policy manager to add a new override APN.
|
||||
* This method must only be called from the system or phone processes.
|
||||
*
|
||||
* @param context Context to use.
|
||||
* @param apnSetting The {@link ApnSetting} describing the new APN.
|
||||
* @return An integer, corresponding to a primary key in a database, that allows the caller to
|
||||
* modify the APN in the future via {@link #modifyDevicePolicyOverrideApn}, or
|
||||
* {@link android.provider.Telephony.Carriers.INVALID_APN_ID} if the override operation
|
||||
* failed.
|
||||
* @throws {@link SecurityException} if the caller is not the system or phone process.
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@TestApi
|
||||
// TODO: add new permission tag indicating that this is system-only.
|
||||
public int addDevicePolicyOverrideApn(@NonNull Context context,
|
||||
@NonNull ApnSetting apnSetting) {
|
||||
Uri resultUri = context.getContentResolver().insert(DPC_URI, apnSetting.toContentValues());
|
||||
|
||||
int resultId = INVALID_APN_ID;
|
||||
if (resultUri != null) {
|
||||
try {
|
||||
resultId = Integer.parseInt(resultUri.getLastPathSegment());
|
||||
} catch (NumberFormatException e) {
|
||||
Rlog.e(TAG, "Failed to parse inserted override APN id: "
|
||||
+ resultUri.getLastPathSegment());
|
||||
}
|
||||
}
|
||||
return resultId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by the device policy manager to modify an override APN.
|
||||
* This method must only be called from the system or phone processes.
|
||||
*
|
||||
* @param context Context to use.
|
||||
* @param apnId The integer key of the APN to modify, as returned by
|
||||
* {@link #addDevicePolicyOverrideApn}
|
||||
* @param apnSetting The {@link ApnSetting} describing the updated APN.
|
||||
* @return {@code true} if successful, {@code false} otherwise.
|
||||
* @throws {@link SecurityException} if the caller is not the system or phone process.
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@TestApi
|
||||
// TODO: add new permission tag indicating that this is system-only.
|
||||
public boolean modifyDevicePolicyOverrideApn(@NonNull Context context, int apnId,
|
||||
@NonNull ApnSetting apnSetting) {
|
||||
return context.getContentResolver().update(
|
||||
Uri.withAppendedPath(DPC_URI, Integer.toString(apnId)),
|
||||
apnSetting.toContentValues(), null, null) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether data is enabled for certain APN type. This will tell if framework will accept
|
||||
* corresponding network requests on a subId.
|
||||
|
||||
Reference in New Issue
Block a user