Start enforcing explicit intents for Context.bindService()
No longer prints a warning, now throws an exception.
Also fix a bug in UserManagerService that was causing an
exception while booting.
Change-Id: I3b43cfe08067da840b6850b9bed58664d36d34f1
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 0351292..344c3b2 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -1479,13 +1479,13 @@
private void validateServiceIntent(Intent service) {
if (service.getComponent() == null && service.getPackage() == null) {
- if (true || getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.KITKAT) {
+ if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.L) {
+ IllegalArgumentException ex = new IllegalArgumentException(
+ "Service Intent must be explicit: " + service);
+ throw ex;
+ } else {
Log.w(TAG, "Implicit intents with startService are not safe: " + service
+ " " + Debug.getCallers(2, 3));
- //IllegalArgumentException ex = new IllegalArgumentException(
- // "Service Intent must be explicit: " + service);
- //Log.e(TAG, "This will become an error", ex);
- //throw ex;
}
}
}
diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java
index 22e1476..c8051aa 100644
--- a/core/java/android/os/Build.java
+++ b/core/java/android/os/Build.java
@@ -467,6 +467,19 @@
* </ul>
*/
public static final int KITKAT = 19;
+
+ /**
+ * L!
+ *
+ * <p>Applications targeting this or a later release will get these
+ * new changes in behavior:</p>
+ * <ul>
+ * <li> {@link android.content.Context#bindService Context.bindService} now
+ * requires an explicit Intent, and will throw an exception if given an explicit
+ * Intent.</li>
+ * </ul>
+ */
+ public static final int L = CUR_DEVELOPMENT;
}
/** The type of build, like "user" or "eng". */