summaryrefslogtreecommitdiffstats
path: root/core/java/android/app/ContextImpl.java
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2013-08-04 16:50:16 -0700
committerDianne Hackborn <hackbod@google.com>2013-08-05 16:53:26 -0700
commit221ea892dcc661bd07d6f36ff012edca2c48aed4 (patch)
tree33a29861257497ebd865fe5565c9e3bfbde3cb1a /core/java/android/app/ContextImpl.java
parent33041bd90301d50c61e6375bbd9bb6da2f1c8cba (diff)
downloadframeworks_base-221ea892dcc661bd07d6f36ff012edca2c48aed4.zip
frameworks_base-221ea892dcc661bd07d6f36ff012edca2c48aed4.tar.gz
frameworks_base-221ea892dcc661bd07d6f36ff012edca2c48aed4.tar.bz2
Start restricting service calls with implicit intents.
The bindService() and startService() calls have always had undefined behavior when used with an implicit Intent and there are multiple matching services. Because of this, it is not safe for applications to use such Intents when interacting with services, yet the platform would merrily go about doing... something. In KLP I want to cause this case to be invalid, resulting in an exception thrown back to the app. Unfortunately there are lots of (scary) things relying on this behavior, so we can't immediately turn it into an exception, even one qualified by the caller's target SDK version. In this change, we start loggin a WTF when such a call happens, and clean up some stuff in Bluetooth that was doing this behavior. Change-Id: I62e25d07890588d2362104e20b054aebb6c0e007
Diffstat (limited to 'core/java/android/app/ContextImpl.java')
-rw-r--r--core/java/android/app/ContextImpl.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index ab11903..60c0288 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -1444,6 +1444,14 @@ class ContextImpl extends Context {
@Override
public ComponentName startServiceAsUser(Intent service, UserHandle user) {
try {
+ if (service.getComponent() == null && service.getPackage() == null) {
+ if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.KEY_LIME_PIE) {
+ IllegalArgumentException ex = new IllegalArgumentException(
+ "Service Intent must be explicit: " + service);
+ Log.wtf(TAG, "This will become an error", ex);
+ //throw ex;
+ }
+ }
service.prepareToLeaveProcess();
ComponentName cn = ActivityManagerNative.getDefault().startService(
mMainThread.getApplicationThread(), service,
@@ -1468,6 +1476,14 @@ class ContextImpl extends Context {
@Override
public boolean stopServiceAsUser(Intent service, UserHandle user) {
try {
+ if (service.getComponent() == null && service.getPackage() == null) {
+ if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.KEY_LIME_PIE) {
+ IllegalArgumentException ex = new IllegalArgumentException(
+ "Service Intent must be explicit: " + service);
+ Log.wtf(TAG, "This will become an error", ex);
+ //throw ex;
+ }
+ }
service.prepareToLeaveProcess();
int res = ActivityManagerNative.getDefault().stopService(
mMainThread.getApplicationThread(), service,
@@ -1503,6 +1519,14 @@ class ContextImpl extends Context {
} else {
throw new RuntimeException("Not supported in system context");
}
+ if (service.getComponent() == null && service.getPackage() == null) {
+ if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.KEY_LIME_PIE) {
+ IllegalArgumentException ex = new IllegalArgumentException(
+ "Service Intent must be explicit: " + service);
+ Log.wtf(TAG, "This will become an error", ex);
+ //throw ex;
+ }
+ }
try {
IBinder token = getActivityToken();
if (token == null && (flags&BIND_AUTO_CREATE) == 0 && mPackageInfo != null