use of com.android.internal.telephony.uicc.UiccCard in project android_frameworks_opt_telephony by LineageOS.
the class PhoneSubInfoController method enforcePrivilegedPermissionOrCarrierPrivilege.
/**
* Make sure caller has either read privileged phone permission or carrier privilege.
*
* @throws SecurityException if the caller does not have the required permission/privilege
*/
private void enforcePrivilegedPermissionOrCarrierPrivilege(Phone phone) {
int permissionResult = mContext.checkCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE);
if (permissionResult == PackageManager.PERMISSION_GRANTED) {
return;
}
log("No read privileged phone permission, check carrier privilege next.");
UiccCard uiccCard = phone.getUiccCard();
if (uiccCard == null) {
throw new SecurityException("No Carrier Privilege: No UICC");
}
if (uiccCard.getCarrierPrivilegeStatusForCurrentTransaction(mContext.getPackageManager()) != CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
throw new SecurityException("No Carrier Privilege.");
}
}
use of com.android.internal.telephony.uicc.UiccCard in project android_frameworks_opt_telephony by LineageOS.
the class PhoneSubInfoController method getIccSimChallengeResponse.
public String getIccSimChallengeResponse(int subId, int appType, int authType, String data) throws RemoteException {
Phone phone = getPhone(subId);
enforcePrivilegedPermissionOrCarrierPrivilege(phone);
UiccCard uiccCard = phone.getUiccCard();
if (uiccCard == null) {
loge("getIccSimChallengeResponse() UiccCard is null");
return null;
}
UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
if (uiccApp == null) {
loge("getIccSimChallengeResponse() no app with specified type -- " + appType);
return null;
} else {
loge("getIccSimChallengeResponse() found app " + uiccApp.getAid() + " specified type -- " + appType);
}
if (authType != UiccCardApplication.AUTH_CONTEXT_EAP_SIM && authType != UiccCardApplication.AUTH_CONTEXT_EAP_AKA) {
loge("getIccSimChallengeResponse() unsupported authType: " + authType);
return null;
}
return uiccApp.getIccRecords().getIccSimChallengeResponse(authType, data);
}
use of com.android.internal.telephony.uicc.UiccCard in project android_frameworks_opt_telephony by LineageOS.
the class GsmCdmaPhone method setOperatorBrandOverride.
@Override
public boolean setOperatorBrandOverride(String brand) {
if (mUiccController == null) {
return false;
}
UiccCard card = mUiccController.getUiccCard(getPhoneId());
if (card == null) {
return false;
}
boolean status = card.setOperatorBrandOverride(brand);
// Refresh.
if (status) {
TelephonyManager.from(mContext).setSimOperatorNameForPhone(getPhoneId(), mSST.getServiceProviderName());
// TODO: check if pollState is need when set operator brand override.
mSST.pollState();
}
return status;
}
use of com.android.internal.telephony.uicc.UiccCard in project android_frameworks_opt_telephony by LineageOS.
the class SubscriptionController method addSubInfo.
/**
* Add a new subscription info record, if needed.
* @param uniqueId This is the unique identifier for the subscription within the specific
* subscription type.
* @param displayName human-readable name of the device the subscription corresponds to.
* @param slotIndex value for {@link SubscriptionManager#SIM_SLOT_INDEX}
* @param subscriptionType the type of subscription to be added.
* @return 0 if success, < 0 on error.
*/
@Override
public int addSubInfo(String uniqueId, String displayName, int slotIndex, int subscriptionType) {
if (DBG) {
String iccIdStr = uniqueId;
if (!isSubscriptionForRemoteSim(subscriptionType)) {
iccIdStr = SubscriptionInfo.givePrintableIccid(uniqueId);
}
logdl("[addSubInfoRecord]+ iccid: " + iccIdStr + ", slotIndex: " + slotIndex + ", subscriptionType: " + subscriptionType);
}
enforceModifyPhoneState("addSubInfo");
// Now that all security checks passes, perform the operation as ourselves.
final long identity = Binder.clearCallingIdentity();
try {
if (uniqueId == null) {
if (DBG)
logdl("[addSubInfo]- null iccId");
return -1;
}
ContentResolver resolver = mContext.getContentResolver();
String selection = SubscriptionManager.ICC_ID + "=?";
String[] args;
if (isSubscriptionForRemoteSim(subscriptionType)) {
selection += " AND " + SubscriptionManager.SUBSCRIPTION_TYPE + "=?";
args = new String[] { uniqueId, Integer.toString(subscriptionType) };
} else {
selection += " OR " + SubscriptionManager.ICC_ID + "=?";
args = new String[] { uniqueId, IccUtils.getDecimalSubstring(uniqueId) };
}
Cursor cursor = resolver.query(SubscriptionManager.CONTENT_URI, new String[] { SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID, SubscriptionManager.SIM_SLOT_INDEX, SubscriptionManager.NAME_SOURCE, SubscriptionManager.ICC_ID, SubscriptionManager.CARD_ID }, selection, args, null);
boolean setDisplayName = false;
try {
boolean recordsDoNotExist = (cursor == null || !cursor.moveToFirst());
if (isSubscriptionForRemoteSim(subscriptionType)) {
if (recordsDoNotExist) {
// create a Subscription record
slotIndex = SubscriptionManager.SLOT_INDEX_FOR_REMOTE_SIM_SUB;
Uri uri = insertEmptySubInfoRecord(uniqueId, displayName, slotIndex, subscriptionType);
if (DBG)
logd("[addSubInfoRecord] New record created: " + uri);
} else {
if (DBG)
logdl("[addSubInfoRecord] Record already exists");
}
} else {
// Handle Local SIM devices
if (recordsDoNotExist) {
setDisplayName = true;
Uri uri = insertEmptySubInfoRecord(uniqueId, slotIndex);
if (DBG)
logdl("[addSubInfoRecord] New record created: " + uri);
} else {
// there are matching records in the database for the given ICC_ID
int subId = cursor.getInt(0);
int oldSimInfoId = cursor.getInt(1);
int nameSource = cursor.getInt(2);
String oldIccId = cursor.getString(3);
String oldCardId = cursor.getString(4);
ContentValues value = new ContentValues();
if (slotIndex != oldSimInfoId) {
value.put(SubscriptionManager.SIM_SLOT_INDEX, slotIndex);
}
if (oldIccId != null && oldIccId.length() < uniqueId.length() && (oldIccId.equals(IccUtils.getDecimalSubstring(uniqueId)))) {
value.put(SubscriptionManager.ICC_ID, uniqueId);
}
UiccCard card = mUiccController.getUiccCardForPhone(slotIndex);
if (card != null) {
String cardId = card.getCardId();
if (cardId != null && cardId != oldCardId) {
value.put(SubscriptionManager.CARD_ID, cardId);
}
}
if (value.size() > 0) {
resolver.update(SubscriptionManager.getUriForSubscriptionId(subId), value, null, null);
}
if (DBG)
logdl("[addSubInfoRecord] Record already exists");
}
}
} finally {
if (cursor != null) {
cursor.close();
}
}
selection = SubscriptionManager.SIM_SLOT_INDEX + "=?";
args = new String[] { String.valueOf(slotIndex) };
if (isSubscriptionForRemoteSim(subscriptionType)) {
selection = SubscriptionManager.ICC_ID + "=? AND " + SubscriptionManager.SUBSCRIPTION_TYPE + "=?";
args = new String[] { uniqueId, Integer.toString(subscriptionType) };
}
cursor = resolver.query(SubscriptionManager.CONTENT_URI, null, selection, args, null);
try {
if (cursor != null && cursor.moveToFirst()) {
do {
int subId = cursor.getInt(cursor.getColumnIndexOrThrow(SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID));
// do not add it.
if (addToSubIdList(slotIndex, subId, subscriptionType)) {
// TODO While two subs active, if user deactivats first
// one, need to update the default subId with second one.
// FIXME: Currently we assume phoneId == slotIndex which in the future
// may not be true, for instance with multiple subs per slot.
// But is true at the moment.
int subIdCountMax = getActiveSubInfoCountMax();
int defaultSubId = getDefaultSubId();
if (DBG) {
logdl("[addSubInfoRecord]" + " sSlotIndexToSubIds.size=" + sSlotIndexToSubIds.size() + " slotIndex=" + slotIndex + " subId=" + subId + " defaultSubId=" + defaultSubId + " simCount=" + subIdCountMax);
}
// Set the default sub if not set or if single sim device
if (!isSubscriptionForRemoteSim(subscriptionType)) {
if (!SubscriptionManager.isValidSubscriptionId(defaultSubId) || subIdCountMax == 1) {
logdl("setting default fallback subid to " + subId);
setDefaultFallbackSubId(subId, subscriptionType);
}
// everything
if (subIdCountMax == 1) {
if (DBG) {
logdl("[addSubInfoRecord] one sim set defaults to subId=" + subId);
}
setDefaultDataSubId(subId);
setDefaultSmsSubId(subId);
setDefaultVoiceSubId(subId);
}
} else {
updateDefaultSubIdsIfNeeded(subId, subscriptionType);
}
} else {
if (DBG) {
logdl("[addSubInfoRecord] current SubId is already known, " + "IGNORE");
}
}
if (DBG) {
logdl("[addSubInfoRecord] hashmap(" + slotIndex + "," + subId + ")");
}
} while (cursor.moveToNext());
}
} finally {
if (cursor != null) {
cursor.close();
}
}
// Refresh the Cache of Active Subscription Info List. This should be done after
// updating sSlotIndexToSubIds which is done through addToSubIdList() above.
refreshCachedActiveSubscriptionInfoList();
if (isSubscriptionForRemoteSim(subscriptionType)) {
notifySubscriptionInfoChanged();
} else {
// Handle Local SIM devices
// Set Display name after sub id is set above so as to get valid simCarrierName
int subId = getSubIdUsingPhoneId(slotIndex);
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
if (DBG) {
logdl("[addSubInfoRecord]- getSubId failed invalid subId = " + subId);
}
return -1;
}
if (setDisplayName) {
String simCarrierName = mTelephonyManager.getSimOperatorName(subId);
String nameToSet;
if (!TextUtils.isEmpty(simCarrierName)) {
nameToSet = simCarrierName;
} else {
nameToSet = "CARD " + Integer.toString(slotIndex + 1);
}
ContentValues value = new ContentValues();
value.put(SubscriptionManager.DISPLAY_NAME, nameToSet);
resolver.update(SubscriptionManager.getUriForSubscriptionId(subId), value, null, null);
// Refresh the Cache of Active Subscription Info List
refreshCachedActiveSubscriptionInfoList();
if (DBG)
logdl("[addSubInfoRecord] sim name = " + nameToSet);
}
if (DBG)
logdl("[addSubInfoRecord]- info size=" + sSlotIndexToSubIds.size());
}
} finally {
Binder.restoreCallingIdentity(identity);
}
return 0;
}
use of com.android.internal.telephony.uicc.UiccCard in project android_frameworks_opt_telephony by LineageOS.
the class CatService method updateIccAvailability.
void updateIccAvailability() {
if (null == mUiccController) {
return;
}
CardState newState = CardState.CARDSTATE_ABSENT;
UiccCard newCard = mUiccController.getUiccCard(mSlotId);
if (newCard != null) {
newState = newCard.getCardState();
}
CardState oldState = mCardState;
mCardState = newState;
CatLog.d(this, "New Card State = " + newState + " " + "Old Card State = " + oldState);
if (oldState == CardState.CARDSTATE_PRESENT && newState != CardState.CARDSTATE_PRESENT) {
broadcastCardStateAndIccRefreshResp(newState, null);
} else if (oldState != CardState.CARDSTATE_PRESENT && newState == CardState.CARDSTATE_PRESENT) {
// Card moved to PRESENT STATE.
mCmdIf.reportStkServiceIsRunning(null);
}
}
Aggregations