Merge "Don't erase backup metadata when an app is uninstalled" into mnc-dev
diff --git a/api/current.txt b/api/current.txt
index 6175651..0209fa4 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -8907,6 +8907,7 @@
     field public static final int FLAG_EXTRACT_NATIVE_LIBS = 268435456; // 0x10000000
     field public static final int FLAG_FACTORY_TEST = 16; // 0x10
     field public static final int FLAG_FULL_BACKUP_ONLY = 67108864; // 0x4000000
+    field public static final int FLAG_HARDWARE_ACCELERATED = 536870912; // 0x20000000
     field public static final int FLAG_HAS_CODE = 4; // 0x4
     field public static final int FLAG_INSTALLED = 8388608; // 0x800000
     field public static final int FLAG_IS_DATA_ONLY = 16777216; // 0x1000000
@@ -8936,7 +8937,6 @@
     field public int descriptionRes;
     field public boolean enabled;
     field public int flags;
-    field public boolean hardwareAccelerated;
     field public int largestWidthLimitDp;
     field public java.lang.String manageSpaceActivityName;
     field public java.lang.String nativeLibraryDir;
@@ -15910,6 +15910,7 @@
     field public static final java.lang.String MIMETYPE_AUDIO_AC3 = "audio/ac3";
     field public static final java.lang.String MIMETYPE_AUDIO_AMR_NB = "audio/3gpp";
     field public static final java.lang.String MIMETYPE_AUDIO_AMR_WB = "audio/amr-wb";
+    field public static final java.lang.String MIMETYPE_AUDIO_EAC3 = "audio/eac3";
     field public static final java.lang.String MIMETYPE_AUDIO_FLAC = "audio/flac";
     field public static final java.lang.String MIMETYPE_AUDIO_G711_ALAW = "audio/g711-alaw";
     field public static final java.lang.String MIMETYPE_AUDIO_G711_MLAW = "audio/g711-mlaw";
diff --git a/api/system-current.txt b/api/system-current.txt
index 1f2ad073..baab9a3 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -9136,6 +9136,7 @@
     field public static final int FLAG_EXTRACT_NATIVE_LIBS = 268435456; // 0x10000000
     field public static final int FLAG_FACTORY_TEST = 16; // 0x10
     field public static final int FLAG_FULL_BACKUP_ONLY = 67108864; // 0x4000000
+    field public static final int FLAG_HARDWARE_ACCELERATED = 536870912; // 0x20000000
     field public static final int FLAG_HAS_CODE = 4; // 0x4
     field public static final int FLAG_INSTALLED = 8388608; // 0x800000
     field public static final int FLAG_IS_DATA_ONLY = 16777216; // 0x1000000
@@ -9165,7 +9166,6 @@
     field public int descriptionRes;
     field public boolean enabled;
     field public int flags;
-    field public boolean hardwareAccelerated;
     field public int largestWidthLimitDp;
     field public java.lang.String manageSpaceActivityName;
     field public java.lang.String nativeLibraryDir;
@@ -17146,6 +17146,7 @@
     field public static final java.lang.String MIMETYPE_AUDIO_AC3 = "audio/ac3";
     field public static final java.lang.String MIMETYPE_AUDIO_AMR_NB = "audio/3gpp";
     field public static final java.lang.String MIMETYPE_AUDIO_AMR_WB = "audio/amr-wb";
+    field public static final java.lang.String MIMETYPE_AUDIO_EAC3 = "audio/eac3";
     field public static final java.lang.String MIMETYPE_AUDIO_FLAC = "audio/flac";
     field public static final java.lang.String MIMETYPE_AUDIO_G711_ALAW = "audio/g711-alaw";
     field public static final java.lang.String MIMETYPE_AUDIO_G711_MLAW = "audio/g711-mlaw";
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index 96bb2ee..9fb6f4d 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -373,6 +373,12 @@
     public static final int FLAG_EXTRACT_NATIVE_LIBS = 1<<28;
 
     /**
+     * Value for {@link #flags}: {@code true} when the application's rendering
+     * should be hardware accelerated.
+     */
+    public static final int FLAG_HARDWARE_ACCELERATED = 1<<29;
+
+    /**
      * Value for {@link #flags}: true if code from this application will need to be
      * loaded into other applications' processes. On devices that support multiple
      * instruction sets, this implies the code might be loaded into a process that's
@@ -648,11 +654,6 @@
      */
     public int installLocation = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
 
-    /**
-     * True when the application's rendering should be hardware accelerated.
-     */
-    public boolean hardwareAccelerated;
-
     public void dump(Printer pw, String prefix) {
         super.dumpFront(pw, prefix);
         if (className != null) {
@@ -692,7 +693,6 @@
         }
         pw.println(prefix + "enabled=" + enabled + " targetSdkVersion=" + targetSdkVersion
                 + " versionCode=" + versionCode);
-        pw.println(prefix + "hardwareAccelerated=" + hardwareAccelerated);
         if (manageSpaceActivityName != null) {
             pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
         }
@@ -784,7 +784,6 @@
         descriptionRes = orig.descriptionRes;
         uiOptions = orig.uiOptions;
         backupAgentName = orig.backupAgentName;
-        hardwareAccelerated = orig.hardwareAccelerated;
         fullBackupContent = orig.fullBackupContent;
     }
 
@@ -838,7 +837,6 @@
         dest.writeString(backupAgentName);
         dest.writeInt(descriptionRes);
         dest.writeInt(uiOptions);
-        dest.writeInt(hardwareAccelerated ? 1 : 0);
         dest.writeInt(fullBackupContent);
     }
 
@@ -891,7 +889,6 @@
         backupAgentName = source.readString();
         descriptionRes = source.readInt();
         uiOptions = source.readInt();
-        hardwareAccelerated = source.readInt() != 0;
         fullBackupContent = source.readInt();
     }
 
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 596c0e4..755eb5b 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -2530,7 +2530,9 @@
         owner.baseHardwareAccelerated = sa.getBoolean(
                 com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
                 owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
-        ai.hardwareAccelerated = owner.baseHardwareAccelerated;
+        if (owner.baseHardwareAccelerated) {
+            ai.flags |= ApplicationInfo.FLAG_HARDWARE_ACCELERATED;
+        }
 
         if (sa.getBoolean(
                 com.android.internal.R.styleable.AndroidManifestApplication_hasCode,
diff --git a/core/java/android/view/WindowManagerGlobal.java b/core/java/android/view/WindowManagerGlobal.java
index c16578e..606168c 100644
--- a/core/java/android/view/WindowManagerGlobal.java
+++ b/core/java/android/view/WindowManagerGlobal.java
@@ -20,6 +20,7 @@
 import android.app.ActivityManager;
 import android.content.ComponentCallbacks2;
 import android.content.Context;
+import android.content.pm.ApplicationInfo;
 import android.content.res.Configuration;
 import android.os.IBinder;
 import android.os.RemoteException;
@@ -247,7 +248,8 @@
             // set from the application's hardware acceleration setting.
             final Context context = view.getContext();
             if (context != null
-                    && context.getApplicationInfo().hardwareAccelerated) {
+                    && (context.getApplicationInfo().flags
+                            & ApplicationInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
                 wparams.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
             }
         }
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 4f451c7..57a2ede 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -2451,7 +2451,7 @@
 
     <!-- Allows applications to act as network scorers. @hide @SystemApi-->
     <permission android:name="android.permission.LOCAL_MAC_ADDRESS"
-                android:protectionLevel="signature" />
+                android:protectionLevel="signatureOrSystem" />
 
     <!-- The system process is explicitly the only one allowed to launch the
          confirmation UI for full backup/restore -->
diff --git a/media/java/android/media/MediaFormat.java b/media/java/android/media/MediaFormat.java
index 0e67daa..b2fa0ac 100644
--- a/media/java/android/media/MediaFormat.java
+++ b/media/java/android/media/MediaFormat.java
@@ -106,9 +106,6 @@
     public static final String MIMETYPE_AUDIO_FLAC = "audio/flac";
     public static final String MIMETYPE_AUDIO_MSGSM = "audio/gsm";
     public static final String MIMETYPE_AUDIO_AC3 = "audio/ac3";
-    /**
-     * @hide
-     */
     public static final String MIMETYPE_AUDIO_EAC3 = "audio/eac3";
 
     /**
diff --git a/packages/DocumentsUI/src/com/android/documentsui/CopyService.java b/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
index 6e050c6..506ec5833 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
@@ -173,8 +173,6 @@
                         .setAutoCancel(true);
                 mNotificationManager.notify(mJobId, 0, errorBuilder.build());
             }
-
-            // TODO: Display a toast if the copy was cancelled.
         }
     }
 
@@ -306,13 +304,15 @@
     private void handleCancel(Intent intent) {
         final String cancelledId = intent.getStringExtra(EXTRA_CANCEL);
         // Do nothing if the cancelled ID doesn't match the current job ID. This prevents racey
-        // cancellation requests from affecting unrelated copy jobs.
-        if (Objects.equals(mJobId, cancelledId)) {
+        // cancellation requests from affecting unrelated copy jobs.  However, if the current job ID
+        // is null, the service most likely crashed and was revived by the incoming cancel intent.
+        // In that case, always allow the cancellation to proceed.
+        if (Objects.equals(mJobId, cancelledId) || mJobId == null) {
             // Set the cancel flag. This causes the copy loops to exit.
             mIsCancelled = true;
             // Dismiss the progress notification here rather than in the copy loop. This preserves
             // interactivity for the user in case the copy loop is stalled.
-            mNotificationManager.cancel(mJobId, 0);
+            mNotificationManager.cancel(cancelledId, 0);
         }
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
index e3fb16a..ca0f357 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
@@ -227,7 +227,7 @@
     /** Returns the top task. */
     public ActivityManager.RunningTaskInfo getTopMostTask() {
         List<ActivityManager.RunningTaskInfo> tasks = getRunningTasks(1);
-        if (!tasks.isEmpty()) {
+        if (tasks != null && !tasks.isEmpty()) {
             return tasks.get(0);
         }
         return null;
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
index be33085..f16f6bd 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
@@ -137,21 +137,31 @@
         int previewWidth = data.previewWidth;
         int previewHeight = data.previewheight;
 
-        final int shortSide = mImageWidth < mImageHeight ? mImageWidth : mImageHeight;
-        Bitmap preview = Bitmap.createBitmap(previewWidth, previewHeight, data.image.getConfig());
-        Canvas c = new Canvas(preview);
+        Canvas c = new Canvas();
         Paint paint = new Paint();
         ColorMatrix desat = new ColorMatrix();
         desat.setSaturation(0.25f);
         paint.setColorFilter(new ColorMatrixColorFilter(desat));
         Matrix matrix = new Matrix();
-        matrix.postTranslate((previewWidth - mImageWidth) / 2,
-                            (previewHeight - mImageHeight) / 2);
+        int overlayColor = 0x40FFFFFF;
+
+        Bitmap picture = Bitmap.createBitmap(previewWidth, previewHeight, data.image.getConfig());
+        matrix.setTranslate((previewWidth - mImageWidth) / 2, (previewHeight - mImageHeight) / 2);
+        c.setBitmap(picture);
         c.drawBitmap(data.image, matrix, paint);
-        c.drawColor(0x40FFFFFF);
+        c.drawColor(overlayColor);
         c.setBitmap(null);
 
-        Bitmap croppedIcon = Bitmap.createScaledBitmap(preview, iconSize, iconSize, true);
+        // Note, we can't use the preview for the small icon, since it is non-square
+        float scale = (float) iconSize / Math.min(mImageWidth, mImageHeight);
+        Bitmap icon = Bitmap.createBitmap(iconSize, iconSize, data.image.getConfig());
+        matrix.setScale(scale, scale);
+        matrix.postTranslate((iconSize - (scale * mImageWidth)) / 2,
+                (iconSize - (scale * mImageHeight)) / 2);
+        c.setBitmap(icon);
+        c.drawBitmap(data.image, matrix, paint);
+        c.drawColor(overlayColor);
+        c.setBitmap(null);
 
         // Show the intermediate notification
         mTickerAddSpace = !mTickerAddSpace;
@@ -169,7 +179,7 @@
             .setColor(r.getColor(com.android.internal.R.color.system_notification_accent_color));
 
         mNotificationStyle = new Notification.BigPictureStyle()
-            .bigPicture(preview);
+            .bigPicture(picture);
         mNotificationBuilder.setStyle(mNotificationStyle);
 
         // For "public" situations we want to show all the same info but
@@ -192,7 +202,7 @@
         // On the tablet, the large icon makes the notification appear as if it is clickable (and
         // on small devices, the large icon is not shown) so defer showing the large icon until
         // we compose the final post-save notification below.
-        mNotificationBuilder.setLargeIcon(croppedIcon);
+        mNotificationBuilder.setLargeIcon(icon);
         // But we still don't set it for the expanded view, allowing the smallIcon to show here.
         mNotificationStyle.bigLargeIcon((Bitmap) null);
     }