Don't enforce access checks for overloading for targetSdkVersion < 17.

Still warn, and enforce the missing check for targetSdkVersion >= 17.

Bug: 7301030
Change-Id: I8189fcbf222f331b1f80a156b01082d61f1f9362
diff --git a/vm/Globals.h b/vm/Globals.h
index 565c92a..3a90ddf 100644
--- a/vm/Globals.h
+++ b/vm/Globals.h
@@ -124,6 +124,8 @@
     void        (*abortHook)(void);
     bool        (*isSensitiveThreadHook)(void);
 
+    int targetSdkVersion;
+
     int         jniGrefLimit;       // 0 means no limit
     char*       jniTrace;
     bool        reduceSignals;
diff --git a/vm/native/dalvik_system_VMRuntime.cpp b/vm/native/dalvik_system_VMRuntime.cpp
index 72bad29..0195a8c 100644
--- a/vm/native/dalvik_system_VMRuntime.cpp
+++ b/vm/native/dalvik_system_VMRuntime.cpp
@@ -191,10 +191,10 @@
     // This is the target SDK version of the app we're about to run.
     // Note that this value may be CUR_DEVELOPMENT (10000).
     // Note that this value may be 0, meaning "current".
-    int targetSdkVersion = args[1];
-    if (targetSdkVersion > 0 && targetSdkVersion <= 13 /* honeycomb-mr2 */) {
+    gDvm.targetSdkVersion = args[1];
+    if (gDvm.targetSdkVersion > 0 && gDvm.targetSdkVersion <= 13 /* honeycomb-mr2 */) {
         // TODO: running with CheckJNI should override this and force you to obey the strictest rules.
-        ALOGI("Turning on JNI app bug workarounds for target SDK version %i...", targetSdkVersion);
+        ALOGI("Turning on JNI app bug workarounds for target SDK version %i...", gDvm.targetSdkVersion);
         gDvmJni.workAroundAppJniBugs = true;
     }
     RETURN_VOID();
diff --git a/vm/oo/Class.cpp b/vm/oo/Class.cpp
index eb816b0..17c9ff8 100644
--- a/vm/oo/Class.cpp
+++ b/vm/oo/Class.cpp
@@ -2914,24 +2914,30 @@
                 Method* superMeth = clazz->vtable[si];
 
                 if (dvmCompareMethodNamesAndProtos(localMeth, superMeth) == 0) {
-                    if (dvmCheckMethodAccess(clazz, superMeth)) {
-                        /* verify */
+                    // Some apps were relying on us not checking access: http://b/7301030
+                    bool isPreJbMr1 = (gDvm.targetSdkVersion > 0 && gDvm.targetSdkVersion < 17);
+                    bool isAccessible = dvmCheckMethodAccess(clazz, superMeth);
+                    if (isPreJbMr1 || isAccessible) {
                         if (dvmIsFinalMethod(superMeth)) {
                             ALOGW("Method %s.%s overrides final %s.%s",
-                                localMeth->clazz->descriptor, localMeth->name,
-                                superMeth->clazz->descriptor, superMeth->name);
+                                  localMeth->clazz->descriptor, localMeth->name,
+                                  superMeth->clazz->descriptor, superMeth->name);
                             goto bail;
                         }
+
+                        // Warn if we may have just worked around broken code...
+                        if (!isAccessible) {
+                            ALOGW("in older Android releases, method %s.%s would have incorrectly "
+                                  "overridden package-private method with same name in %s",
+                                  localMeth->clazz->descriptor, localMeth->name,
+                                  superMeth->clazz->descriptor);
+                        }
+
                         clazz->vtable[si] = localMeth;
                         localMeth->methodIndex = (u2) si;
                         //ALOGV("+++   override %s.%s (slot %d)",
                         //    clazz->descriptor, localMeth->name, si);
                         break;
-                    } else {
-                        ALOGW("in older versions of dalvik, method %s.%s would have incorrectly "
-                              "overridden package-private method with same name in %s",
-                              localMeth->clazz->descriptor, localMeth->name,
-                              superMeth->clazz->descriptor);
                     }
                 }
             }