From 1554a1714e55ecab70a69384a5578502b6c45cab Mon Sep 17 00:00:00 2001 From: Adnan Begovic Date: Tue, 25 Nov 2014 07:41:06 -0600 Subject: Telephony: Fall back on deprecated createFromPdu. Since some of our legacy cdma devices utilizes legacy RIL blobs and hacky implementations, we can't wholly rely on getting a correct format from the InboundSmsTracker. Thus we fallback on the deprecated createFromPdu which attempts to guess the format of the SmsMessage by looking at the voice tech and falling back to the other format if it's incorrect. Change-Id: I90dc185071de827510f2bcec1c837c0024182c41 --- src/java/android/provider/Telephony.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/java/android/provider/Telephony.java b/src/java/android/provider/Telephony.java index b76c5f11a..46780156f 100755 --- a/src/java/android/provider/Telephony.java +++ b/src/java/android/provider/Telephony.java @@ -1164,6 +1164,18 @@ public final class Telephony { for (int i = 0; i < pduCount; i++) { byte[] pdu = (byte[]) pdus[i]; msgs[i] = SmsMessage.createFromPdu(pdu, format); + // If the originating address is null on our message + // then the format for SmsMessage createFromPdu is likely + // incorrect. SmsMessage createFromPdu(the new method) + // takes in a format parameter that it gets from the Tracker + // however, on some of our legacy devices using a legacy ril, + // since that format is derived by getting voice tech, + // we can get a bad format and no valid members. + // Thus we introduce a hack that utilizes the deprecated + // SmsMessage.createFromPdu if we get a null originating address. + if (msgs[i].getOriginatingAddress() == null) { + msgs[i] = SmsMessage.createFromPdu(pdu); + } String originatingAddress = msgs[i].getOriginatingAddress(); if (!TextUtils.isEmpty(originatingAddress)) { String normalized = normalizeDigitsOnly(originatingAddress); -- cgit v1.2.3 From 023e93eec9f7f6c91fc2fa8b54a1b66c91567b20 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Mon, 1 Dec 2014 16:11:32 -0800 Subject: Telephony: Find creator package if sms is sent from systemuid. Change-Id: I72a8e479eab903a8354b5a3eb5aaf11a41570294 --- .../android/internal/telephony/SMSDispatcher.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/java/com/android/internal/telephony/SMSDispatcher.java b/src/java/com/android/internal/telephony/SMSDispatcher.java index 9dee86342..3ae3de5e2 100644 --- a/src/java/com/android/internal/telephony/SMSDispatcher.java +++ b/src/java/com/android/internal/telephony/SMSDispatcher.java @@ -38,6 +38,7 @@ import android.os.AsyncResult; import android.os.Binder; import android.os.Handler; import android.os.Message; +import android.os.Process; import android.os.SystemProperties; import android.provider.Settings; import android.provider.Telephony; @@ -331,6 +332,16 @@ public abstract class SMSDispatcher extends Handler { } } + private static boolean isSystemUid(Context context, String pkgName) { + final PackageManager packageManager = context.getPackageManager(); + try { + return packageManager.getPackageInfo(pkgName, 0) + .applicationInfo.uid == Process.SYSTEM_UID; + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } + /** * Called when SMS send completes. Broadcasts a sentIntent on success. * On failure, either sets up retries or broadcasts a sentIntent with @@ -353,8 +364,16 @@ public abstract class SMSDispatcher extends Handler { if (ar.exception == null) { if (DBG) Rlog.d(TAG, "SMS send complete. Broadcasting intent: " + sentIntent); + String packageName = tracker.mAppInfo.applicationInfo.packageName; + // System UID maps to multiple packages. Try to narrow it + // down to an actual sender if possible + if (isSystemUid(mContext, packageName) && sentIntent != null && + sentIntent.getCreatorPackage() != null) { + packageName = sentIntent.getCreatorPackage(); + } + if (SmsApplication.shouldWriteMessageForPackage( - tracker.mAppInfo.applicationInfo.packageName, mContext)) { + packageName, mContext)) { // Persist it into the SMS database as a sent message // so the user can see it in their default app. tracker.writeSentMessage(mContext); -- cgit v1.2.3 From 9e7b80a78a156b729e6fe92636494d900404d138 Mon Sep 17 00:00:00 2001 From: Adnan Date: Mon, 8 Dec 2014 10:39:37 -0800 Subject: Telephony: Always allow ignored sms packages for premium sms. Also clean up redundant code by creating a new method (resolvePackageName). Change-Id: I14eafe2c1ae007c1a8d9c1270a832a2c92f3a04e --- .../android/internal/telephony/SMSDispatcher.java | 38 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/java/com/android/internal/telephony/SMSDispatcher.java b/src/java/com/android/internal/telephony/SMSDispatcher.java index 3ae3de5e2..70aa7e97c 100644 --- a/src/java/com/android/internal/telephony/SMSDispatcher.java +++ b/src/java/com/android/internal/telephony/SMSDispatcher.java @@ -64,7 +64,9 @@ import com.android.internal.telephony.GsmAlphabet.TextEncodingDetails; import com.android.internal.telephony.ImsSMSDispatcher; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; @@ -364,13 +366,7 @@ public abstract class SMSDispatcher extends Handler { if (ar.exception == null) { if (DBG) Rlog.d(TAG, "SMS send complete. Broadcasting intent: " + sentIntent); - String packageName = tracker.mAppInfo.applicationInfo.packageName; - // System UID maps to multiple packages. Try to narrow it - // down to an actual sender if possible - if (isSystemUid(mContext, packageName) && sentIntent != null && - sentIntent.getCreatorPackage() != null) { - packageName = sentIntent.getCreatorPackage(); - } + String packageName = resolvePackageName(tracker); if (SmsApplication.shouldWriteMessageForPackage( packageName, mContext)) { @@ -820,6 +816,15 @@ public abstract class SMSDispatcher extends Handler { * @return true if the destination is approved; false if user confirmation event was sent */ boolean checkDestination(SmsTracker tracker) { + List ignorePackages = Arrays.asList( + mContext.getResources().getStringArray(R.array.config_ignored_sms_packages)); + + String packageName = resolvePackageName(tracker); + + if (ignorePackages.contains(packageName)) { + return true; + } + if (mContext.checkCallingOrSelfPermission(SEND_SMS_NO_CONFIRMATION_PERMISSION) == PackageManager.PERMISSION_GRANTED) { return true; // app is pre-approved to send to short codes @@ -922,6 +927,25 @@ public abstract class SMSDispatcher extends Handler { } } + /** + * Returns the package name from the original creator of the sms, even + * if the package is mapped with others in a specific UID (like System UID) + * + * @param tracker + * @return the package name that created the original sms + */ + private String resolvePackageName(SmsTracker tracker) { + PendingIntent sentIntent = tracker.mSentIntent; + String packageName = tracker.mAppInfo.applicationInfo.packageName; + // System UID maps to multiple packages. Try to narrow it + // down to an actual sender if possible + if (isSystemUid(mContext, packageName) && sentIntent != null && + sentIntent.getCreatorPackage() != null) { + packageName = sentIntent.getCreatorPackage(); + } + return packageName; + } + /** * Post an alert when SMS needs confirmation due to excessive usage. * @param tracker an SmsTracker for the current message. -- cgit v1.2.3 From 9e20514b298ee1cdf909084c9d1a56e8663d132a Mon Sep 17 00:00:00 2001 From: Ian Roy Date: Wed, 3 Dec 2014 15:47:38 -0500 Subject: Store correct IMSI when retreived from SIMRecords and use it for RuimRecords Stock stores the IMSI gathered with SIMRecords and uses that value when RuimRecords wants to get the APN/operator number. Set System prop "ro.telephony.get_imsi_from_sim=true" to enable this function Change-Id: I5e766951313afe4dedb0b6bccfdc83acf701f440 --- .../internal/telephony/uicc/RuimRecords.java | 13 ++++ .../internal/telephony/uicc/SIMRecords.java | 14 ++++ .../internal/telephony/uicc/UICCConfig.java | 87 ++++++++++++++++++++++ .../android/internal/telephony/uicc/UiccCard.java | 8 ++ .../telephony/uicc/UiccCardApplication.java | 5 ++ 5 files changed, 127 insertions(+) create mode 100644 src/java/com/android/internal/telephony/uicc/UICCConfig.java diff --git a/src/java/com/android/internal/telephony/uicc/RuimRecords.java b/src/java/com/android/internal/telephony/uicc/RuimRecords.java index 7da53d4e5..2e77d864e 100644 --- a/src/java/com/android/internal/telephony/uicc/RuimRecords.java +++ b/src/java/com/android/internal/telephony/uicc/RuimRecords.java @@ -43,6 +43,7 @@ import com.android.internal.telephony.MccTable; import com.android.internal.telephony.cdma.sms.UserData; import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppState; +import com.android.internal.telephony.uicc.UICCConfig; /** @@ -253,6 +254,18 @@ public final class RuimRecords extends IccRecords { return null; } + if (SystemProperties.getBoolean("ro.telephony.get_imsi_from_sim", false)) { + String imsi = mParentApp.getUICCConfig().getImsi(); + int mnclength = mParentApp.getUICCConfig().getMncLength(); + + // If we are LTE over CDMA (Verizon), then pull the correct info from SIMRecords + if (imsi != null) { + log("Overriding with Operator Numeric: " + imsi.substring(0, 3 + mnclength)); + return imsi.substring(0, 3 + mnclength); + } + } + + if (mMncLength != UNINITIALIZED && mMncLength != UNKNOWN) { // Length = length of MCC + length of MNC // length of mcc = 3 (3GPP2 C.S0005 - Section 2.3) diff --git a/src/java/com/android/internal/telephony/uicc/SIMRecords.java b/src/java/com/android/internal/telephony/uicc/SIMRecords.java index 88181ba27..4cf5c93c3 100644 --- a/src/java/com/android/internal/telephony/uicc/SIMRecords.java +++ b/src/java/com/android/internal/telephony/uicc/SIMRecords.java @@ -37,6 +37,7 @@ import com.android.internal.telephony.MccTable; import com.android.internal.telephony.SmsConstants; import com.android.internal.telephony.gsm.SimTlv; import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; +import com.android.internal.telephony.uicc.UICCConfig; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -240,6 +241,8 @@ public class SIMRecords extends IccRecords { setSystemProperty(PROPERTY_APN_SIM_OPERATOR_NUMERIC, null); setSystemProperty(PROPERTY_ICC_OPERATOR_ALPHA, null); setSystemProperty(PROPERTY_ICC_OPERATOR_ISO_COUNTRY, null); + mParentApp.getUICCConfig().setImsi(mImsi); + mParentApp.getUICCConfig().setMncLength(mMncLength); // recordsRequested is set to false indicating that the SIM // read requests made so far are not valid. This is set to @@ -660,6 +663,14 @@ public class SIMRecords extends IccRecords { } } + mParentApp.getUICCConfig().setImsi(mImsi); + if (mMncLength == UNKNOWN || mMncLength == UNINITIALIZED) { + // We need to default to something that seems common + mParentApp.getUICCConfig().setMncLength(3); + } else { + mParentApp.getUICCConfig().setMncLength(mMncLength); + } + if (mMncLength != UNKNOWN && mMncLength != UNINITIALIZED) { // finally have both the imsi and the mncLength and can parse the imsi properly MccTable.updateMccMncConfiguration(mContext, @@ -872,7 +883,10 @@ public class SIMRecords extends IccRecords { if (mMncLength == 0xf) { mMncLength = UNKNOWN; + } else { + mParentApp.getUICCConfig().setMncLength(mMncLength); } + } finally { if (((mMncLength == UNINITIALIZED) || (mMncLength == UNKNOWN) || (mMncLength == 2)) && ((mImsi != null) && (mImsi.length() >= 6))) { diff --git a/src/java/com/android/internal/telephony/uicc/UICCConfig.java b/src/java/com/android/internal/telephony/uicc/UICCConfig.java new file mode 100644 index 000000000..768ec14b4 --- /dev/null +++ b/src/java/com/android/internal/telephony/uicc/UICCConfig.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2014 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.telephony.uicc; + +import android.content.Context; +import android.content.SharedPreferences; +import android.telephony.Rlog; + +/** + * A class that stores various UICC Settings/values. + * @hide + */ +public final class UICCConfig +{ + private final String PREFERENCE_NAME = "UICCConfig"; + private final String TAG = "UICCConfig"; + private final boolean LOG_DEBUG = false; + + private String mImsi; + private int mMncLength; + + /** + * A method to get the stored Imsi. + * @hide + */ + public String getImsi() { + if (mImsi == null) { + logd("Getting IMSI: null"); + } else { + logd("Getting IMSI: " + mImsi); + } + return mImsi; + } + + /** + * A method to set the stored Imsi. + * @hide + */ + public void setImsi(String lImsi) { + logd("Setting IMSI: " + lImsi); + mImsi = lImsi; + } + + /** + * A method to get the stored MncLength. + * @hide + */ + public int getMncLength() { + logd("Getting MncLength: " + Integer.toString(mMncLength)); + return mMncLength; + } + + /** + * A method to set the stored MncLength. + * @hide + */ + public void setMncLength(int lMncLength) { + logd("Setting MncLength: " + Integer.toString(lMncLength)); + mMncLength = lMncLength; + } + + private void logd(String sLog) { + if (LOG_DEBUG) { + Rlog.d(TAG, sLog); + } + } + + private void loge(String sLog) + { + Rlog.e(TAG, sLog); + } + +} \ No newline at end of file diff --git a/src/java/com/android/internal/telephony/uicc/UiccCard.java b/src/java/com/android/internal/telephony/uicc/UiccCard.java index 359658c7d..7d603f1e8 100644 --- a/src/java/com/android/internal/telephony/uicc/UiccCard.java +++ b/src/java/com/android/internal/telephony/uicc/UiccCard.java @@ -74,6 +74,7 @@ public class UiccCard { protected CatService mCatService; private boolean mDestroyed = false; //set to true once this card is commanded to be disposed of. private RadioState mLastRadioState = RadioState.RADIO_UNAVAILABLE; + private UICCConfig mUICCConfig = null; private RegistrantList mAbsentRegistrants = new RegistrantList(); @@ -100,6 +101,7 @@ public class UiccCard { } mCatService = null; mUiccApplications = null; + mUICCConfig = null; } } @@ -118,6 +120,8 @@ public class UiccCard { mContext = c; mCi = ci; //update applications + if (mUICCConfig == null) + mUICCConfig = new UICCConfig(); if (DBG) log(ics.mApplications.length + " applications"); for ( int i = 0; i < mUiccApplications.length; i++) { if (mUiccApplications[i] == null) { @@ -374,6 +378,10 @@ public class UiccCard { return count; } + public UICCConfig getUICCConfig() { + return mUICCConfig; + } + void onRefresh(IccRefreshResponse refreshResponse){ for ( int i = 0; i < mUiccApplications.length; i++) { if (mUiccApplications[i] != null) { diff --git a/src/java/com/android/internal/telephony/uicc/UiccCardApplication.java b/src/java/com/android/internal/telephony/uicc/UiccCardApplication.java index f94a5924a..69fab91e9 100644 --- a/src/java/com/android/internal/telephony/uicc/UiccCardApplication.java +++ b/src/java/com/android/internal/telephony/uicc/UiccCardApplication.java @@ -29,6 +29,7 @@ import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppState; import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; import com.android.internal.telephony.uicc.IccCardApplicationStatus.PersoSubState; import com.android.internal.telephony.uicc.IccCardStatus.PinState; +import com.android.internal.telephony.uicc.UICCConfig; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -904,6 +905,10 @@ public class UiccCardApplication { } } + public UICCConfig getUICCConfig() { + return mUiccCard.getUICCConfig(); + } + private void log(String msg) { Rlog.d(LOG_TAG, msg); } -- cgit v1.2.3