Rewriting phone constants for mainline

* Exposing Emergency extra constants through TelephonyManager
* Always reading or writing PhoneConstants.SubscriptionKey
with SubscriptionManager.EXTRA_SUBSCRIPTION_KEY

Bug: 147465477
Test: FrameworksCoreTests, FrameworksServicesTest, CarrierTests
Change-Id: I84d6687ca6cab86c8c68dc2dd2679cfee0919c1e
This commit is contained in:
Daniel Bright
2020-01-09 21:58:16 -08:00
parent e2bb499531
commit 4bcbfce5fc
9 changed files with 78 additions and 41 deletions

View File

@@ -10583,6 +10583,8 @@ package android.telephony {
field public static final String EXTRA_ERROR_CODE = "errorCode";
field public static final String EXTRA_PCO_ID = "pcoId";
field public static final String EXTRA_PCO_VALUE = "pcoValue";
field public static final String EXTRA_PHONE_IN_ECM_STATE = "android.telephony.extra.PHONE_IN_ECM_STATE";
field public static final String EXTRA_PHONE_IN_EMERGENCY_CALL = "android.telephony.extra.PHONE_IN_EMERGENCY_CALL";
field public static final String EXTRA_REDIRECTION_URL = "redirectionUrl";
field public static final String EXTRA_SIM_STATE = "android.telephony.extra.SIM_STATE";
field public static final String EXTRA_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL = "android.telephony.extra.VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL";

View File

@@ -30,8 +30,6 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import com.android.internal.telephony.PhoneConstants;
/**
* This util class provides common logic for carrier actions
*/
@@ -103,7 +101,7 @@ public class CarrierActionUtils {
}
private static void onDisableAllMeteredApns(Intent intent, Context context) {
int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
SubscriptionManager.getDefaultVoiceSubscriptionId());
logd("onDisableAllMeteredApns subId: " + subId);
final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
@@ -111,7 +109,7 @@ public class CarrierActionUtils {
}
private static void onEnableAllMeteredApns(Intent intent, Context context) {
int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
SubscriptionManager.getDefaultVoiceSubscriptionId());
logd("onEnableAllMeteredApns subId: " + subId);
final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
@@ -135,7 +133,7 @@ public class CarrierActionUtils {
}
private static void onRegisterDefaultNetworkAvail(Intent intent, Context context) {
int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
SubscriptionManager.getDefaultVoiceSubscriptionId());
logd("onRegisterDefaultNetworkAvail subId: " + subId);
final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
@@ -143,7 +141,7 @@ public class CarrierActionUtils {
}
private static void onDeregisterDefaultNetworkAvail(Intent intent, Context context) {
int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
SubscriptionManager.getDefaultVoiceSubscriptionId());
logd("onDeregisterDefaultNetworkAvail subId: " + subId);
final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
@@ -151,7 +149,7 @@ public class CarrierActionUtils {
}
private static void onDisableRadio(Intent intent, Context context) {
int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
SubscriptionManager.getDefaultVoiceSubscriptionId());
logd("onDisableRadio subId: " + subId);
final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
@@ -159,7 +157,7 @@ public class CarrierActionUtils {
}
private static void onEnableRadio(Intent intent, Context context) {
int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
SubscriptionManager.getDefaultVoiceSubscriptionId());
logd("onEnableRadio subId: " + subId);
final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);
@@ -202,7 +200,7 @@ public class CarrierActionUtils {
}
private static void onResetAllCarrierActions(Intent intent, Context context) {
int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
SubscriptionManager.getDefaultVoiceSubscriptionId());
logd("onResetAllCarrierActions subId: " + subId);
final TelephonyManager telephonyMgr = context.getSystemService(TelephonyManager.class);

View File

@@ -15,6 +15,7 @@
*/
package com.android.carrierdefaultapp;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
@@ -26,11 +27,10 @@ import android.app.PendingIntent;
import android.content.Intent;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.test.InstrumentationTestCase;
import com.android.internal.telephony.PhoneConstants;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -69,6 +69,7 @@ public class CarrierDefaultReceiverTest extends InstrumentationTestCase {
mContext.injectSystemService(NotificationManager.class, mNotificationMgr);
mContext.injectSystemService(TelephonyManager.class, mTelephonyMgr);
mContext.injectSystemService(CarrierConfigManager.class, mCarrierConfigMgr);
doReturn(mTelephonyMgr).when(mTelephonyMgr).createForSubscriptionId(anyInt());
mReceiver = new CarrierDefaultBroadcastReceiver();
}
@@ -88,7 +89,7 @@ public class CarrierDefaultReceiverTest extends InstrumentationTestCase {
doReturn(b).when(mCarrierConfigMgr).getConfig();
Intent intent = new Intent(TelephonyManager.ACTION_CARRIER_SIGNAL_REDIRECTED);
intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
mReceiver.onReceive(mContext, intent);
mContext.waitForMs(100);

View File

@@ -59,7 +59,6 @@ import android.telecom.TelecomManager;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.FeatureFlagUtils;
import android.util.Log;
@@ -1415,8 +1414,8 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
} else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
// Airplane mode can be changed after ECM exits if airplane toggle button
// is pressed during ECM mode
if (!(intent.getBooleanExtra("PHONE_IN_ECM_STATE", false)) &&
mIsWaitingForEcmExit) {
if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
&& mIsWaitingForEcmExit) {
mIsWaitingForEcmExit = false;
changeAirplaneModeSystemSetting(true);
}

View File

@@ -30,12 +30,12 @@ import android.telephony.CellSignalStrength;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper.RunWithLooper;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
import com.android.settingslib.graph.SignalDrawable;
import com.android.settingslib.net.DataUsageController;
@@ -418,7 +418,7 @@ public class NetworkControllerSignalTest extends NetworkControllerBaseTest {
intent.putExtra(TelephonyIntents.EXTRA_SHOW_PLMN, showPlmn);
intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn);
intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
SubscriptionManager.putSubscriptionIdExtra(intent, mSubId);
return intent;
}

View File

@@ -743,8 +743,8 @@ class LegacyGlobalActions implements DialogInterface.OnDismissListener, DialogIn
} else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
// Airplane mode can be changed after ECM exits if airplane toggle button
// is pressed during ECM mode
if (!(intent.getBooleanExtra("PHONE_IN_ECM_STATE", false)) &&
mIsWaitingForEcmExit) {
if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false))
&& mIsWaitingForEcmExit) {
mIsWaitingForEcmExit = false;
changeAirplaneModeSystemSetting(true);
}

View File

@@ -16,8 +16,6 @@
package android.telephony;
import com.android.telephony.Rlog;
import static android.net.NetworkPolicyManager.OVERRIDE_CONGESTED;
import static android.net.NetworkPolicyManager.OVERRIDE_UNMETERED;
@@ -67,6 +65,7 @@ import com.android.internal.telephony.ISub;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.util.HandlerExecutor;
import com.android.internal.util.Preconditions;
import com.android.telephony.Rlog;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -2240,10 +2239,9 @@ public class SubscriptionManager {
@UnsupportedAppUsage
public static void putPhoneIdAndSubIdExtra(Intent intent, int phoneId, int subId) {
if (VDBG) logd("putPhoneIdAndSubIdExtra: phoneId=" + phoneId + " subId=" + subId);
intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
intent.putExtra(EXTRA_SUBSCRIPTION_INDEX, subId);
intent.putExtra(EXTRA_SLOT_INDEX, phoneId);
intent.putExtra(PhoneConstants.PHONE_KEY, phoneId);
putSubscriptionIdExtra(intent, subId);
}
/**
@@ -3489,4 +3487,19 @@ public class SubscriptionManager {
}
return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
}
/**
* Helper method that puts a subscription id on an intent with the constants:
* PhoneConstant.SUBSCRIPTION_KEY and SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX.
* Both constants are used to support backwards compatibility. Once we know we got all places,
* we can remove PhoneConstants.SUBSCRIPTION_KEY.
* @param intent Intent to put sub id on.
* @param subId SubscriptionId to put on intent.
*
* @hide
*/
public static void putSubscriptionIdExtra(Intent intent, int subId) {
intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId);
}
}

View File

@@ -1446,7 +1446,8 @@ public class TelephonyManager {
/**
* <p>Broadcast Action: The emergency callback mode is changed.
* <ul>
* <li><em>phoneinECMState</em> - A boolean value,true=phone in ECM, false=ECM off</li>
* <li><em>EXTRA_PHONE_IN_ECM_STATE</em> - A boolean value,true=phone in ECM,
* false=ECM off</li>
* </ul>
* <p class="note">
* You can <em>not</em> receive this through components declared
@@ -1456,12 +1457,25 @@ public class TelephonyManager {
*
* <p class="note">This is a protected intent that can only be sent by the system.
*
* @see #EXTRA_PHONE_IN_ECM_STATE
*
* @hide
*/
@SystemApi
@SuppressLint("ActionValue")
public static final String ACTION_EMERGENCY_CALLBACK_MODE_CHANGED
= "android.intent.action.EMERGENCY_CALLBACK_MODE_CHANGED";
public static final String ACTION_EMERGENCY_CALLBACK_MODE_CHANGED =
"android.intent.action.EMERGENCY_CALLBACK_MODE_CHANGED";
/**
* Extra included in {@link #ACTION_EMERGENCY_CALLBACK_MODE_CHANGED}.
* Indicates whether the phone is in an emergency phone state.
*
* @hide
*/
@SystemApi
public static final String EXTRA_PHONE_IN_ECM_STATE =
"android.telephony.extra.PHONE_IN_ECM_STATE";
/**
* <p>Broadcast Action: when data connections get redirected with validation failure.
@@ -1653,8 +1667,8 @@ public class TelephonyManager {
/**
* <p>Broadcast Action: The emergency call state is changed.
* <ul>
* <li><em>phoneInEmergencyCall</em> - A boolean value, true if phone in emergency call,
* false otherwise</li>
* <li><em>EXTRA_PHONE_IN_EMERGENCY_CALL</em> - A boolean value, true if phone in emergency
* call, false otherwise</li>
* </ul>
* <p class="note">
* You can <em>not</em> receive this through components declared
@@ -1664,12 +1678,25 @@ public class TelephonyManager {
*
* <p class="note">This is a protected intent that can only be sent by the system.
*
* @see #EXTRA_PHONE_IN_EMERGENCY_CALL
*
* @hide
*/
@SystemApi
@SuppressLint("ActionValue")
public static final String ACTION_EMERGENCY_CALL_STATE_CHANGED
= "android.intent.action.EMERGENCY_CALL_STATE_CHANGED";
public static final String ACTION_EMERGENCY_CALL_STATE_CHANGED =
"android.intent.action.EMERGENCY_CALL_STATE_CHANGED";
/**
* Extra included in {@link #ACTION_EMERGENCY_CALL_STATE_CHANGED}.
* It indicates whether the phone is making an emergency call.
*
* @hide
*/
@SystemApi
public static final String EXTRA_PHONE_IN_EMERGENCY_CALL =
"android.telephony.extra.PHONE_IN_EMERGENCY_CALL";
/**
* <p>Broadcast Action: It indicates the Emergency callback mode blocks datacall/sms
@@ -1682,8 +1709,8 @@ public class TelephonyManager {
* @hide
*/
@SystemApi
public static final String ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS
= "android.telephony.action.SHOW_NOTICE_ECM_BLOCK_OTHERS";
public static final String ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS =
"android.telephony.action.SHOW_NOTICE_ECM_BLOCK_OTHERS";
/**
* Broadcast Action: The default data subscription has changed in a multi-SIM device.
@@ -1696,8 +1723,8 @@ public class TelephonyManager {
*/
@SystemApi
@SuppressLint("ActionValue")
public static final String ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED
= "android.intent.action.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED";
public static final String ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED =
"android.intent.action.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED";
/**
* Broadcast Action: The default voice subscription has changed in a mult-SIm device.
@@ -1710,8 +1737,8 @@ public class TelephonyManager {
*/
@SystemApi
@SuppressLint("ActionValue")
public static final String ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED
= "android.intent.action.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED";
public static final String ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED =
"android.intent.action.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED";
/**
* Broadcast Action: This triggers a client initiated OMA-DM session to the OMA server.
@@ -1724,8 +1751,8 @@ public class TelephonyManager {
*/
@SystemApi
@SuppressLint("ActionValue")
public static final String ACTION_REQUEST_OMADM_CONFIGURATION_UPDATE
= "com.android.omadm.service.CONFIGURATION_UPDATE";
public static final String ACTION_REQUEST_OMADM_CONFIGURATION_UPDATE =
"com.android.omadm.service.CONFIGURATION_UPDATE";
//
//

View File

@@ -100,9 +100,6 @@ public class PhoneConstants {
public static final String DATA_APN_TYPE_KEY = "apnType";
public static final String DATA_APN_KEY = "apn";
public static final String PHONE_IN_ECM_STATE = "phoneinECMState";
public static final String PHONE_IN_EMERGENCY_CALL = "phoneInEmergencyCall";
/**
* Return codes for supplyPinReturnResult and
* supplyPukReturnResult APIs