Fix permission check for get/setSmscAddress.

Based on api-council feedback. Incorporated other suggestions too.

Test: basic SMS sanity
Bug: 149236716
Change-Id: I60b300d1b2d4e8b67cfc121e10a7957a8f0aaac8
This commit is contained in:
Amit Mahajan
2020-02-20 13:46:51 -08:00
parent fe348ebe91
commit 15a3b86e89
2 changed files with 20 additions and 4 deletions

View File

@@ -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)) {

View File

@@ -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;
}