diff options
author | Amit Mahajan <amitmahajan@google.com> | 2020-02-20 13:46:51 -0800 |
---|---|---|
committer | Amit Mahajan <amitmahajan@google.com> | 2020-03-02 19:29:55 +0000 |
commit | 05e97205523d6ca0f941b0707539f9be6e54ba54 (patch) | |
tree | 66f48fee983bb06e3a112c0d9e937d98fb2c81e7 | |
parent | 4894b560a53326a50054bcb41097c84c26a17a10 (diff) |
Fix permission check for get/setSmscAddress.
Based on api-council feedback. Incorporated other suggestions too.
Test: basic SMS sanity
Bug: 149236716
Merged-in: I60b300d1b2d4e8b67cfc121e10a7957a8f0aaac8
Change-Id: I60b300d1b2d4e8b67cfc121e10a7957a8f0aaac8
(cherry picked from commit 15a3b86e897fa696fce75362d0cab64fea710f31)
-rw-r--r-- | telephony/common/com/android/internal/telephony/SmsApplication.java | 17 | ||||
-rw-r--r-- | telephony/java/android/telephony/SmsManager.java | 7 |
2 files changed, 20 insertions, 4 deletions
diff --git a/telephony/common/com/android/internal/telephony/SmsApplication.java b/telephony/common/com/android/internal/telephony/SmsApplication.java index bb6f154335a9..d54c054e2f82 100644 --- a/telephony/common/com/android/internal/telephony/SmsApplication.java +++ b/telephony/common/com/android/internal/telephony/SmsApplication.java @@ -1057,7 +1057,8 @@ public final class SmsApplication { } /** - * Check if a package is default sms app (or equivalent, like bluetooth) + * Check if a package is default sms app (or equivalent, like bluetooth), and verify that + * packageName belongs to the caller. * * @param context context from the calling app * @param packageName the name of the package to be checked @@ -1066,8 +1067,22 @@ public final class SmsApplication { @UnsupportedAppUsage public static boolean isDefaultSmsApplication(Context context, String packageName) { if (packageName == null) { + Log.e(LOG_TAG, "isDefaultSmsApplication: packageName is null"); return false; } + try { + if (Binder.getCallingUid() + == context.getPackageManager().getPackageUid(packageName, 0)) { + Log.e(LOG_TAG, "isDefaultSmsApplication: " + packageName + " calling uid " + + context.getPackageManager().getPackageUid(packageName, 0) + + " does not match calling uid " + Binder.getCallingUid()); + return false; + } + } catch (NameNotFoundException ex) { + Log.e(LOG_TAG, "isDefaultSmsApplication: packageName " + packageName + " not found"); + return false; + } + final String defaultSmsPackage = getDefaultSmsApplicationPackageName(context); if ((defaultSmsPackage != null && defaultSmsPackage.equals(packageName)) || BLUETOOTH_PACKAGE_NAME.equals(packageName)) { diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java index 8479db64799c..87d0c7f9edfc 100644 --- a/telephony/java/android/telephony/SmsManager.java +++ b/telephony/java/android/telephony/SmsManager.java @@ -2898,7 +2898,7 @@ public final class SmsManager { getSubscriptionId(), null); } } catch (RemoteException ex) { - // ignore it + throw new RuntimeException(ex); } return smsc; } @@ -2920,7 +2920,8 @@ public final class SmsManager { * </p> * * @param smsc the SMSC address string. - * @return true for success, false otherwise. + * @return true for success, false otherwise. Failure can be due to caller not having the + * appropriate permission, or modem returning an error. */ @SuppressAutoDoc // for carrier privileges and default SMS application. @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) @@ -2932,7 +2933,7 @@ public final class SmsManager { smsc, getSubscriptionId(), null); } } catch (RemoteException ex) { - // ignore it + throw new RuntimeException(ex); } return false; } |