aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmit Mahajan <amitmahajan@google.com>2015-01-30 00:52:36 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-01-30 00:52:37 +0000
commit583f21f57ece05ad8980197f120a142c1ae3178f (patch)
tree91c1e836aba8cb33bbf2f5acc3c673677ed033c8
parentdfe728162d1ecd9f6c76989fba58e05ca943fbe8 (diff)
parentf6c0e3489a9365a4851bf3ed19dab18773ecbf65 (diff)
downloadtelephony-583f21f57ece05ad8980197f120a142c1ae3178f.tar.gz
Merge "Changes to make sure READ_PHONE_STATE permission is not needed to send SMS." into lmp-mr1-dev
-rw-r--r--src/java/android/telephony/SmsManager.java53
-rw-r--r--src/java/android/telephony/SmsMessage.java24
-rwxr-xr-xsrc/java/com/android/internal/telephony/UiccSmsController.java43
3 files changed, 79 insertions, 41 deletions
diff --git a/src/java/android/telephony/SmsManager.java b/src/java/android/telephony/SmsManager.java
index a070d69315..a07d141b9f 100644
--- a/src/java/android/telephony/SmsManager.java
+++ b/src/java/android/telephony/SmsManager.java
@@ -26,7 +26,6 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
-import android.provider.Telephony;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
@@ -503,39 +502,31 @@ public final class SmsManager {
public int getSubscriptionId() {
final int subId = (mSubId == DEFAULT_SUBSCRIPTION_ID)
? getDefaultSmsSubscriptionId() : mSubId;
+ boolean isSmsSimPickActivityNeeded = false;
final Context context = ActivityThread.currentApplication().getApplicationContext();
- TelephonyManager telephonyManager =
- (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- List<SubscriptionInfo> subInfoList =
- SubscriptionManager.from(context).getActiveSubscriptionInfoList();
-
- if (subInfoList != null) {
- final int subInfoLength = subInfoList.size();
-
- for (int i = 0; i < subInfoLength; ++i) {
- final SubscriptionInfo sir = subInfoList.get(i);
- if (sir != null && sir.getSubscriptionId() == subId) {
- // The subscription id is valid.
- return subId;
- }
+ try {
+ ISms iccISms = getISmsService();
+ if (iccISms != null) {
+ isSmsSimPickActivityNeeded = iccISms.isSmsSimPickActivityNeeded(subId);
}
+ } catch (RemoteException ex) {
+ Log.e(TAG, "Exception in getSubscriptionId");
+ }
- // The subscription id is not valid.
- // Now if there is at least one valid subscription and 2 or more SIM slots, then ask
- // the user for a default SMS SIM.
- if (subInfoList.size() > 0 && telephonyManager.getSimCount() > 1) {
- Intent intent = new Intent();
- intent.setClassName("com.android.settings",
- "com.android.settings.sim.SimDialogActivity");
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.putExtra(DIALOG_TYPE_KEY, SMS_PICK);
- try {
- context.startActivity(intent);
- } catch (ActivityNotFoundException anfe) {
- // If Settings is not installed, only log the error as we do not want to break
- // legacy applications.
- Log.e(TAG, "Unable to launch Settings application.");
- }
+ if (isSmsSimPickActivityNeeded) {
+ Log.d(TAG, "getSubscriptionId isSmsSimPickActivityNeeded is true");
+ // ask the user for a default SMS SIM.
+ Intent intent = new Intent();
+ intent.setClassName("com.android.settings",
+ "com.android.settings.sim.SimDialogActivity");
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra(DIALOG_TYPE_KEY, SMS_PICK);
+ try {
+ context.startActivity(intent);
+ } catch (ActivityNotFoundException anfe) {
+ // If Settings is not installed, only log the error as we do not want to break
+ // legacy applications.
+ Log.e(TAG, "Unable to launch Settings application.");
}
}
diff --git a/src/java/android/telephony/SmsMessage.java b/src/java/android/telephony/SmsMessage.java
index b57d39d239..daf1e33a07 100644
--- a/src/java/android/telephony/SmsMessage.java
+++ b/src/java/android/telephony/SmsMessage.java
@@ -16,8 +16,8 @@
package android.telephony;
+import android.os.Binder;
import android.os.Parcel;
-import android.telephony.Rlog;
import android.content.res.Resources;
import android.text.TextUtils;
@@ -772,8 +772,15 @@ public class SmsMessage {
return true;
}
- String simOperator = TelephonyManager.getDefault().getSimOperator();
- String gid = TelephonyManager.getDefault().getGroupIdLevel1();
+ String simOperator;
+ String gid;
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ simOperator = TelephonyManager.getDefault().getSimOperator();
+ gid = TelephonyManager.getDefault().getGroupIdLevel1();
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
for (NoEmsSupportConfig currentConfig : mNoEmsSupportConfigList) {
if (simOperator.startsWith(currentConfig.mOperatorNumber) &&
@@ -795,8 +802,15 @@ public class SmsMessage {
return false;
}
- String simOperator = TelephonyManager.getDefault().getSimOperator();
- String gid = TelephonyManager.getDefault().getGroupIdLevel1();
+ String simOperator;
+ String gid;
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ simOperator = TelephonyManager.getDefault().getSimOperator();
+ gid = TelephonyManager.getDefault().getGroupIdLevel1();
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
for (NoEmsSupportConfig currentConfig : mNoEmsSupportConfigList) {
if (simOperator.startsWith(currentConfig.mOperatorNumber) &&
(TextUtils.isEmpty(currentConfig.mGid1) ||
diff --git a/src/java/com/android/internal/telephony/UiccSmsController.java b/src/java/com/android/internal/telephony/UiccSmsController.java
index 86c0ef6855..5f86aa5c42 100755
--- a/src/java/com/android/internal/telephony/UiccSmsController.java
+++ b/src/java/com/android/internal/telephony/UiccSmsController.java
@@ -18,18 +18,18 @@
package com.android.internal.telephony;
+import android.app.ActivityThread;
import android.app.PendingIntent;
+import android.content.Context;
import android.net.Uri;
+import android.os.Binder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.telephony.Rlog;
+import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
-import com.android.internal.telephony.ISms;
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.SmsRawData;
-
-import java.util.ArrayList;
import java.util.List;
/**
@@ -267,6 +267,39 @@ public class UiccSmsController extends ISms.Stub {
return false;
}
+ @Override
+ public boolean isSmsSimPickActivityNeeded(int subId) {
+ final Context context = ActivityThread.currentApplication().getApplicationContext();
+ TelephonyManager telephonyManager =
+ (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ List<SubscriptionInfo> subInfoList;
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ subInfoList = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
+
+ if (subInfoList != null) {
+ final int subInfoLength = subInfoList.size();
+
+ for (int i = 0; i < subInfoLength; ++i) {
+ final SubscriptionInfo sir = subInfoList.get(i);
+ if (sir != null && sir.getSubscriptionId() == subId) {
+ // The subscription id is valid, sms sim pick activity not needed
+ return false;
+ }
+ }
+
+ // If reached here and multiple SIMs and subs present, sms sim pick activity is needed
+ if (subInfoLength > 0 && telephonyManager.getSimCount() > 1) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
public String getImsSmsFormat() {
return getImsSmsFormatForSubscriber(getPreferredSmsSubscription());
}