pinLockedSubscriptionIdsBuilder = ImmutableList.builder();
for (int subscriptionId : subscriptionIds) {
if (telephonyManager.createForSubscriptionId(subscriptionId).isIccLockEnabled()) {
pinLockedSubscriptionIdsBuilder.add(subscriptionId);
}
}
return pinLockedSubscriptionIdsBuilder.build();
}
/**
* Returns true, if SIM PIN storage is enabled.
*
* The SIM PIN storage might be disabled by OEM or by carrier, subscription (SIM) Id is
* required when checking if the corresponding SIM PIN storage is disabled by the carrier.
*
*
Both the OEM and carrier enable SIM PIN storage by default. If fails to read the OEM/carrier
* configs, it assume SIM PIN storage is enabled.
*/
private static boolean isSimPinStorageEnabled(
Context context, ImmutableList pinLockedSubscriptionIds) {
if (!isSystemEnableSimPin()) {
return false;
}
// If the carrier enables SIM PIN.
CarrierConfigManager carrierConfigManager =
context.getSystemService(CarrierConfigManager.class);
if (carrierConfigManager == null) {
Log.w(TAG, "CarrierConfigManager is null");
return true;
}
for (int pinLockedSubscriptionId : pinLockedSubscriptionIds) {
PersistableBundle subscriptionConfig =
carrierConfigManager.getConfigForSubId(
pinLockedSubscriptionId, CARRIER_ENABLE_SIM_PIN_STORAGE_KEY);
// Only disable if carrier explicitly disables sim pin storage.
if (!subscriptionConfig.isEmpty()
&& !subscriptionConfig.getBoolean(
CARRIER_ENABLE_SIM_PIN_STORAGE_KEY, /* defaultValue= */ true)) {
Log.w(
TAG,
"The carrier disables SIM PIN storage on subscription ID " + pinLockedSubscriptionId);
return false;
}
}
Log.v(TAG, "SIM PIN Storage is enabled");
return true;
}
private static boolean isSystemEnableSimPin() {
try {
boolean value =
Resources.getSystem()
.getBoolean(
Resources.getSystem()
.getIdentifier(
SYSTEM_ENABLE_SIM_PIN_STORAGE_KEY,
/* defType= */ "bool",
/* defPackage= */ "android"));
Log.i(TAG, SYSTEM_ENABLE_SIM_PIN_STORAGE_KEY + " = " + value);
return value;
} catch (Resources.NotFoundException e) {
Log.e(TAG, "Could not read system resource value ," + SYSTEM_ENABLE_SIM_PIN_STORAGE_KEY);
// When not explicitly disabled, assume SIM PIN storage functions properly.
return true;
}
}
}