use of com.android.internal.telephony.uicc.IccFileHandler in project android_frameworks_opt_telephony by LineageOS.
the class CatService method getInstance.
/**
* Used for instantiating the Service from the Card.
*
* @param ci CommandsInterface object
* @param context phone app context
* @param ic Icc card
* @param slotId to know the index of card
* @return The only Service object in the system
*/
public static CatService getInstance(CommandsInterface ci, Context context, UiccProfile uiccProfile, int slotId) {
UiccCardApplication ca = null;
IccFileHandler fh = null;
IccRecords ir = null;
if (uiccProfile != null) {
/* Since Cat is not tied to any application, but rather is Uicc application
* in itself - just get first FileHandler and IccRecords object
*/
ca = uiccProfile.getApplicationIndex(0);
if (ca != null) {
fh = ca.getIccFileHandler();
ir = ca.getIccRecords();
}
}
synchronized (sInstanceLock) {
if (sInstance == null) {
int simCount = TelephonyManager.getDefault().getSupportedModemCount();
sInstance = new CatService[simCount];
for (int i = 0; i < simCount; i++) {
sInstance[i] = null;
}
}
if (sInstance[slotId] == null) {
if (ci == null || ca == null || ir == null || context == null || fh == null || uiccProfile == null) {
return null;
}
sInstance[slotId] = new CatService(ci, ca, ir, context, fh, uiccProfile, slotId);
} else if ((ir != null) && (mIccRecords != ir)) {
if (mIccRecords != null) {
mIccRecords.unregisterForRecordsLoaded(sInstance[slotId]);
}
mIccRecords = ir;
mUiccApplication = ca;
mIccRecords.registerForRecordsLoaded(sInstance[slotId], MSG_ID_ICC_RECORDS_LOADED, null);
CatLog.d(sInstance[slotId], "registerForRecordsLoaded slotid=" + slotId + " instance:" + sInstance[slotId]);
}
return sInstance[slotId];
}
}
use of com.android.internal.telephony.uicc.IccFileHandler in project android_frameworks_opt_telephony by LineageOS.
the class IccSmsInterfaceManager method markMessagesAsRead.
protected void markMessagesAsRead(ArrayList<byte[]> messages) {
if (messages == null) {
return;
}
// IccFileHandler can be null, if icc card is absent.
IccFileHandler fh = mPhone.getIccFileHandler();
if (fh == null) {
// after importing it from icc.
if (Rlog.isLoggable("SMS", Log.DEBUG)) {
loge("markMessagesAsRead - aborting, no icc card present.");
}
return;
}
int count = messages.size();
for (int i = 0; i < count; i++) {
byte[] ba = messages.get(i);
if ((ba[0] & 0x07) == STATUS_ON_ICC_UNREAD) {
int n = ba.length;
byte[] nba = new byte[n - 1];
System.arraycopy(ba, 1, nba, 0, n - 1);
byte[] record = makeSmsRecordData(STATUS_ON_ICC_READ, nba);
fh.updateEFLinearFixed(IccConstants.EF_SMS, i + 1, record, null, null);
if (Rlog.isLoggable("SMS", Log.DEBUG)) {
log("SMS " + (i + 1) + " marked as read");
}
}
}
}
use of com.android.internal.telephony.uicc.IccFileHandler in project android_frameworks_opt_telephony by LineageOS.
the class IccSmsInterfaceManager method getAllMessagesFromIccEf.
/**
* Retrieves all messages currently stored on Icc.
*
* @return list of SmsRawData of all sms on Icc
*/
@UnsupportedAppUsage
public List<SmsRawData> getAllMessagesFromIccEf(String callingPackage) {
if (DBG)
log("getAllMessagesFromEF");
mContext.enforceCallingOrSelfPermission(Manifest.permission.RECEIVE_SMS, "Reading messages from Icc");
enforceAccessMessageOnICC("Reading messages from Icc");
enforceNotOnHandlerThread("getAllMessagesFromIccEf");
if (mAppOps.noteOp(AppOpsManager.OPSTR_READ_ICC_SMS, Binder.getCallingUid(), callingPackage) != AppOpsManager.MODE_ALLOWED) {
return new ArrayList<SmsRawData>();
}
synchronized (mLock) {
IccFileHandler fh = mPhone.getIccFileHandler();
if (fh == null) {
loge("Cannot load Sms records. No icc card?");
mSms = null;
return mSms;
}
Message response = mHandler.obtainMessage(EVENT_LOAD_DONE);
fh.loadEFLinearFixedAll(IccConstants.EF_SMS, response);
try {
mLock.wait();
} catch (InterruptedException e) {
loge("interrupted while trying to load from the Icc");
}
}
return mSms;
}
use of com.android.internal.telephony.uicc.IccFileHandler in project android_frameworks_opt_telephony by LineageOS.
the class IccSmsInterfaceManager method updateMessageOnIccEf.
/**
* Update the specified message on the Icc.
*
* @param index record index of message to update
* @param status new message status (STATUS_ON_ICC_READ,
* STATUS_ON_ICC_UNREAD, STATUS_ON_ICC_SENT,
* STATUS_ON_ICC_UNSENT, STATUS_ON_ICC_FREE)
* @param pdu the raw PDU to store
* @return success or not
*/
@UnsupportedAppUsage
public boolean updateMessageOnIccEf(String callingPackage, int index, int status, byte[] pdu) {
if (DBG)
log("updateMessageOnIccEf: index=" + index + " status=" + status + " ==> " + "(" + Arrays.toString(pdu) + ")");
enforceReceiveAndSend("Updating message on Icc");
enforceAccessMessageOnICC("Updating message on Icc");
enforceNotOnHandlerThread("updateMessageOnIccEf");
if (mAppOps.noteOp(AppOpsManager.OPSTR_WRITE_ICC_SMS, Binder.getCallingUid(), callingPackage) != AppOpsManager.MODE_ALLOWED) {
return false;
}
synchronized (mLock) {
mSuccess = false;
Message response = mHandler.obtainMessage(EVENT_UPDATE_DONE);
if ((status & 0x01) == STATUS_ON_ICC_FREE) {
// Will eventually fail if icc card is not present.
if (PhoneConstants.PHONE_TYPE_GSM == mPhone.getPhoneType()) {
mPhone.mCi.deleteSmsOnSim(index, response);
} else {
mPhone.mCi.deleteSmsOnRuim(index, response);
}
} else {
// IccFilehandler can be null if ICC card is not present.
IccFileHandler fh = mPhone.getIccFileHandler();
if (fh == null) {
response.recycle();
return mSuccess;
/* is false */
}
byte[] record = makeSmsRecordData(status, pdu);
fh.updateEFLinearFixed(IccConstants.EF_SMS, index, record, null, response);
}
try {
mLock.wait();
} catch (InterruptedException e) {
loge("interrupted while trying to update by index");
}
}
return mSuccess;
}
use of com.android.internal.telephony.uicc.IccFileHandler in project android_frameworks_opt_telephony by LineageOS.
the class CatService method getInstance.
/**
* Used for instantiating the Service from the Card.
*
* @param ci CommandsInterface object
* @param context phone app context
* @param ic Icc card
* @param slotId to know the index of card
* @return The only Service object in the system
*/
public static CatService getInstance(CommandsInterface ci, Context context, UiccCard ic, int slotId) {
UiccCardApplication ca = null;
IccFileHandler fh = null;
IccRecords ir = null;
if (ic != null) {
/* Since Cat is not tied to any application, but rather is Uicc application
* in itself - just get first FileHandler and IccRecords object
*/
ca = ic.getApplicationIndex(0);
if (ca != null) {
fh = ca.getIccFileHandler();
ir = ca.getIccRecords();
}
}
synchronized (sInstanceLock) {
if (sInstance == null) {
int simCount = TelephonyManager.getDefault().getSimCount();
sInstance = new CatService[simCount];
for (int i = 0; i < simCount; i++) {
sInstance[i] = null;
}
}
if (sInstance[slotId] == null) {
if (ci == null || ca == null || ir == null || context == null || fh == null || ic == null) {
return null;
}
sInstance[slotId] = new CatService(ci, ca, ir, context, fh, ic, slotId);
} else if ((ir != null) && (mIccRecords != ir)) {
if (mIccRecords != null) {
mIccRecords.unregisterForRecordsLoaded(sInstance[slotId]);
}
mIccRecords = ir;
mUiccApplication = ca;
mIccRecords.registerForRecordsLoaded(sInstance[slotId], MSG_ID_ICC_RECORDS_LOADED, null);
CatLog.d(sInstance[slotId], "registerForRecordsLoaded slotid=" + slotId + " instance:" + sInstance[slotId]);
}
return sInstance[slotId];
}
}
Aggregations