Merge "fix [2363362] [Sapphire] Corrupted raw picture displayed during snapshot"
diff --git a/core/java/android/app/ApplicationErrorReport.java b/core/java/android/app/ApplicationErrorReport.java
index a4b692f..832f599 100644
--- a/core/java/android/app/ApplicationErrorReport.java
+++ b/core/java/android/app/ApplicationErrorReport.java
@@ -82,6 +82,11 @@
     public long time;
 
     /**
+     * Set if the app is on the system image.
+     */
+    public boolean systemApp;
+
+    /**
      * If this report is of type {@link #TYPE_CRASH}, contains an instance
      * of CrashInfo describing the crash; otherwise null.
      */
@@ -113,6 +118,7 @@
         dest.writeString(installerPackageName);
         dest.writeString(processName);
         dest.writeLong(time);
+        dest.writeInt(systemApp ? 1 : 0);
 
         switch (type) {
             case TYPE_CRASH:
@@ -130,6 +136,7 @@
         installerPackageName = in.readString();
         processName = in.readString();
         time = in.readLong();
+        systemApp = in.readInt() == 1;
 
         switch (type) {
             case TYPE_CRASH:
@@ -331,6 +338,7 @@
         pw.println(prefix + "installerPackageName: " + installerPackageName);
         pw.println(prefix + "processName: " + processName);
         pw.println(prefix + "time: " + time);
+        pw.println(prefix + "systemApp: " + systemApp);
 
         switch (type) {
             case TYPE_CRASH:
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 404c513..b677b1e 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -66,6 +66,13 @@
     /** when preloading, GC after allocating this many bytes */
     private static final int PRELOAD_GC_THRESHOLD = 50000;
 
+    /** throw on missing preload, only if this looks like a developer */
+    private static final boolean THROW_ON_MISSING_PRELOAD =
+            "1".equals(SystemProperties.get("persist.service.adb.enable"));
+
+    public static final String USAGE_STRING =
+            " <\"true\"|\"false\" for startSystemServer>";
+
     private static LocalServerSocket sServerSocket;
 
     /**
@@ -322,8 +329,8 @@
                     }
                 }
 
-                if (missingClasses != null &&
-                        "1".equals(SystemProperties.get("persist.service.adb.enable"))) {
+                if (THROW_ON_MISSING_PRELOAD &&
+                    missingClasses != null) {
                     throw new IllegalStateException(
                             "Missing class(es) for preloading, update preloaded-classes ["
                             + missingClasses + "]");
@@ -597,12 +604,13 @@
 
             // If requested, start system server directly from Zygote
             if (argv.length != 2) {
-                throw new RuntimeException(
-                        "ZygoteInit.main expects two arguments");
+                throw new RuntimeException(argv[0] + USAGE_STRING);
             }
 
             if (argv[1].equals("true")) {
                 startSystemServer();
+            } else if (!argv[1].equals("false")) {
+                throw new RuntimeException(argv[0] + USAGE_STRING);
             }
 
             Log.i(TAG, "Accepting command socket connections");
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 3080ab0..88521f6 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -110,9 +110,5 @@
 
 include $(BUILD_SHARED_LIBRARY)
 
-# Include the subdirectories ====================
-include $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk,\
-            java \
-    	))
 
 endif #simulator
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index 3ba9cee..eeb9468 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -778,6 +778,17 @@
     rsc->setVertex((ProgramVertex *)tmp.get());
 }
 
+static void SC_drawSpriteScreenspaceCropped(float x, float y, float z, float w, float h,
+        float cx0, float cy0, float cx1, float cy1)
+{
+    GET_TLS();
+    rsc->setupCheck();
+
+    GLint crop[4] = {cx0, cy0, cx1, cy1};
+    glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
+    glDrawTexfOES(x, y, z, w, h);
+}
+
 static void SC_drawSprite(float x, float y, float z, float w, float h)
 {
     GET_TLS();
@@ -1289,6 +1300,8 @@
         "void", "(float x, float y, float z, float w, float h)" },
     { "drawSpriteScreenspace", (void *)&SC_drawSpriteScreenspace,
         "void", "(float x, float y, float z, float w, float h)" },
+    { "drawSpriteScreenspaceCropped", (void *)&SC_drawSpriteScreenspaceCropped,
+        "void", "(float x, float y, float z, float w, float h, float cx0, float cy0, float cx1, float cy1)" },
     { "drawLine", (void *)&SC_drawLine,
         "void", "(float x1, float y1, float z1, float x2, float y2, float z2)" },
     { "drawPoint", (void *)&SC_drawPoint,
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 843058c..5b50a3a 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -8994,6 +8994,7 @@
         report.installerPackageName = r.errorReportReceiver.getPackageName();
         report.processName = r.processName;
         report.time = timeMillis;
+        report.systemApp = (r.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
 
         if (r.crashing) {
             report.type = ApplicationErrorReport.TYPE_CRASH;