/** @hide */
public static final int CDMA_ROAMING_MODE_AFFILIATED = 1;
/** @hide */
- public static final int IMSI_ENCRYPTION_DAYS_TIME_DISABLED = -1;
- /** @hide */
public static final int CDMA_ROAMING_MODE_ANY = 2;
/**
* Boolean indicating if support is provided for directly dialing FDN number from FDN list.
public static final String IMSI_KEY_DOWNLOAD_URL_STRING = "imsi_key_download_url_string";
/**
- * Time in days, after which the key will expire, and a new key will need to be downloaded.
- * default value is {@link IMSI_ENCRYPTION_DAYS_TIME_DISABLED}, and indicates that IMSI
- * encryption is not enabled by default for a carrier. Value of 0 indicates that the key
- * does not expire.
+ * Identifies if the key is available for WLAN or EPDG or both. The value is a bitmask.
+ * 0 indicates that neither EPDG or WLAN is enabled.
+ * 1 indicates that key type {@link TelephonyManager#KEY_TYPE_EPDG} is enabled.
+ * 2 indicates that key type {@link TelephonyManager#KEY_TYPE_WLAN} is enabled.
+ * 3 indicates that both are enabled.
* @hide
*/
- public static final String IMSI_KEY_EXPIRATION_DAYS_TIME_INT =
- "imsi_key_expiration_days_time_int";
+ public static final String IMSI_KEY_AVAILABILITY_INT = "imsi_key_availability_int";
+
/**
* Key identifying if the CDMA Caller ID presentation and suppression MMI codes
sDefaults.putInt(KEY_LTE_EARFCNS_RSRP_BOOST_INT, 0);
sDefaults.putStringArray(KEY_BOOSTED_LTE_EARFCNS_STRING_ARRAY, null);
sDefaults.putBoolean(KEY_DISABLE_VOICE_BARRING_NOTIFICATION_BOOL, false);
- sDefaults.putInt(IMSI_KEY_EXPIRATION_DAYS_TIME_INT, IMSI_ENCRYPTION_DAYS_TIME_DISABLED);
+ sDefaults.putInt(IMSI_KEY_AVAILABILITY_INT, 0);
sDefaults.putString(IMSI_KEY_DOWNLOAD_URL_STRING, null);
sDefaults.putBoolean(KEY_CONVERT_CDMA_CALLER_ID_MMI_CODES_WHILE_ROAMING_ON_3GPP_BOOL,
false);
/** @hide */
- static public final int KEY_TYPE_EPDDG = 1;
+ static public final int KEY_TYPE_EPDG = 1;
/** @hide */
static public final int KEY_TYPE_WLAN = 2;
* Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
* @param keyType whether the key is being used for wlan or epdg. Valid key types are
- * {@link TelephonyManager#KEY_TYPE_EPDDG} or
+ * {@link TelephonyManager#KEY_TYPE_EPDG} or
* {@link TelephonyManager#KEY_TYPE_WLAN}.
* @return ImsiEncryptionInfo Carrier specific information that will be used to encrypt the
* IMSI and IMPI. This includes the public key and the key identifier. This information
- * will be stored in the device keystore.
+ * will be stored in the device keystore. The system will return a null when no key was
+ * found, and the carrier does not require a key. The system will throw the following
+ * exceptions:
+ * 1. IllegalArgumentException when an invalid key is sent.
+ * 2. RuntimeException if the key is required but not found; and also if there was an
+ * internal exception.
* @hide
*/
public ImsiEncryptionInfo getCarrierInfoForImsiEncryption(int keyType) {
try {
IPhoneSubInfo info = getSubscriberInfo();
- if (info == null) return null;
+ if (info == null) {
+ throw new RuntimeException("IMSI error: Subscriber Info is null");
+ }
int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId());
- if (keyType != KEY_TYPE_EPDDG && keyType != KEY_TYPE_WLAN) {
- throw new IllegalArgumentException("Invalid key type");
+ if (keyType != KEY_TYPE_EPDG && keyType != KEY_TYPE_WLAN) {
+ throw new IllegalArgumentException("IMSI error: Invalid key type");
+ }
+ ImsiEncryptionInfo imsiEncryptionInfo = info.getCarrierInfoForImsiEncryption(
+ subId, keyType, mContext.getOpPackageName());
+ if (imsiEncryptionInfo == null
+ && isImsiEncryptionRequired(subId, keyType)) {
+ Rlog.e(TAG, "IMSI error: key is required but not found");
+ throw new RuntimeException("IMSI error: key is required but not found");
}
- return info.getCarrierInfoForImsiEncryption(subId, keyType,
- mContext.getOpPackageName());
+ return imsiEncryptionInfo;
} catch (RemoteException ex) {
- Rlog.e(TAG, "getCarrierInfoForImsiEncryption RemoteException", ex);
- return null;
+ Rlog.e(TAG, "getCarrierInfoForImsiEncryption RemoteException" + ex);
+ throw new RuntimeException("IMSI error: Remote Exception");
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
- Rlog.e(TAG, "getCarrierInfoForImsiEncryption NullPointerException", ex);
- return null;
+ Rlog.e(TAG, "getCarrierInfoForImsiEncryption NullPointerException" + ex);
+ throw new RuntimeException("IMSI error: Null Pointer exception");
+ }
+ }
+
+ /**
+ * @param keyAvailability bitmask that defines the availabilty of keys for a type.
+ * @param keyType the key type which is being checked. (WLAN, EPDG)
+ * @return true if the digit at position keyType is 1, else false.
+ * @hide
+ */
+ private static boolean isKeyEnabled(int keyAvailability, int keyType) {
+ int returnValue = (keyAvailability >> (keyType - 1)) & 1;
+ return (returnValue == 1) ? true : false;
+ }
+
+ /**
+ * If Carrier requires Imsi to be encrypted.
+ * @hide
+ */
+ private boolean isImsiEncryptionRequired(int subId, int keyType) {
+ CarrierConfigManager configManager =
+ (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
+ if (configManager == null) {
+ return false;
+ }
+ PersistableBundle pb = configManager.getConfigForSubId(subId);
+ if (pb == null) {
+ return false;
}
+ int keyAvailability = pb.getInt(CarrierConfigManager.IMSI_KEY_AVAILABILITY_INT);
+ return isKeyEnabled(keyAvailability, keyType);
}
/**