Merge "Correct exit animation window retention logic."
diff --git a/Android.mk b/Android.mk
index d3e1cf5..c1c74ea 100644
--- a/Android.mk
+++ b/Android.mk
@@ -226,7 +226,6 @@
 	core/java/android/service/carrier/ICarrierMessagingService.aidl \
 	core/java/android/service/gatekeeper/IGateKeeperService.aidl \
 	core/java/android/service/notification/INotificationListener.aidl \
-	core/java/android/service/notification/INotificationAssistant.aidl \
 	core/java/android/service/notification/IStatusBarNotificationHolder.aidl \
 	core/java/android/service/notification/IConditionListener.aidl \
 	core/java/android/service/notification/IConditionProvider.aidl \
@@ -262,7 +261,7 @@
 	core/java/android/view/IApplicationToken.aidl \
 	core/java/android/view/IAppTransitionAnimationSpecsFuture.aidl \
 	core/java/android/view/IAssetAtlas.aidl \
-	core/java/android/view/IDockDividerVisibilityListener.aidl \
+	core/java/android/view/IDockedStackListener.aidl \
 	core/java/android/view/IGraphicsStats.aidl \
 	core/java/android/view/IInputFilter.aidl \
 	core/java/android/view/IInputFilterHost.aidl \
diff --git a/api/current.txt b/api/current.txt
index 76e44cf..8d9ca6e 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -67,7 +67,6 @@
     field public static final java.lang.String DUMP = "android.permission.DUMP";
     field public static final java.lang.String EXPAND_STATUS_BAR = "android.permission.EXPAND_STATUS_BAR";
     field public static final java.lang.String FACTORY_TEST = "android.permission.FACTORY_TEST";
-    field public static final java.lang.String FLASHLIGHT = "android.permission.FLASHLIGHT";
     field public static final java.lang.String GET_ACCOUNTS = "android.permission.GET_ACCOUNTS";
     field public static final java.lang.String GET_ACCOUNTS_PRIVILEGED = "android.permission.GET_ACCOUNTS_PRIVILEGED";
     field public static final java.lang.String GET_PACKAGE_SIZE = "android.permission.GET_PACKAGE_SIZE";
@@ -4229,7 +4228,7 @@
     field public static final java.lang.String COLUMN_DESCRIPTION = "description";
     field public static final java.lang.String COLUMN_ID = "_id";
     field public static final java.lang.String COLUMN_LAST_MODIFIED_TIMESTAMP = "last_modified_timestamp";
-    field public static final java.lang.String COLUMN_LOCAL_FILENAME = "local_filename";
+    field public static final deprecated java.lang.String COLUMN_LOCAL_FILENAME = "local_filename";
     field public static final java.lang.String COLUMN_LOCAL_URI = "local_uri";
     field public static final java.lang.String COLUMN_MEDIAPROVIDER_URI = "mediaprovider_uri";
     field public static final java.lang.String COLUMN_MEDIA_TYPE = "media_type";
@@ -5198,6 +5197,7 @@
     field public static final int SUPPRESSED_EFFECTS_UNSET = -1; // 0xffffffff
     field public static final int SUPPRESSED_EFFECT_LIGHTS = 1; // 0x1
     field public static final int SUPPRESSED_EFFECT_PEEK = 2; // 0x2
+    field public static final int SUPPRESSED_EFFECT_SCREEN_ON = 4; // 0x4
     field public final int priorityCallSenders;
     field public final int priorityCategories;
     field public final int priorityMessageSenders;
@@ -5758,9 +5758,11 @@
     method public java.lang.String getDeviceOwnerLockScreenInfo();
     method public java.util.List<byte[]> getInstalledCaCerts(android.content.ComponentName);
     method public int getKeyguardDisabledFeatures(android.content.ComponentName);
+    method public java.lang.String getLongSupportMessage(android.content.ComponentName);
     method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
     method public long getMaximumTimeToLock(android.content.ComponentName);
     method public boolean getPackageSuspended(android.content.ComponentName, java.lang.String);
+    method public android.app.admin.DevicePolicyManager getParentProfileInstance(android.content.ComponentName);
     method public long getPasswordExpiration(android.content.ComponentName);
     method public long getPasswordExpirationTimeout(android.content.ComponentName);
     method public int getPasswordHistoryLength(android.content.ComponentName);
@@ -5778,6 +5780,7 @@
     method public java.util.List<java.lang.String> getPermittedAccessibilityServices(android.content.ComponentName);
     method public java.util.List<java.lang.String> getPermittedInputMethods(android.content.ComponentName);
     method public boolean getScreenCaptureDisabled(android.content.ComponentName);
+    method public java.lang.String getShortSupportMessage(android.content.ComponentName);
     method public boolean getStorageEncryption(android.content.ComponentName);
     method public int getStorageEncryptionStatus();
     method public android.app.admin.SystemUpdatePolicy getSystemUpdatePolicy();
@@ -5819,6 +5822,7 @@
     method public boolean setKeyguardDisabled(android.content.ComponentName, boolean);
     method public void setKeyguardDisabledFeatures(android.content.ComponentName, int);
     method public void setLockTaskPackages(android.content.ComponentName, java.lang.String[]) throws java.lang.SecurityException;
+    method public void setLongSupportMessage(android.content.ComponentName, java.lang.String);
     method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
     method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
     method public void setMaximumTimeToLock(android.content.ComponentName, long);
@@ -5843,6 +5847,7 @@
     method public void setRestrictionsProvider(android.content.ComponentName, android.content.ComponentName);
     method public void setScreenCaptureDisabled(android.content.ComponentName, boolean);
     method public void setSecureSetting(android.content.ComponentName, java.lang.String, java.lang.String);
+    method public void setShortSupportMessage(android.content.ComponentName, java.lang.String);
     method public boolean setStatusBarDisabled(android.content.ComponentName, boolean);
     method public int setStorageEncryption(android.content.ComponentName, boolean);
     method public void setSystemUpdatePolicy(android.content.ComponentName, android.app.admin.SystemUpdatePolicy);
@@ -7568,11 +7573,12 @@
     method public abstract void writeDataToPipe(android.os.ParcelFileDescriptor, android.net.Uri, java.lang.String, android.os.Bundle, T);
   }
 
-  public class ContentProviderClient {
+  public class ContentProviderClient implements java.lang.AutoCloseable {
     method public android.content.ContentProviderResult[] applyBatch(java.util.ArrayList<android.content.ContentProviderOperation>) throws android.content.OperationApplicationException, android.os.RemoteException;
     method public int bulkInsert(android.net.Uri, android.content.ContentValues[]) throws android.os.RemoteException;
     method public android.os.Bundle call(java.lang.String, java.lang.String, android.os.Bundle) throws android.os.RemoteException;
     method public final android.net.Uri canonicalize(android.net.Uri) throws android.os.RemoteException;
+    method public void close();
     method public int delete(android.net.Uri, java.lang.String, java.lang.String[]) throws android.os.RemoteException;
     method public android.content.ContentProvider getLocalContentProvider();
     method public java.lang.String[] getStreamTypes(android.net.Uri, java.lang.String) throws android.os.RemoteException;
@@ -7586,7 +7592,7 @@
     method public final android.content.res.AssetFileDescriptor openTypedAssetFileDescriptor(android.net.Uri, java.lang.String, android.os.Bundle, android.os.CancellationSignal) throws java.io.FileNotFoundException, android.os.RemoteException;
     method public android.database.Cursor query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String) throws android.os.RemoteException;
     method public android.database.Cursor query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String, android.os.CancellationSignal) throws android.os.RemoteException;
-    method public boolean release();
+    method public deprecated boolean release();
     method public final android.net.Uri uncanonicalize(android.net.Uri) throws android.os.RemoteException;
     method public int update(android.net.Uri, android.content.ContentValues, java.lang.String, java.lang.String[]) throws android.os.RemoteException;
   }
@@ -9441,8 +9447,10 @@
     method public abstract java.lang.String getNameForUid(int);
     method public android.content.pm.PackageInfo getPackageArchiveInfo(java.lang.String, int);
     method public abstract int[] getPackageGids(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
+    method public abstract int[] getPackageGids(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract android.content.pm.PackageInfo getPackageInfo(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract android.content.pm.PackageInstaller getPackageInstaller();
+    method public abstract int getPackageUid(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract java.lang.String[] getPackagesForUid(int);
     method public abstract java.util.List<android.content.pm.PackageInfo> getPackagesHoldingPermissions(java.lang.String[], int);
     method public abstract android.content.pm.PermissionGroupInfo getPermissionGroupInfo(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
@@ -9513,6 +9521,7 @@
     field public static final java.lang.String FEATURE_CONNECTION_SERVICE = "android.software.connectionservice";
     field public static final java.lang.String FEATURE_CONSUMER_IR = "android.hardware.consumerir";
     field public static final java.lang.String FEATURE_DEVICE_ADMIN = "android.software.device_admin";
+    field public static final java.lang.String FEATURE_ETHERNET = "android.hardware.ethernet";
     field public static final java.lang.String FEATURE_FAKETOUCH = "android.hardware.faketouch";
     field public static final java.lang.String FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT = "android.hardware.faketouch.multitouch.distinct";
     field public static final java.lang.String FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND = "android.hardware.faketouch.multitouch.jazzhand";
@@ -9571,8 +9580,8 @@
     field public static final java.lang.String FEATURE_WIFI_DIRECT = "android.hardware.wifi.direct";
     field public static final int GET_ACTIVITIES = 1; // 0x1
     field public static final int GET_CONFIGURATIONS = 16384; // 0x4000
-    field public static final int GET_DISABLED_COMPONENTS = 512; // 0x200
-    field public static final int GET_DISABLED_UNTIL_USED_COMPONENTS = 32768; // 0x8000
+    field public static final deprecated int GET_DISABLED_COMPONENTS = 512; // 0x200
+    field public static final deprecated int GET_DISABLED_UNTIL_USED_COMPONENTS = 32768; // 0x8000
     field public static final int GET_GIDS = 256; // 0x100
     field public static final int GET_INSTRUMENTATION = 16; // 0x10
     field public static final int GET_INTENT_FILTERS = 32; // 0x20
@@ -9584,13 +9593,17 @@
     field public static final int GET_SERVICES = 4; // 0x4
     field public static final int GET_SHARED_LIBRARY_FILES = 1024; // 0x400
     field public static final int GET_SIGNATURES = 64; // 0x40
-    field public static final int GET_UNINSTALLED_PACKAGES = 8192; // 0x2000
+    field public static final deprecated int GET_UNINSTALLED_PACKAGES = 8192; // 0x2000
     field public static final int GET_URI_PERMISSION_PATTERNS = 2048; // 0x800
     field public static final int MATCH_ALL = 131072; // 0x20000
     field public static final int MATCH_DEFAULT_ONLY = 65536; // 0x10000
+    field public static final int MATCH_DISABLED_COMPONENTS = 512; // 0x200
+    field public static final int MATCH_DISABLED_UNTIL_USED_COMPONENTS = 32768; // 0x8000
+    field public static final int MATCH_ENCRYPTION_AWARE = 524288; // 0x80000
     field public static final int MATCH_ENCRYPTION_AWARE_AND_UNAWARE = 786432; // 0xc0000
-    field public static final int MATCH_ENCRYPTION_AWARE_ONLY = 524288; // 0x80000
-    field public static final int MATCH_ENCRYPTION_UNAWARE_ONLY = 262144; // 0x40000
+    field public static final int MATCH_ENCRYPTION_UNAWARE = 262144; // 0x40000
+    field public static final int MATCH_SYSTEM_ONLY = 1048576; // 0x100000
+    field public static final int MATCH_UNINSTALLED_PACKAGES = 8192; // 0x2000
     field public static final long MAXIMUM_VERIFICATION_TIMEOUT = 3600000L; // 0x36ee80L
     field public static final int PERMISSION_DENIED = -1; // 0xffffffff
     field public static final int PERMISSION_GRANTED = 0; // 0x0
@@ -10840,7 +10853,7 @@
     field public final int statusCode;
   }
 
-  public class DrmManagerClient {
+  public class DrmManagerClient implements java.lang.AutoCloseable {
     ctor public DrmManagerClient(android.content.Context);
     method public android.drm.DrmInfo acquireDrmInfo(android.drm.DrmInfoRequest);
     method public int acquireRights(android.drm.DrmInfoRequest);
@@ -10850,6 +10863,7 @@
     method public int checkRightsStatus(android.net.Uri);
     method public int checkRightsStatus(java.lang.String, int);
     method public int checkRightsStatus(android.net.Uri, int);
+    method public void close();
     method public android.drm.DrmConvertedStatus closeConvertSession(int);
     method public android.drm.DrmConvertedStatus convertData(int, byte[]);
     method public java.lang.String[] getAvailableDrmEngines();
@@ -10863,7 +10877,7 @@
     method public java.lang.String getOriginalMimeType(android.net.Uri);
     method public int openConvertSession(java.lang.String);
     method public int processDrmInfo(android.drm.DrmInfo);
-    method public void release();
+    method public deprecated void release();
     method public int removeAllRights();
     method public int removeRights(java.lang.String);
     method public int removeRights(android.net.Uri);
@@ -11267,14 +11281,14 @@
 
   public static class BitmapFactory.Options {
     ctor public BitmapFactory.Options();
-    method public void requestCancelDecode();
+    method public deprecated void requestCancelDecode();
     field public android.graphics.Bitmap inBitmap;
     field public int inDensity;
-    field public boolean inDither;
+    field public deprecated boolean inDither;
     field public deprecated boolean inInputShareable;
     field public boolean inJustDecodeBounds;
     field public boolean inMutable;
-    field public boolean inPreferQualityOverSpeed;
+    field public deprecated boolean inPreferQualityOverSpeed;
     field public android.graphics.Bitmap.Config inPreferredConfig;
     field public boolean inPremultiplied;
     field public deprecated boolean inPurgeable;
@@ -18243,7 +18257,6 @@
     method public static java.lang.String getCanonicalID(java.lang.String, boolean[]);
     method public int getDSTSavings();
     method public static android.icu.util.TimeZone getDefault();
-    method public static int getDefaultTimeZoneType();
     method public final java.lang.String getDisplayName();
     method public final java.lang.String getDisplayName(java.util.Locale);
     method public final java.lang.String getDisplayName(android.icu.util.ULocale);
@@ -18267,8 +18280,6 @@
     method public abstract boolean inDaylightTime(java.util.Date);
     method public boolean isFrozen();
     method public boolean observesDaylightTime();
-    method public static synchronized void setDefault(android.icu.util.TimeZone);
-    method public static synchronized void setDefaultTimeZoneType(int);
     method public void setID(java.lang.String);
     method public abstract void setRawOffset(int);
     method public abstract boolean useDaylightTime();
@@ -18281,8 +18292,6 @@
     field public static final int SHORT_COMMONLY_USED = 6; // 0x6
     field public static final int SHORT_GENERIC = 2; // 0x2
     field public static final int SHORT_GMT = 4; // 0x4
-    field public static final int TIMEZONE_ICU = 0; // 0x0
-    field public static final int TIMEZONE_JDK = 1; // 0x1
     field public static final android.icu.util.TimeZone UNKNOWN_ZONE;
     field public static final java.lang.String UNKNOWN_ZONE_ID = "Etc/Unknown";
   }
@@ -18378,8 +18387,6 @@
     method public static java.lang.String getVariant(java.lang.String);
     method public boolean isRightToLeft();
     method public static android.icu.util.ULocale minimizeSubtags(android.icu.util.ULocale);
-    method public static synchronized void setDefault(android.icu.util.ULocale);
-    method public static synchronized void setDefault(android.icu.util.ULocale.Category, android.icu.util.ULocale);
     method public android.icu.util.ULocale setKeywordValue(java.lang.String, java.lang.String);
     method public static java.lang.String setKeywordValue(java.lang.String, java.lang.String, java.lang.String);
     method public java.lang.String toLanguageTag();
@@ -22448,6 +22455,7 @@
     method public int[] getObjectHandles(int, int, int);
     method public android.mtp.MtpObjectInfo getObjectInfo(int);
     method public long getParent(int);
+    method public int getPartialObject(int, int, int, byte[]) throws java.io.IOException;
     method public long getStorageId(int);
     method public int[] getStorageIds();
     method public android.mtp.MtpStorageInfo getStorageInfo(int);
@@ -30774,7 +30782,7 @@
     field public static final java.lang.String COLUMN_MIME_TYPE = "mime_type";
     field public static final java.lang.String COLUMN_SIZE = "_size";
     field public static final java.lang.String COLUMN_SUMMARY = "summary";
-    field public static final int FLAG_ARCHIVE = 2048; // 0x800
+    field public static final int FLAG_ARCHIVE = 1024; // 0x400
     field public static final int FLAG_DIR_PREFERS_GRID = 16; // 0x10
     field public static final int FLAG_DIR_PREFERS_LAST_MODIFIED = 32; // 0x20
     field public static final int FLAG_DIR_SUPPORTS_CREATE = 8; // 0x8
@@ -30783,9 +30791,8 @@
     field public static final int FLAG_SUPPORTS_MOVE = 256; // 0x100
     field public static final int FLAG_SUPPORTS_RENAME = 64; // 0x40
     field public static final int FLAG_SUPPORTS_THUMBNAIL = 1; // 0x1
-    field public static final int FLAG_SUPPORTS_TYPED_DOCUMENT = 512; // 0x200
     field public static final int FLAG_SUPPORTS_WRITE = 2; // 0x2
-    field public static final int FLAG_VIRTUAL_DOCUMENT = 1024; // 0x400
+    field public static final int FLAG_VIRTUAL_DOCUMENT = 512; // 0x200
     field public static final java.lang.String MIME_TYPE_DIR = "vnd.android.document/directory";
   }
 
@@ -31229,6 +31236,7 @@
     field public static final java.lang.String ACTION_SEARCH_SETTINGS = "android.search.action.SEARCH_SETTINGS";
     field public static final java.lang.String ACTION_SECURITY_SETTINGS = "android.settings.SECURITY_SETTINGS";
     field public static final java.lang.String ACTION_SETTINGS = "android.settings.SETTINGS";
+    field public static final java.lang.String ACTION_SHOW_ADMIN_SUPPORT_DETAILS = "android.settings.SHOW_ADMIN_SUPPORT_DETAILS";
     field public static final java.lang.String ACTION_SHOW_REGULATORY_INFO = "android.settings.SHOW_REGULATORY_INFO";
     field public static final java.lang.String ACTION_SOUND_SETTINGS = "android.settings.SOUND_SETTINGS";
     field public static final java.lang.String ACTION_SYNC_SETTINGS = "android.settings.SYNC_SETTINGS";
@@ -33102,6 +33110,7 @@
   public class NetworkSecurityPolicy {
     method public static android.security.NetworkSecurityPolicy getInstance();
     method public boolean isCleartextTrafficPermitted();
+    method public boolean isCleartextTrafficPermitted(java.lang.String);
   }
 
 }
@@ -33494,20 +33503,13 @@
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.ConditionProviderService";
   }
 
-  public class NotificationAdjustment implements android.os.Parcelable {
-    ctor public NotificationAdjustment(int, java.lang.CharSequence, android.net.Uri);
-    method public int describeContents();
-    method public void writeToParcel(android.os.Parcel, int);
-    field public static final android.os.Parcelable.Creator<android.service.notification.NotificationAdjustment> CREATOR;
-  }
-
   public abstract class NotificationAssistantService extends android.service.notification.NotificationListenerService {
     ctor public NotificationAssistantService();
-    method public final void adjustImportance(java.lang.String, android.service.notification.NotificationAdjustment);
+    method public final void adjustImportance(java.lang.String, android.service.notification.NotificationAssistantService.Adjustment);
     method public final void clearAnnotation(java.lang.String);
     method public void onNotificationActionClick(java.lang.String, long, int);
     method public void onNotificationClick(java.lang.String, long);
-    method public abstract android.service.notification.NotificationAdjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, int, boolean);
+    method public abstract android.service.notification.NotificationAssistantService.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, int, boolean);
     method public void onNotificationRemoved(java.lang.String, long, int);
     method public void onNotificationVisibilityChanged(java.lang.String, long, boolean);
     method public final void setAnnotation(java.lang.String, android.app.Notification);
@@ -33527,6 +33529,10 @@
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
   }
 
+  public class NotificationAssistantService.Adjustment {
+    ctor public NotificationAssistantService.Adjustment(int, java.lang.CharSequence, android.net.Uri);
+  }
+
   public abstract class NotificationListenerService extends android.app.Service {
     ctor public NotificationListenerService();
     method public final void cancelAllNotifications();
@@ -33560,6 +33566,7 @@
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationListenerService";
     field public static final int SUPPRESSED_EFFECT_LIGHTS = 1; // 0x1
     field public static final int SUPPRESSED_EFFECT_PEEK = 2; // 0x2
+    field public static final int SUPPRESSED_EFFECT_SCREEN_ON = 4; // 0x4
   }
 
   public static class NotificationListenerService.Ranking {
@@ -33631,10 +33638,13 @@
     method public void onClick();
     method public void onStartListening();
     method public void onStopListening();
-    method public void onTileAdded();
+    method public int onTileAdded();
     method public void onTileRemoved();
+    method public static final void requestListeningState(android.content.Context, android.content.ComponentName);
     method public final void showDialog(android.app.Dialog);
     field public static final java.lang.String ACTION_QS_TILE = "android.service.quicksettings.action.QS_TILE";
+    field public static final int TILE_MODE_ACTIVE = 2; // 0x2
+    field public static final int TILE_MODE_PASSIVE = 1; // 0x1
   }
 
 }
@@ -34895,6 +34905,7 @@
     field public static final int PROPERTY_GENERIC_CONFERENCE = 2; // 0x2
     field public static final int PROPERTY_HIGH_DEF_AUDIO = 16; // 0x10
     field public static final int PROPERTY_WIFI = 8; // 0x8
+    field public static final int PROPERTY_WORK_CALL = 32; // 0x20
   }
 
   public final class CallAudioState implements android.os.Parcelable {
@@ -36039,6 +36050,7 @@
     method public java.lang.String getSubscriberId();
     method public java.lang.String getVoiceMailAlphaTag();
     method public java.lang.String getVoiceMailNumber();
+    method public android.net.Uri getVoicemailRingtoneUri(android.telecom.PhoneAccountHandle);
     method public boolean hasCarrierPrivileges();
     method public boolean hasIccCard();
     method public boolean iccCloseLogicalChannel(int);
@@ -36051,6 +36063,7 @@
     method public boolean isSmsCapable();
     method public boolean isTtyModeSupported();
     method public boolean isVoiceCapable();
+    method public boolean isVoicemailVibrationEnabled(android.telecom.PhoneAccountHandle);
     method public boolean isWorldPhone();
     method public void listen(android.telephony.PhoneStateListener, int);
     method public java.lang.String sendEnvelopeWithStatus(java.lang.String);
@@ -36733,7 +36746,6 @@
     method public android.graphics.drawable.Drawable getApplicationLogo(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
     method public int getComponentEnabledSetting(android.content.ComponentName);
     method public android.graphics.drawable.Drawable getDefaultActivityIcon();
-    method public java.lang.String getDefaultBrowserPackageName(int);
     method public android.graphics.drawable.Drawable getDrawable(java.lang.String, int, android.content.pm.ApplicationInfo);
     method public byte[] getEphemeralCookie();
     method public int getEphemeralCookieMaxSizeBytes();
@@ -36745,8 +36757,10 @@
     method public android.content.Intent getLeanbackLaunchIntentForPackage(java.lang.String);
     method public java.lang.String getNameForUid(int);
     method public int[] getPackageGids(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
+    method public int[] getPackageGids(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public android.content.pm.PackageInfo getPackageInfo(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public android.content.pm.PackageInstaller getPackageInstaller();
+    method public int getPackageUid(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public java.lang.String[] getPackagesForUid(int);
     method public java.util.List<android.content.pm.PackageInfo> getPackagesHoldingPermissions(java.lang.String[], int);
     method public android.content.pm.PermissionGroupInfo getPermissionGroupInfo(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
@@ -36785,7 +36799,6 @@
     method public android.content.pm.ResolveInfo resolveService(android.content.Intent, int);
     method public void setApplicationEnabledSetting(java.lang.String, int, int);
     method public void setComponentEnabledSetting(android.content.ComponentName, int, int);
-    method public boolean setDefaultBrowserPackageName(java.lang.String, int);
     method public boolean setEphemeralCookie(byte[]);
     method public void setInstallerPackageName(java.lang.String, java.lang.String);
     method public void verifyPendingInstall(int, int);
@@ -39175,7 +39188,7 @@
     method public static final java.lang.String digitsAndPlusOnly(java.util.regex.Matcher);
     field public static final java.util.regex.Pattern DOMAIN_NAME;
     field public static final java.util.regex.Pattern EMAIL_ADDRESS;
-    field public static final java.lang.String GOOD_IRI_CHAR = "a-zA-Z0-9\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef";
+    field public static final deprecated java.lang.String GOOD_IRI_CHAR = "a-zA-Z0-9\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef";
     field public static final java.util.regex.Pattern IP_ADDRESS;
     field public static final java.util.regex.Pattern PHONE;
     field public static final deprecated java.util.regex.Pattern TOP_LEVEL_DOMAIN;
@@ -40554,7 +40567,6 @@
     field public static final int AXIS_RX = 12; // 0xc
     field public static final int AXIS_RY = 13; // 0xd
     field public static final int AXIS_RZ = 14; // 0xe
-    field public static final int AXIS_SCROLL = 26; // 0x1a
     field public static final int AXIS_SIZE = 3; // 0x3
     field public static final int AXIS_THROTTLE = 19; // 0x13
     field public static final int AXIS_TILT = 25; // 0x19
@@ -44041,7 +44053,7 @@
     method public abstract deprecated void setEnableSmoothTransition(boolean);
     method public abstract void setFantasyFontFamily(java.lang.String);
     method public abstract void setFixedFontFamily(java.lang.String);
-    method public abstract void setGeolocationDatabasePath(java.lang.String);
+    method public abstract deprecated void setGeolocationDatabasePath(java.lang.String);
     method public abstract void setGeolocationEnabled(boolean);
     method public abstract void setJavaScriptCanOpenWindowsAutomatically(boolean);
     method public abstract void setJavaScriptEnabled(boolean);
diff --git a/api/removed.txt b/api/removed.txt
index f12e61e..6b7961e 100644
--- a/api/removed.txt
+++ b/api/removed.txt
@@ -199,6 +199,15 @@
 
 }
 
+package android.test.mock {
+
+  public class MockPackageManager extends android.content.pm.PackageManager {
+    method public deprecated java.lang.String getDefaultBrowserPackageName(int);
+    method public deprecated boolean setDefaultBrowserPackageName(java.lang.String, int);
+  }
+
+}
+
 package android.text.format {
 
   public class DateFormat {
diff --git a/api/system-current.txt b/api/system-current.txt
index 27a16bf..669c813 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -93,7 +93,6 @@
     field public static final java.lang.String DUMP = "android.permission.DUMP";
     field public static final java.lang.String EXPAND_STATUS_BAR = "android.permission.EXPAND_STATUS_BAR";
     field public static final java.lang.String FACTORY_TEST = "android.permission.FACTORY_TEST";
-    field public static final java.lang.String FLASHLIGHT = "android.permission.FLASHLIGHT";
     field public static final java.lang.String FORCE_BACK = "android.permission.FORCE_BACK";
     field public static final java.lang.String FORCE_STOP_PACKAGES = "android.permission.FORCE_STOP_PACKAGES";
     field public static final java.lang.String GET_ACCOUNTS = "android.permission.GET_ACCOUNTS";
@@ -4349,7 +4348,7 @@
     field public static final java.lang.String COLUMN_DESCRIPTION = "description";
     field public static final java.lang.String COLUMN_ID = "_id";
     field public static final java.lang.String COLUMN_LAST_MODIFIED_TIMESTAMP = "last_modified_timestamp";
-    field public static final java.lang.String COLUMN_LOCAL_FILENAME = "local_filename";
+    field public static final deprecated java.lang.String COLUMN_LOCAL_FILENAME = "local_filename";
     field public static final java.lang.String COLUMN_LOCAL_URI = "local_uri";
     field public static final java.lang.String COLUMN_MEDIAPROVIDER_URI = "mediaprovider_uri";
     field public static final java.lang.String COLUMN_MEDIA_TYPE = "media_type";
@@ -5318,6 +5317,7 @@
     field public static final int SUPPRESSED_EFFECTS_UNSET = -1; // 0xffffffff
     field public static final int SUPPRESSED_EFFECT_LIGHTS = 1; // 0x1
     field public static final int SUPPRESSED_EFFECT_PEEK = 2; // 0x2
+    field public static final int SUPPRESSED_EFFECT_SCREEN_ON = 4; // 0x4
     field public final int priorityCallSenders;
     field public final int priorityCategories;
     field public final int priorityMessageSenders;
@@ -5886,9 +5886,11 @@
     method public java.lang.String getDeviceOwnerLockScreenInfo();
     method public java.util.List<byte[]> getInstalledCaCerts(android.content.ComponentName);
     method public int getKeyguardDisabledFeatures(android.content.ComponentName);
+    method public java.lang.String getLongSupportMessage(android.content.ComponentName);
     method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
     method public long getMaximumTimeToLock(android.content.ComponentName);
     method public boolean getPackageSuspended(android.content.ComponentName, java.lang.String);
+    method public android.app.admin.DevicePolicyManager getParentProfileInstance(android.content.ComponentName);
     method public long getPasswordExpiration(android.content.ComponentName);
     method public long getPasswordExpirationTimeout(android.content.ComponentName);
     method public int getPasswordHistoryLength(android.content.ComponentName);
@@ -5910,6 +5912,7 @@
     method public android.content.ComponentName getProfileOwner() throws java.lang.IllegalArgumentException;
     method public java.lang.String getProfileOwnerNameAsUser(int) throws java.lang.IllegalArgumentException;
     method public boolean getScreenCaptureDisabled(android.content.ComponentName);
+    method public java.lang.String getShortSupportMessage(android.content.ComponentName);
     method public boolean getStorageEncryption(android.content.ComponentName);
     method public int getStorageEncryptionStatus();
     method public android.app.admin.SystemUpdatePolicy getSystemUpdatePolicy();
@@ -5953,6 +5956,7 @@
     method public boolean setKeyguardDisabled(android.content.ComponentName, boolean);
     method public void setKeyguardDisabledFeatures(android.content.ComponentName, int);
     method public void setLockTaskPackages(android.content.ComponentName, java.lang.String[]) throws java.lang.SecurityException;
+    method public void setLongSupportMessage(android.content.ComponentName, java.lang.String);
     method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
     method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
     method public void setMaximumTimeToLock(android.content.ComponentName, long);
@@ -5977,6 +5981,7 @@
     method public void setRestrictionsProvider(android.content.ComponentName, android.content.ComponentName);
     method public void setScreenCaptureDisabled(android.content.ComponentName, boolean);
     method public void setSecureSetting(android.content.ComponentName, java.lang.String, java.lang.String);
+    method public void setShortSupportMessage(android.content.ComponentName, java.lang.String);
     method public boolean setStatusBarDisabled(android.content.ComponentName, boolean);
     method public int setStorageEncryption(android.content.ComponentName, boolean);
     method public void setSystemUpdatePolicy(android.content.ComponentName, android.app.admin.SystemUpdatePolicy);
@@ -7811,11 +7816,12 @@
     method public abstract void writeDataToPipe(android.os.ParcelFileDescriptor, android.net.Uri, java.lang.String, android.os.Bundle, T);
   }
 
-  public class ContentProviderClient {
+  public class ContentProviderClient implements java.lang.AutoCloseable {
     method public android.content.ContentProviderResult[] applyBatch(java.util.ArrayList<android.content.ContentProviderOperation>) throws android.content.OperationApplicationException, android.os.RemoteException;
     method public int bulkInsert(android.net.Uri, android.content.ContentValues[]) throws android.os.RemoteException;
     method public android.os.Bundle call(java.lang.String, java.lang.String, android.os.Bundle) throws android.os.RemoteException;
     method public final android.net.Uri canonicalize(android.net.Uri) throws android.os.RemoteException;
+    method public void close();
     method public int delete(android.net.Uri, java.lang.String, java.lang.String[]) throws android.os.RemoteException;
     method public android.content.ContentProvider getLocalContentProvider();
     method public java.lang.String[] getStreamTypes(android.net.Uri, java.lang.String) throws android.os.RemoteException;
@@ -7829,7 +7835,7 @@
     method public final android.content.res.AssetFileDescriptor openTypedAssetFileDescriptor(android.net.Uri, java.lang.String, android.os.Bundle, android.os.CancellationSignal) throws java.io.FileNotFoundException, android.os.RemoteException;
     method public android.database.Cursor query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String) throws android.os.RemoteException;
     method public android.database.Cursor query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String, android.os.CancellationSignal) throws android.os.RemoteException;
-    method public boolean release();
+    method public deprecated boolean release();
     method public final android.net.Uri uncanonicalize(android.net.Uri) throws android.os.RemoteException;
     method public int update(android.net.Uri, android.content.ContentValues, java.lang.String, java.lang.String[]) throws android.os.RemoteException;
   }
@@ -9550,12 +9556,6 @@
     method public abstract void onPackagesUnavailable(java.lang.String[], android.os.UserHandle, boolean);
   }
 
-  public class ManifestDigest implements android.os.Parcelable {
-    method public int describeContents();
-    method public void writeToParcel(android.os.Parcel, int);
-    field public static final android.os.Parcelable.Creator<android.content.pm.ManifestDigest> CREATOR;
-  }
-
   public class PackageInfo implements android.os.Parcelable {
     ctor public PackageInfo();
     method public int describeContents();
@@ -9748,8 +9748,10 @@
     method public abstract java.lang.String getNameForUid(int);
     method public android.content.pm.PackageInfo getPackageArchiveInfo(java.lang.String, int);
     method public abstract int[] getPackageGids(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
+    method public abstract int[] getPackageGids(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract android.content.pm.PackageInfo getPackageInfo(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract android.content.pm.PackageInstaller getPackageInstaller();
+    method public abstract int getPackageUid(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract java.lang.String[] getPackagesForUid(int);
     method public abstract java.util.List<android.content.pm.PackageInfo> getPackagesHoldingPermissions(java.lang.String[], int);
     method public abstract int getPermissionFlags(java.lang.String, java.lang.String, android.os.UserHandle);
@@ -9829,6 +9831,7 @@
     field public static final java.lang.String FEATURE_CONNECTION_SERVICE = "android.software.connectionservice";
     field public static final java.lang.String FEATURE_CONSUMER_IR = "android.hardware.consumerir";
     field public static final java.lang.String FEATURE_DEVICE_ADMIN = "android.software.device_admin";
+    field public static final java.lang.String FEATURE_ETHERNET = "android.hardware.ethernet";
     field public static final java.lang.String FEATURE_FAKETOUCH = "android.hardware.faketouch";
     field public static final java.lang.String FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT = "android.hardware.faketouch.multitouch.distinct";
     field public static final java.lang.String FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND = "android.hardware.faketouch.multitouch.jazzhand";
@@ -9887,8 +9890,8 @@
     field public static final java.lang.String FEATURE_WIFI_DIRECT = "android.hardware.wifi.direct";
     field public static final int GET_ACTIVITIES = 1; // 0x1
     field public static final int GET_CONFIGURATIONS = 16384; // 0x4000
-    field public static final int GET_DISABLED_COMPONENTS = 512; // 0x200
-    field public static final int GET_DISABLED_UNTIL_USED_COMPONENTS = 32768; // 0x8000
+    field public static final deprecated int GET_DISABLED_COMPONENTS = 512; // 0x200
+    field public static final deprecated int GET_DISABLED_UNTIL_USED_COMPONENTS = 32768; // 0x8000
     field public static final int GET_GIDS = 256; // 0x100
     field public static final int GET_INSTRUMENTATION = 16; // 0x10
     field public static final int GET_INTENT_FILTERS = 32; // 0x20
@@ -9900,7 +9903,7 @@
     field public static final int GET_SERVICES = 4; // 0x4
     field public static final int GET_SHARED_LIBRARY_FILES = 1024; // 0x400
     field public static final int GET_SIGNATURES = 64; // 0x40
-    field public static final int GET_UNINSTALLED_PACKAGES = 8192; // 0x2000
+    field public static final deprecated int GET_UNINSTALLED_PACKAGES = 8192; // 0x2000
     field public static final int GET_URI_PERMISSION_PATTERNS = 2048; // 0x800
     field public static final int INSTALL_FAILED_ALREADY_EXISTS = -1; // 0xffffffff
     field public static final int INSTALL_FAILED_CONFLICTING_PROVIDER = -13; // 0xfffffff3
@@ -9941,9 +9944,13 @@
     field public static final int MASK_PERMISSION_FLAGS = 255; // 0xff
     field public static final int MATCH_ALL = 131072; // 0x20000
     field public static final int MATCH_DEFAULT_ONLY = 65536; // 0x10000
+    field public static final int MATCH_DISABLED_COMPONENTS = 512; // 0x200
+    field public static final int MATCH_DISABLED_UNTIL_USED_COMPONENTS = 32768; // 0x8000
+    field public static final int MATCH_ENCRYPTION_AWARE = 524288; // 0x80000
     field public static final int MATCH_ENCRYPTION_AWARE_AND_UNAWARE = 786432; // 0xc0000
-    field public static final int MATCH_ENCRYPTION_AWARE_ONLY = 524288; // 0x80000
-    field public static final int MATCH_ENCRYPTION_UNAWARE_ONLY = 262144; // 0x40000
+    field public static final int MATCH_ENCRYPTION_UNAWARE = 262144; // 0x40000
+    field public static final int MATCH_SYSTEM_ONLY = 1048576; // 0x100000
+    field public static final int MATCH_UNINSTALLED_PACKAGES = 8192; // 0x2000
     field public static final long MAXIMUM_VERIFICATION_TIMEOUT = 3600000L; // 0x36ee80L
     field public static final int PERMISSION_DENIED = -1; // 0xffffffff
     field public static final int PERMISSION_GRANTED = 0; // 0x0
@@ -11200,7 +11207,7 @@
     field public final int statusCode;
   }
 
-  public class DrmManagerClient {
+  public class DrmManagerClient implements java.lang.AutoCloseable {
     ctor public DrmManagerClient(android.content.Context);
     method public android.drm.DrmInfo acquireDrmInfo(android.drm.DrmInfoRequest);
     method public int acquireRights(android.drm.DrmInfoRequest);
@@ -11210,6 +11217,7 @@
     method public int checkRightsStatus(android.net.Uri);
     method public int checkRightsStatus(java.lang.String, int);
     method public int checkRightsStatus(android.net.Uri, int);
+    method public void close();
     method public android.drm.DrmConvertedStatus closeConvertSession(int);
     method public android.drm.DrmConvertedStatus convertData(int, byte[]);
     method public java.lang.String[] getAvailableDrmEngines();
@@ -11223,7 +11231,7 @@
     method public java.lang.String getOriginalMimeType(android.net.Uri);
     method public int openConvertSession(java.lang.String);
     method public int processDrmInfo(android.drm.DrmInfo);
-    method public void release();
+    method public deprecated void release();
     method public int removeAllRights();
     method public int removeRights(java.lang.String);
     method public int removeRights(android.net.Uri);
@@ -11627,14 +11635,14 @@
 
   public static class BitmapFactory.Options {
     ctor public BitmapFactory.Options();
-    method public void requestCancelDecode();
+    method public deprecated void requestCancelDecode();
     field public android.graphics.Bitmap inBitmap;
     field public int inDensity;
-    field public boolean inDither;
+    field public deprecated boolean inDither;
     field public deprecated boolean inInputShareable;
     field public boolean inJustDecodeBounds;
     field public boolean inMutable;
-    field public boolean inPreferQualityOverSpeed;
+    field public deprecated boolean inPreferQualityOverSpeed;
     field public android.graphics.Bitmap.Config inPreferredConfig;
     field public boolean inPremultiplied;
     field public deprecated boolean inPurgeable;
@@ -19230,7 +19238,6 @@
     method public static java.lang.String getCanonicalID(java.lang.String, boolean[]);
     method public int getDSTSavings();
     method public static android.icu.util.TimeZone getDefault();
-    method public static int getDefaultTimeZoneType();
     method public final java.lang.String getDisplayName();
     method public final java.lang.String getDisplayName(java.util.Locale);
     method public final java.lang.String getDisplayName(android.icu.util.ULocale);
@@ -19254,8 +19261,6 @@
     method public abstract boolean inDaylightTime(java.util.Date);
     method public boolean isFrozen();
     method public boolean observesDaylightTime();
-    method public static synchronized void setDefault(android.icu.util.TimeZone);
-    method public static synchronized void setDefaultTimeZoneType(int);
     method public void setID(java.lang.String);
     method public abstract void setRawOffset(int);
     method public abstract boolean useDaylightTime();
@@ -19268,8 +19273,6 @@
     field public static final int SHORT_COMMONLY_USED = 6; // 0x6
     field public static final int SHORT_GENERIC = 2; // 0x2
     field public static final int SHORT_GMT = 4; // 0x4
-    field public static final int TIMEZONE_ICU = 0; // 0x0
-    field public static final int TIMEZONE_JDK = 1; // 0x1
     field public static final android.icu.util.TimeZone UNKNOWN_ZONE;
     field public static final java.lang.String UNKNOWN_ZONE_ID = "Etc/Unknown";
   }
@@ -19365,8 +19368,6 @@
     method public static java.lang.String getVariant(java.lang.String);
     method public boolean isRightToLeft();
     method public static android.icu.util.ULocale minimizeSubtags(android.icu.util.ULocale);
-    method public static synchronized void setDefault(android.icu.util.ULocale);
-    method public static synchronized void setDefault(android.icu.util.ULocale.Category, android.icu.util.ULocale);
     method public android.icu.util.ULocale setKeywordValue(java.lang.String, java.lang.String);
     method public static java.lang.String setKeywordValue(java.lang.String, java.lang.String, java.lang.String);
     method public java.lang.String toLanguageTag();
@@ -24000,6 +24001,7 @@
     method public int[] getObjectHandles(int, int, int);
     method public android.mtp.MtpObjectInfo getObjectInfo(int);
     method public long getParent(int);
+    method public int getPartialObject(int, int, int, byte[]) throws java.io.IOException;
     method public long getStorageId(int);
     method public int[] getStorageIds();
     method public android.mtp.MtpStorageInfo getStorageInfo(int);
@@ -32813,7 +32815,7 @@
     field public static final java.lang.String COLUMN_MIME_TYPE = "mime_type";
     field public static final java.lang.String COLUMN_SIZE = "_size";
     field public static final java.lang.String COLUMN_SUMMARY = "summary";
-    field public static final int FLAG_ARCHIVE = 2048; // 0x800
+    field public static final int FLAG_ARCHIVE = 1024; // 0x400
     field public static final int FLAG_DIR_PREFERS_GRID = 16; // 0x10
     field public static final int FLAG_DIR_PREFERS_LAST_MODIFIED = 32; // 0x20
     field public static final int FLAG_DIR_SUPPORTS_CREATE = 8; // 0x8
@@ -32822,9 +32824,8 @@
     field public static final int FLAG_SUPPORTS_MOVE = 256; // 0x100
     field public static final int FLAG_SUPPORTS_RENAME = 64; // 0x40
     field public static final int FLAG_SUPPORTS_THUMBNAIL = 1; // 0x1
-    field public static final int FLAG_SUPPORTS_TYPED_DOCUMENT = 512; // 0x200
     field public static final int FLAG_SUPPORTS_WRITE = 2; // 0x2
-    field public static final int FLAG_VIRTUAL_DOCUMENT = 1024; // 0x400
+    field public static final int FLAG_VIRTUAL_DOCUMENT = 512; // 0x200
     field public static final java.lang.String MIME_TYPE_DIR = "vnd.android.document/directory";
   }
 
@@ -33370,6 +33371,7 @@
     field public static final java.lang.String ACTION_SEARCH_SETTINGS = "android.search.action.SEARCH_SETTINGS";
     field public static final java.lang.String ACTION_SECURITY_SETTINGS = "android.settings.SECURITY_SETTINGS";
     field public static final java.lang.String ACTION_SETTINGS = "android.settings.SETTINGS";
+    field public static final java.lang.String ACTION_SHOW_ADMIN_SUPPORT_DETAILS = "android.settings.SHOW_ADMIN_SUPPORT_DETAILS";
     field public static final java.lang.String ACTION_SHOW_REGULATORY_INFO = "android.settings.SHOW_REGULATORY_INFO";
     field public static final java.lang.String ACTION_SOUND_SETTINGS = "android.settings.SOUND_SETTINGS";
     field public static final java.lang.String ACTION_SYNC_SETTINGS = "android.settings.SYNC_SETTINGS";
@@ -35244,6 +35246,7 @@
   public class NetworkSecurityPolicy {
     method public static android.security.NetworkSecurityPolicy getInstance();
     method public boolean isCleartextTrafficPermitted();
+    method public boolean isCleartextTrafficPermitted(java.lang.String);
   }
 
 }
@@ -35636,20 +35639,13 @@
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.ConditionProviderService";
   }
 
-  public class NotificationAdjustment implements android.os.Parcelable {
-    ctor public NotificationAdjustment(int, java.lang.CharSequence, android.net.Uri);
-    method public int describeContents();
-    method public void writeToParcel(android.os.Parcel, int);
-    field public static final android.os.Parcelable.Creator<android.service.notification.NotificationAdjustment> CREATOR;
-  }
-
   public abstract class NotificationAssistantService extends android.service.notification.NotificationListenerService {
     ctor public NotificationAssistantService();
-    method public final void adjustImportance(java.lang.String, android.service.notification.NotificationAdjustment);
+    method public final void adjustImportance(java.lang.String, android.service.notification.NotificationAssistantService.Adjustment);
     method public final void clearAnnotation(java.lang.String);
     method public void onNotificationActionClick(java.lang.String, long, int);
     method public void onNotificationClick(java.lang.String, long);
-    method public abstract android.service.notification.NotificationAdjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, int, boolean);
+    method public abstract android.service.notification.NotificationAssistantService.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, int, boolean);
     method public void onNotificationRemoved(java.lang.String, long, int);
     method public void onNotificationVisibilityChanged(java.lang.String, long, boolean);
     method public final void setAnnotation(java.lang.String, android.app.Notification);
@@ -35669,6 +35665,10 @@
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
   }
 
+  public class NotificationAssistantService.Adjustment {
+    ctor public NotificationAssistantService.Adjustment(int, java.lang.CharSequence, android.net.Uri);
+  }
+
   public abstract class NotificationListenerService extends android.app.Service {
     ctor public NotificationListenerService();
     method public final void cancelAllNotifications();
@@ -35707,6 +35707,7 @@
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationListenerService";
     field public static final int SUPPRESSED_EFFECT_LIGHTS = 1; // 0x1
     field public static final int SUPPRESSED_EFFECT_PEEK = 2; // 0x2
+    field public static final int SUPPRESSED_EFFECT_SCREEN_ON = 4; // 0x4
     field public static final int TRIM_FULL = 0; // 0x0
     field public static final int TRIM_LIGHT = 1; // 0x1
   }
@@ -35805,10 +35806,13 @@
     method public void onClick();
     method public void onStartListening();
     method public void onStopListening();
-    method public void onTileAdded();
+    method public int onTileAdded();
     method public void onTileRemoved();
+    method public static final void requestListeningState(android.content.Context, android.content.ComponentName);
     method public final void showDialog(android.app.Dialog);
     field public static final java.lang.String ACTION_QS_TILE = "android.service.quicksettings.action.QS_TILE";
+    field public static final int TILE_MODE_ACTIVE = 2; // 0x2
+    field public static final int TILE_MODE_PASSIVE = 1; // 0x1
   }
 
 }
@@ -37112,6 +37116,7 @@
     field public static final int PROPERTY_GENERIC_CONFERENCE = 2; // 0x2
     field public static final int PROPERTY_HIGH_DEF_AUDIO = 16; // 0x10
     field public static final int PROPERTY_WIFI = 8; // 0x8
+    field public static final int PROPERTY_WORK_CALL = 32; // 0x20
   }
 
   public static abstract deprecated class Call.Listener extends android.telecom.Call.Callback {
@@ -38346,6 +38351,7 @@
     method public java.lang.String getSubscriberId();
     method public java.lang.String getVoiceMailAlphaTag();
     method public java.lang.String getVoiceMailNumber();
+    method public android.net.Uri getVoicemailRingtoneUri(android.telecom.PhoneAccountHandle);
     method public boolean handlePinMmi(java.lang.String);
     method public boolean handlePinMmiForSubscriber(int, java.lang.String);
     method public boolean hasCarrierPrivileges();
@@ -38367,6 +38373,7 @@
     method public boolean isTtyModeSupported();
     method public boolean isVideoCallingEnabled();
     method public boolean isVoiceCapable();
+    method public boolean isVoicemailVibrationEnabled(android.telecom.PhoneAccountHandle);
     method public boolean isWorldPhone();
     method public void listen(android.telephony.PhoneStateListener, int);
     method public boolean needsOtaServiceProvisioning();
@@ -39080,7 +39087,6 @@
     method public android.graphics.drawable.Drawable getApplicationLogo(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
     method public int getComponentEnabledSetting(android.content.ComponentName);
     method public android.graphics.drawable.Drawable getDefaultActivityIcon();
-    method public java.lang.String getDefaultBrowserPackageName(int);
     method public android.graphics.drawable.Drawable getDrawable(java.lang.String, int, android.content.pm.ApplicationInfo);
     method public byte[] getEphemeralCookie();
     method public int getEphemeralCookieMaxSizeBytes();
@@ -39092,8 +39098,10 @@
     method public android.content.Intent getLeanbackLaunchIntentForPackage(java.lang.String);
     method public java.lang.String getNameForUid(int);
     method public int[] getPackageGids(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
+    method public int[] getPackageGids(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public android.content.pm.PackageInfo getPackageInfo(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public android.content.pm.PackageInstaller getPackageInstaller();
+    method public int getPackageUid(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public java.lang.String[] getPackagesForUid(int);
     method public java.util.List<android.content.pm.PackageInfo> getPackagesHoldingPermissions(java.lang.String[], int);
     method public int getPermissionFlags(java.lang.String, java.lang.String, android.os.UserHandle);
@@ -39136,7 +39144,6 @@
     method public void revokeRuntimePermission(java.lang.String, java.lang.String, android.os.UserHandle);
     method public void setApplicationEnabledSetting(java.lang.String, int, int);
     method public void setComponentEnabledSetting(android.content.ComponentName, int, int);
-    method public boolean setDefaultBrowserPackageName(java.lang.String, int);
     method public boolean setEphemeralCookie(byte[]);
     method public void setInstallerPackageName(java.lang.String, java.lang.String);
     method public void updatePermissionFlags(java.lang.String, java.lang.String, int, int, android.os.UserHandle);
@@ -41528,7 +41535,7 @@
     method public static final java.lang.String digitsAndPlusOnly(java.util.regex.Matcher);
     field public static final java.util.regex.Pattern DOMAIN_NAME;
     field public static final java.util.regex.Pattern EMAIL_ADDRESS;
-    field public static final java.lang.String GOOD_IRI_CHAR = "a-zA-Z0-9\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef";
+    field public static final deprecated java.lang.String GOOD_IRI_CHAR = "a-zA-Z0-9\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef";
     field public static final java.util.regex.Pattern IP_ADDRESS;
     field public static final java.util.regex.Pattern PHONE;
     field public static final deprecated java.util.regex.Pattern TOP_LEVEL_DOMAIN;
@@ -42907,7 +42914,6 @@
     field public static final int AXIS_RX = 12; // 0xc
     field public static final int AXIS_RY = 13; // 0xd
     field public static final int AXIS_RZ = 14; // 0xe
-    field public static final int AXIS_SCROLL = 26; // 0x1a
     field public static final int AXIS_SIZE = 3; // 0x3
     field public static final int AXIS_THROTTLE = 19; // 0x13
     field public static final int AXIS_TILT = 25; // 0x19
@@ -46465,7 +46471,7 @@
     method public abstract deprecated void setEnableSmoothTransition(boolean);
     method public abstract void setFantasyFontFamily(java.lang.String);
     method public abstract void setFixedFontFamily(java.lang.String);
-    method public abstract void setGeolocationDatabasePath(java.lang.String);
+    method public abstract deprecated void setGeolocationDatabasePath(java.lang.String);
     method public abstract void setGeolocationEnabled(boolean);
     method public abstract void setJavaScriptCanOpenWindowsAutomatically(boolean);
     method public abstract void setJavaScriptEnabled(boolean);
diff --git a/api/system-removed.txt b/api/system-removed.txt
index 642d2a8..90a5dc7 100644
--- a/api/system-removed.txt
+++ b/api/system-removed.txt
@@ -190,6 +190,15 @@
 
 }
 
+package android.test.mock {
+
+  public class MockPackageManager extends android.content.pm.PackageManager {
+    method public deprecated java.lang.String getDefaultBrowserPackageName(int);
+    method public deprecated boolean setDefaultBrowserPackageName(java.lang.String, int);
+  }
+
+}
+
 package android.text.format {
 
   public class DateFormat {
diff --git a/api/test-current.txt b/api/test-current.txt
index cee8fad..e8fe5fe 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -67,7 +67,6 @@
     field public static final java.lang.String DUMP = "android.permission.DUMP";
     field public static final java.lang.String EXPAND_STATUS_BAR = "android.permission.EXPAND_STATUS_BAR";
     field public static final java.lang.String FACTORY_TEST = "android.permission.FACTORY_TEST";
-    field public static final java.lang.String FLASHLIGHT = "android.permission.FLASHLIGHT";
     field public static final java.lang.String GET_ACCOUNTS = "android.permission.GET_ACCOUNTS";
     field public static final java.lang.String GET_ACCOUNTS_PRIVILEGED = "android.permission.GET_ACCOUNTS_PRIVILEGED";
     field public static final java.lang.String GET_PACKAGE_SIZE = "android.permission.GET_PACKAGE_SIZE";
@@ -4229,7 +4228,7 @@
     field public static final java.lang.String COLUMN_DESCRIPTION = "description";
     field public static final java.lang.String COLUMN_ID = "_id";
     field public static final java.lang.String COLUMN_LAST_MODIFIED_TIMESTAMP = "last_modified_timestamp";
-    field public static final java.lang.String COLUMN_LOCAL_FILENAME = "local_filename";
+    field public static final deprecated java.lang.String COLUMN_LOCAL_FILENAME = "local_filename";
     field public static final java.lang.String COLUMN_LOCAL_URI = "local_uri";
     field public static final java.lang.String COLUMN_MEDIAPROVIDER_URI = "mediaprovider_uri";
     field public static final java.lang.String COLUMN_MEDIA_TYPE = "media_type";
@@ -5198,6 +5197,7 @@
     field public static final int SUPPRESSED_EFFECTS_UNSET = -1; // 0xffffffff
     field public static final int SUPPRESSED_EFFECT_LIGHTS = 1; // 0x1
     field public static final int SUPPRESSED_EFFECT_PEEK = 2; // 0x2
+    field public static final int SUPPRESSED_EFFECT_SCREEN_ON = 4; // 0x4
     field public final int priorityCallSenders;
     field public final int priorityCategories;
     field public final int priorityMessageSenders;
@@ -5501,8 +5501,10 @@
     method public android.view.WindowAnimationFrameStats getWindowAnimationFrameStats();
     method public android.view.WindowContentFrameStats getWindowContentFrameStats(int);
     method public java.util.List<android.view.accessibility.AccessibilityWindowInfo> getWindows();
+    method public boolean grantRuntimePermission(java.lang.String, java.lang.String, android.os.UserHandle);
     method public boolean injectInputEvent(android.view.InputEvent, boolean);
     method public final boolean performGlobalAction(int);
+    method public boolean revokeRuntimePermission(java.lang.String, java.lang.String, android.os.UserHandle);
     method public void setOnAccessibilityEventListener(android.app.UiAutomation.OnAccessibilityEventListener);
     method public boolean setRotation(int);
     method public void setRunAsMonkey(boolean);
@@ -5758,9 +5760,11 @@
     method public java.lang.String getDeviceOwnerLockScreenInfo();
     method public java.util.List<byte[]> getInstalledCaCerts(android.content.ComponentName);
     method public int getKeyguardDisabledFeatures(android.content.ComponentName);
+    method public java.lang.String getLongSupportMessage(android.content.ComponentName);
     method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
     method public long getMaximumTimeToLock(android.content.ComponentName);
     method public boolean getPackageSuspended(android.content.ComponentName, java.lang.String);
+    method public android.app.admin.DevicePolicyManager getParentProfileInstance(android.content.ComponentName);
     method public long getPasswordExpiration(android.content.ComponentName);
     method public long getPasswordExpirationTimeout(android.content.ComponentName);
     method public int getPasswordHistoryLength(android.content.ComponentName);
@@ -5778,6 +5782,7 @@
     method public java.util.List<java.lang.String> getPermittedAccessibilityServices(android.content.ComponentName);
     method public java.util.List<java.lang.String> getPermittedInputMethods(android.content.ComponentName);
     method public boolean getScreenCaptureDisabled(android.content.ComponentName);
+    method public java.lang.String getShortSupportMessage(android.content.ComponentName);
     method public boolean getStorageEncryption(android.content.ComponentName);
     method public int getStorageEncryptionStatus();
     method public android.app.admin.SystemUpdatePolicy getSystemUpdatePolicy();
@@ -5819,6 +5824,7 @@
     method public boolean setKeyguardDisabled(android.content.ComponentName, boolean);
     method public void setKeyguardDisabledFeatures(android.content.ComponentName, int);
     method public void setLockTaskPackages(android.content.ComponentName, java.lang.String[]) throws java.lang.SecurityException;
+    method public void setLongSupportMessage(android.content.ComponentName, java.lang.String);
     method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
     method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
     method public void setMaximumTimeToLock(android.content.ComponentName, long);
@@ -5843,6 +5849,7 @@
     method public void setRestrictionsProvider(android.content.ComponentName, android.content.ComponentName);
     method public void setScreenCaptureDisabled(android.content.ComponentName, boolean);
     method public void setSecureSetting(android.content.ComponentName, java.lang.String, java.lang.String);
+    method public void setShortSupportMessage(android.content.ComponentName, java.lang.String);
     method public boolean setStatusBarDisabled(android.content.ComponentName, boolean);
     method public int setStorageEncryption(android.content.ComponentName, boolean);
     method public void setSystemUpdatePolicy(android.content.ComponentName, android.app.admin.SystemUpdatePolicy);
@@ -7568,11 +7575,12 @@
     method public abstract void writeDataToPipe(android.os.ParcelFileDescriptor, android.net.Uri, java.lang.String, android.os.Bundle, T);
   }
 
-  public class ContentProviderClient {
+  public class ContentProviderClient implements java.lang.AutoCloseable {
     method public android.content.ContentProviderResult[] applyBatch(java.util.ArrayList<android.content.ContentProviderOperation>) throws android.content.OperationApplicationException, android.os.RemoteException;
     method public int bulkInsert(android.net.Uri, android.content.ContentValues[]) throws android.os.RemoteException;
     method public android.os.Bundle call(java.lang.String, java.lang.String, android.os.Bundle) throws android.os.RemoteException;
     method public final android.net.Uri canonicalize(android.net.Uri) throws android.os.RemoteException;
+    method public void close();
     method public int delete(android.net.Uri, java.lang.String, java.lang.String[]) throws android.os.RemoteException;
     method public android.content.ContentProvider getLocalContentProvider();
     method public java.lang.String[] getStreamTypes(android.net.Uri, java.lang.String) throws android.os.RemoteException;
@@ -7586,7 +7594,7 @@
     method public final android.content.res.AssetFileDescriptor openTypedAssetFileDescriptor(android.net.Uri, java.lang.String, android.os.Bundle, android.os.CancellationSignal) throws java.io.FileNotFoundException, android.os.RemoteException;
     method public android.database.Cursor query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String) throws android.os.RemoteException;
     method public android.database.Cursor query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String, android.os.CancellationSignal) throws android.os.RemoteException;
-    method public boolean release();
+    method public deprecated boolean release();
     method public final android.net.Uri uncanonicalize(android.net.Uri) throws android.os.RemoteException;
     method public int update(android.net.Uri, android.content.ContentValues, java.lang.String, java.lang.String[]) throws android.os.RemoteException;
   }
@@ -7668,6 +7676,7 @@
     method public static java.util.List<android.content.PeriodicSync> getPeriodicSyncs(android.accounts.Account, java.lang.String);
     method public java.util.List<android.content.UriPermission> getPersistedUriPermissions();
     method public java.lang.String[] getStreamTypes(android.net.Uri, java.lang.String);
+    method public static java.lang.String[] getSyncAdapterPackagesForAuthorityAsUser(java.lang.String, int);
     method public static android.content.SyncAdapterType[] getSyncAdapterTypes();
     method public static boolean getSyncAutomatically(android.accounts.Account, java.lang.String);
     method public final java.lang.String getType(android.net.Uri);
@@ -7834,6 +7843,7 @@
     method public abstract java.lang.String getSystemServiceName(java.lang.Class<?>);
     method public final java.lang.CharSequence getText(int);
     method public abstract android.content.res.Resources.Theme getTheme();
+    method public abstract int getUserId();
     method public abstract deprecated android.graphics.drawable.Drawable getWallpaper();
     method public abstract deprecated int getWallpaperDesiredMinimumHeight();
     method public abstract deprecated int getWallpaperDesiredMinimumWidth();
@@ -8016,6 +8026,7 @@
     method public java.lang.Object getSystemService(java.lang.String);
     method public java.lang.String getSystemServiceName(java.lang.Class<?>);
     method public android.content.res.Resources.Theme getTheme();
+    method public int getUserId();
     method public deprecated android.graphics.drawable.Drawable getWallpaper();
     method public deprecated int getWallpaperDesiredMinimumHeight();
     method public deprecated int getWallpaperDesiredMinimumWidth();
@@ -9068,6 +9079,8 @@
     ctor public ApplicationInfo(android.content.pm.ApplicationInfo);
     method public int describeContents();
     method public void dump(android.util.Printer, java.lang.String);
+    method public boolean isPrivilegedApp();
+    method public boolean isSystemApp();
     method public java.lang.CharSequence loadDescription(android.content.pm.PackageManager);
     field public static final android.os.Parcelable.Creator<android.content.pm.ApplicationInfo> CREATOR;
     field public static final int FLAG_ALLOW_BACKUP = 32768; // 0x8000
@@ -9429,6 +9442,7 @@
     method public abstract android.graphics.drawable.Drawable getApplicationLogo(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract int getComponentEnabledSetting(android.content.ComponentName);
     method public abstract android.graphics.drawable.Drawable getDefaultActivityIcon();
+    method public abstract java.lang.String getDefaultBrowserPackageNameAsUser(int);
     method public abstract android.graphics.drawable.Drawable getDrawable(java.lang.String, int, android.content.pm.ApplicationInfo);
     method public abstract byte[] getEphemeralCookie();
     method public abstract int getEphemeralCookieMaxSizeBytes();
@@ -9441,8 +9455,10 @@
     method public abstract java.lang.String getNameForUid(int);
     method public android.content.pm.PackageInfo getPackageArchiveInfo(java.lang.String, int);
     method public abstract int[] getPackageGids(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
+    method public abstract int[] getPackageGids(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract android.content.pm.PackageInfo getPackageInfo(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract android.content.pm.PackageInstaller getPackageInstaller();
+    method public abstract int getPackageUid(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract java.lang.String[] getPackagesForUid(int);
     method public abstract java.util.List<android.content.pm.PackageInfo> getPackagesHoldingPermissions(java.lang.String[], int);
     method public abstract android.content.pm.PermissionGroupInfo getPermissionGroupInfo(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
@@ -9513,6 +9529,7 @@
     field public static final java.lang.String FEATURE_CONNECTION_SERVICE = "android.software.connectionservice";
     field public static final java.lang.String FEATURE_CONSUMER_IR = "android.hardware.consumerir";
     field public static final java.lang.String FEATURE_DEVICE_ADMIN = "android.software.device_admin";
+    field public static final java.lang.String FEATURE_ETHERNET = "android.hardware.ethernet";
     field public static final java.lang.String FEATURE_FAKETOUCH = "android.hardware.faketouch";
     field public static final java.lang.String FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT = "android.hardware.faketouch.multitouch.distinct";
     field public static final java.lang.String FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND = "android.hardware.faketouch.multitouch.jazzhand";
@@ -9571,8 +9588,8 @@
     field public static final java.lang.String FEATURE_WIFI_DIRECT = "android.hardware.wifi.direct";
     field public static final int GET_ACTIVITIES = 1; // 0x1
     field public static final int GET_CONFIGURATIONS = 16384; // 0x4000
-    field public static final int GET_DISABLED_COMPONENTS = 512; // 0x200
-    field public static final int GET_DISABLED_UNTIL_USED_COMPONENTS = 32768; // 0x8000
+    field public static final deprecated int GET_DISABLED_COMPONENTS = 512; // 0x200
+    field public static final deprecated int GET_DISABLED_UNTIL_USED_COMPONENTS = 32768; // 0x8000
     field public static final int GET_GIDS = 256; // 0x100
     field public static final int GET_INSTRUMENTATION = 16; // 0x10
     field public static final int GET_INTENT_FILTERS = 32; // 0x20
@@ -9584,13 +9601,17 @@
     field public static final int GET_SERVICES = 4; // 0x4
     field public static final int GET_SHARED_LIBRARY_FILES = 1024; // 0x400
     field public static final int GET_SIGNATURES = 64; // 0x40
-    field public static final int GET_UNINSTALLED_PACKAGES = 8192; // 0x2000
+    field public static final deprecated int GET_UNINSTALLED_PACKAGES = 8192; // 0x2000
     field public static final int GET_URI_PERMISSION_PATTERNS = 2048; // 0x800
     field public static final int MATCH_ALL = 131072; // 0x20000
     field public static final int MATCH_DEFAULT_ONLY = 65536; // 0x10000
+    field public static final int MATCH_DISABLED_COMPONENTS = 512; // 0x200
+    field public static final int MATCH_DISABLED_UNTIL_USED_COMPONENTS = 32768; // 0x8000
+    field public static final int MATCH_ENCRYPTION_AWARE = 524288; // 0x80000
     field public static final int MATCH_ENCRYPTION_AWARE_AND_UNAWARE = 786432; // 0xc0000
-    field public static final int MATCH_ENCRYPTION_AWARE_ONLY = 524288; // 0x80000
-    field public static final int MATCH_ENCRYPTION_UNAWARE_ONLY = 262144; // 0x40000
+    field public static final int MATCH_ENCRYPTION_UNAWARE = 262144; // 0x40000
+    field public static final int MATCH_SYSTEM_ONLY = 1048576; // 0x100000
+    field public static final int MATCH_UNINSTALLED_PACKAGES = 8192; // 0x2000
     field public static final long MAXIMUM_VERIFICATION_TIMEOUT = 3600000L; // 0x36ee80L
     field public static final int PERMISSION_DENIED = -1; // 0xffffffff
     field public static final int PERMISSION_GRANTED = 0; // 0x0
@@ -10840,7 +10861,7 @@
     field public final int statusCode;
   }
 
-  public class DrmManagerClient {
+  public class DrmManagerClient implements java.lang.AutoCloseable {
     ctor public DrmManagerClient(android.content.Context);
     method public android.drm.DrmInfo acquireDrmInfo(android.drm.DrmInfoRequest);
     method public int acquireRights(android.drm.DrmInfoRequest);
@@ -10850,6 +10871,7 @@
     method public int checkRightsStatus(android.net.Uri);
     method public int checkRightsStatus(java.lang.String, int);
     method public int checkRightsStatus(android.net.Uri, int);
+    method public void close();
     method public android.drm.DrmConvertedStatus closeConvertSession(int);
     method public android.drm.DrmConvertedStatus convertData(int, byte[]);
     method public java.lang.String[] getAvailableDrmEngines();
@@ -10863,7 +10885,7 @@
     method public java.lang.String getOriginalMimeType(android.net.Uri);
     method public int openConvertSession(java.lang.String);
     method public int processDrmInfo(android.drm.DrmInfo);
-    method public void release();
+    method public deprecated void release();
     method public int removeAllRights();
     method public int removeRights(java.lang.String);
     method public int removeRights(android.net.Uri);
@@ -11267,14 +11289,14 @@
 
   public static class BitmapFactory.Options {
     ctor public BitmapFactory.Options();
-    method public void requestCancelDecode();
+    method public deprecated void requestCancelDecode();
     field public android.graphics.Bitmap inBitmap;
     field public int inDensity;
-    field public boolean inDither;
+    field public deprecated boolean inDither;
     field public deprecated boolean inInputShareable;
     field public boolean inJustDecodeBounds;
     field public boolean inMutable;
-    field public boolean inPreferQualityOverSpeed;
+    field public deprecated boolean inPreferQualityOverSpeed;
     field public android.graphics.Bitmap.Config inPreferredConfig;
     field public boolean inPremultiplied;
     field public deprecated boolean inPurgeable;
@@ -18243,7 +18265,6 @@
     method public static java.lang.String getCanonicalID(java.lang.String, boolean[]);
     method public int getDSTSavings();
     method public static android.icu.util.TimeZone getDefault();
-    method public static int getDefaultTimeZoneType();
     method public final java.lang.String getDisplayName();
     method public final java.lang.String getDisplayName(java.util.Locale);
     method public final java.lang.String getDisplayName(android.icu.util.ULocale);
@@ -18267,8 +18288,6 @@
     method public abstract boolean inDaylightTime(java.util.Date);
     method public boolean isFrozen();
     method public boolean observesDaylightTime();
-    method public static synchronized void setDefault(android.icu.util.TimeZone);
-    method public static synchronized void setDefaultTimeZoneType(int);
     method public void setID(java.lang.String);
     method public abstract void setRawOffset(int);
     method public abstract boolean useDaylightTime();
@@ -18281,8 +18300,6 @@
     field public static final int SHORT_COMMONLY_USED = 6; // 0x6
     field public static final int SHORT_GENERIC = 2; // 0x2
     field public static final int SHORT_GMT = 4; // 0x4
-    field public static final int TIMEZONE_ICU = 0; // 0x0
-    field public static final int TIMEZONE_JDK = 1; // 0x1
     field public static final android.icu.util.TimeZone UNKNOWN_ZONE;
     field public static final java.lang.String UNKNOWN_ZONE_ID = "Etc/Unknown";
   }
@@ -18378,8 +18395,6 @@
     method public static java.lang.String getVariant(java.lang.String);
     method public boolean isRightToLeft();
     method public static android.icu.util.ULocale minimizeSubtags(android.icu.util.ULocale);
-    method public static synchronized void setDefault(android.icu.util.ULocale);
-    method public static synchronized void setDefault(android.icu.util.ULocale.Category, android.icu.util.ULocale);
     method public android.icu.util.ULocale setKeywordValue(java.lang.String, java.lang.String);
     method public static java.lang.String setKeywordValue(java.lang.String, java.lang.String, java.lang.String);
     method public java.lang.String toLanguageTag();
@@ -22448,6 +22463,7 @@
     method public int[] getObjectHandles(int, int, int);
     method public android.mtp.MtpObjectInfo getObjectInfo(int);
     method public long getParent(int);
+    method public int getPartialObject(int, int, int, byte[]) throws java.io.IOException;
     method public long getStorageId(int);
     method public int[] getStorageIds();
     method public android.mtp.MtpStorageInfo getStorageInfo(int);
@@ -28362,6 +28378,7 @@
   public final class UserHandle implements android.os.Parcelable {
     ctor public UserHandle(android.os.Parcel);
     method public int describeContents();
+    method public static int getAppId(int);
     method public static android.os.UserHandle readFromParcel(android.os.Parcel);
     method public void writeToParcel(android.os.Parcel, int);
     method public static void writeToParcel(android.os.UserHandle, android.os.Parcel);
@@ -30777,7 +30794,7 @@
     field public static final java.lang.String COLUMN_MIME_TYPE = "mime_type";
     field public static final java.lang.String COLUMN_SIZE = "_size";
     field public static final java.lang.String COLUMN_SUMMARY = "summary";
-    field public static final int FLAG_ARCHIVE = 2048; // 0x800
+    field public static final int FLAG_ARCHIVE = 1024; // 0x400
     field public static final int FLAG_DIR_PREFERS_GRID = 16; // 0x10
     field public static final int FLAG_DIR_PREFERS_LAST_MODIFIED = 32; // 0x20
     field public static final int FLAG_DIR_SUPPORTS_CREATE = 8; // 0x8
@@ -30786,9 +30803,8 @@
     field public static final int FLAG_SUPPORTS_MOVE = 256; // 0x100
     field public static final int FLAG_SUPPORTS_RENAME = 64; // 0x40
     field public static final int FLAG_SUPPORTS_THUMBNAIL = 1; // 0x1
-    field public static final int FLAG_SUPPORTS_TYPED_DOCUMENT = 512; // 0x200
     field public static final int FLAG_SUPPORTS_WRITE = 2; // 0x2
-    field public static final int FLAG_VIRTUAL_DOCUMENT = 1024; // 0x400
+    field public static final int FLAG_VIRTUAL_DOCUMENT = 512; // 0x200
     field public static final java.lang.String MIME_TYPE_DIR = "vnd.android.document/directory";
   }
 
@@ -31232,6 +31248,7 @@
     field public static final java.lang.String ACTION_SEARCH_SETTINGS = "android.search.action.SEARCH_SETTINGS";
     field public static final java.lang.String ACTION_SECURITY_SETTINGS = "android.settings.SECURITY_SETTINGS";
     field public static final java.lang.String ACTION_SETTINGS = "android.settings.SETTINGS";
+    field public static final java.lang.String ACTION_SHOW_ADMIN_SUPPORT_DETAILS = "android.settings.SHOW_ADMIN_SUPPORT_DETAILS";
     field public static final java.lang.String ACTION_SHOW_REGULATORY_INFO = "android.settings.SHOW_REGULATORY_INFO";
     field public static final java.lang.String ACTION_SOUND_SETTINGS = "android.settings.SOUND_SETTINGS";
     field public static final java.lang.String ACTION_SYNC_SETTINGS = "android.settings.SYNC_SETTINGS";
@@ -31386,6 +31403,7 @@
     field public static final deprecated java.lang.String TTS_USE_DEFAULTS = "tts_use_defaults";
     field public static final deprecated java.lang.String USB_MASS_STORAGE_ENABLED = "usb_mass_storage_enabled";
     field public static final deprecated java.lang.String USE_GOOGLE_MAIL = "use_google_mail";
+    field public static final java.lang.String VOICE_INTERACTION_SERVICE = "voice_interaction_service";
     field public static final deprecated java.lang.String WIFI_MAX_DHCP_RETRY_COUNT = "wifi_max_dhcp_retry_count";
     field public static final deprecated java.lang.String WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS = "wifi_mobile_data_transition_wakelock_timeout_ms";
     field public static final deprecated java.lang.String WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON = "wifi_networks_available_notification_on";
@@ -31769,6 +31787,7 @@
     field public static final int RESULT_SMS_OUT_OF_MEMORY = 3; // 0x3
     field public static final int RESULT_SMS_UNSUPPORTED = 4; // 0x4
     field public static final java.lang.String SIM_FULL_ACTION = "android.provider.Telephony.SIM_FULL";
+    field public static final java.lang.String SMS_CARRIER_PROVISION_ACTION = "android.provider.Telephony.SMS_CARRIER_PROVISION";
     field public static final java.lang.String SMS_CB_RECEIVED_ACTION = "android.provider.Telephony.SMS_CB_RECEIVED";
     field public static final java.lang.String SMS_DELIVER_ACTION = "android.provider.Telephony.SMS_DELIVER";
     field public static final java.lang.String SMS_EMERGENCY_CB_RECEIVED_ACTION = "android.provider.Telephony.SMS_EMERGENCY_CB_RECEIVED";
@@ -33105,6 +33124,7 @@
   public class NetworkSecurityPolicy {
     method public static android.security.NetworkSecurityPolicy getInstance();
     method public boolean isCleartextTrafficPermitted();
+    method public boolean isCleartextTrafficPermitted(java.lang.String);
   }
 
 }
@@ -33497,20 +33517,13 @@
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.ConditionProviderService";
   }
 
-  public class NotificationAdjustment implements android.os.Parcelable {
-    ctor public NotificationAdjustment(int, java.lang.CharSequence, android.net.Uri);
-    method public int describeContents();
-    method public void writeToParcel(android.os.Parcel, int);
-    field public static final android.os.Parcelable.Creator<android.service.notification.NotificationAdjustment> CREATOR;
-  }
-
   public abstract class NotificationAssistantService extends android.service.notification.NotificationListenerService {
     ctor public NotificationAssistantService();
-    method public final void adjustImportance(java.lang.String, android.service.notification.NotificationAdjustment);
+    method public final void adjustImportance(java.lang.String, android.service.notification.NotificationAssistantService.Adjustment);
     method public final void clearAnnotation(java.lang.String);
     method public void onNotificationActionClick(java.lang.String, long, int);
     method public void onNotificationClick(java.lang.String, long);
-    method public abstract android.service.notification.NotificationAdjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, int, boolean);
+    method public abstract android.service.notification.NotificationAssistantService.Adjustment onNotificationEnqueued(android.service.notification.StatusBarNotification, int, boolean);
     method public void onNotificationRemoved(java.lang.String, long, int);
     method public void onNotificationVisibilityChanged(java.lang.String, long, boolean);
     method public final void setAnnotation(java.lang.String, android.app.Notification);
@@ -33530,6 +33543,10 @@
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationAssistantService";
   }
 
+  public class NotificationAssistantService.Adjustment {
+    ctor public NotificationAssistantService.Adjustment(int, java.lang.CharSequence, android.net.Uri);
+  }
+
   public abstract class NotificationListenerService extends android.app.Service {
     ctor public NotificationListenerService();
     method public final void cancelAllNotifications();
@@ -33563,6 +33580,7 @@
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationListenerService";
     field public static final int SUPPRESSED_EFFECT_LIGHTS = 1; // 0x1
     field public static final int SUPPRESSED_EFFECT_PEEK = 2; // 0x2
+    field public static final int SUPPRESSED_EFFECT_SCREEN_ON = 4; // 0x4
   }
 
   public static class NotificationListenerService.Ranking {
@@ -33634,10 +33652,13 @@
     method public void onClick();
     method public void onStartListening();
     method public void onStopListening();
-    method public void onTileAdded();
+    method public int onTileAdded();
     method public void onTileRemoved();
+    method public static final void requestListeningState(android.content.Context, android.content.ComponentName);
     method public final void showDialog(android.app.Dialog);
     field public static final java.lang.String ACTION_QS_TILE = "android.service.quicksettings.action.QS_TILE";
+    field public static final int TILE_MODE_ACTIVE = 2; // 0x2
+    field public static final int TILE_MODE_PASSIVE = 1; // 0x1
   }
 
 }
@@ -34898,6 +34919,7 @@
     field public static final int PROPERTY_GENERIC_CONFERENCE = 2; // 0x2
     field public static final int PROPERTY_HIGH_DEF_AUDIO = 16; // 0x10
     field public static final int PROPERTY_WIFI = 8; // 0x8
+    field public static final int PROPERTY_WORK_CALL = 32; // 0x20
   }
 
   public final class CallAudioState implements android.os.Parcelable {
@@ -36042,6 +36064,7 @@
     method public java.lang.String getSubscriberId();
     method public java.lang.String getVoiceMailAlphaTag();
     method public java.lang.String getVoiceMailNumber();
+    method public android.net.Uri getVoicemailRingtoneUri(android.telecom.PhoneAccountHandle);
     method public boolean hasCarrierPrivileges();
     method public boolean hasIccCard();
     method public boolean iccCloseLogicalChannel(int);
@@ -36054,6 +36077,7 @@
     method public boolean isSmsCapable();
     method public boolean isTtyModeSupported();
     method public boolean isVoiceCapable();
+    method public boolean isVoicemailVibrationEnabled(android.telecom.PhoneAccountHandle);
     method public boolean isWorldPhone();
     method public void listen(android.telephony.PhoneStateListener, int);
     method public java.lang.String sendEnvelopeWithStatus(java.lang.String);
@@ -36610,6 +36634,7 @@
     method public java.lang.Object getSystemService(java.lang.String);
     method public java.lang.String getSystemServiceName(java.lang.Class<?>);
     method public android.content.res.Resources.Theme getTheme();
+    method public int getUserId();
     method public android.graphics.drawable.Drawable getWallpaper();
     method public int getWallpaperDesiredMinimumHeight();
     method public int getWallpaperDesiredMinimumWidth();
@@ -36736,7 +36761,7 @@
     method public android.graphics.drawable.Drawable getApplicationLogo(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
     method public int getComponentEnabledSetting(android.content.ComponentName);
     method public android.graphics.drawable.Drawable getDefaultActivityIcon();
-    method public java.lang.String getDefaultBrowserPackageName(int);
+    method public java.lang.String getDefaultBrowserPackageNameAsUser(int);
     method public android.graphics.drawable.Drawable getDrawable(java.lang.String, int, android.content.pm.ApplicationInfo);
     method public byte[] getEphemeralCookie();
     method public int getEphemeralCookieMaxSizeBytes();
@@ -36748,8 +36773,10 @@
     method public android.content.Intent getLeanbackLaunchIntentForPackage(java.lang.String);
     method public java.lang.String getNameForUid(int);
     method public int[] getPackageGids(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
+    method public int[] getPackageGids(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public android.content.pm.PackageInfo getPackageInfo(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public android.content.pm.PackageInstaller getPackageInstaller();
+    method public int getPackageUid(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public java.lang.String[] getPackagesForUid(int);
     method public java.util.List<android.content.pm.PackageInfo> getPackagesHoldingPermissions(java.lang.String[], int);
     method public android.content.pm.PermissionGroupInfo getPermissionGroupInfo(java.lang.String, int) throws android.content.pm.PackageManager.NameNotFoundException;
@@ -36788,7 +36815,6 @@
     method public android.content.pm.ResolveInfo resolveService(android.content.Intent, int);
     method public void setApplicationEnabledSetting(java.lang.String, int, int);
     method public void setComponentEnabledSetting(android.content.ComponentName, int, int);
-    method public boolean setDefaultBrowserPackageName(java.lang.String, int);
     method public boolean setEphemeralCookie(byte[]);
     method public void setInstallerPackageName(java.lang.String, java.lang.String);
     method public void verifyPendingInstall(int, int);
@@ -39178,7 +39204,7 @@
     method public static final java.lang.String digitsAndPlusOnly(java.util.regex.Matcher);
     field public static final java.util.regex.Pattern DOMAIN_NAME;
     field public static final java.util.regex.Pattern EMAIL_ADDRESS;
-    field public static final java.lang.String GOOD_IRI_CHAR = "a-zA-Z0-9\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef";
+    field public static final deprecated java.lang.String GOOD_IRI_CHAR = "a-zA-Z0-9\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef";
     field public static final java.util.regex.Pattern IP_ADDRESS;
     field public static final java.util.regex.Pattern PHONE;
     field public static final deprecated java.util.regex.Pattern TOP_LEVEL_DOMAIN;
@@ -40557,7 +40583,6 @@
     field public static final int AXIS_RX = 12; // 0xc
     field public static final int AXIS_RY = 13; // 0xd
     field public static final int AXIS_RZ = 14; // 0xe
-    field public static final int AXIS_SCROLL = 26; // 0x1a
     field public static final int AXIS_SIZE = 3; // 0x3
     field public static final int AXIS_THROTTLE = 19; // 0x13
     field public static final int AXIS_TILT = 25; // 0x19
@@ -44044,7 +44069,7 @@
     method public abstract deprecated void setEnableSmoothTransition(boolean);
     method public abstract void setFantasyFontFamily(java.lang.String);
     method public abstract void setFixedFontFamily(java.lang.String);
-    method public abstract void setGeolocationDatabasePath(java.lang.String);
+    method public abstract deprecated void setGeolocationDatabasePath(java.lang.String);
     method public abstract void setGeolocationEnabled(boolean);
     method public abstract void setJavaScriptCanOpenWindowsAutomatically(boolean);
     method public abstract void setJavaScriptEnabled(boolean);
diff --git a/api/test-removed.txt b/api/test-removed.txt
index f12e61e..6b7961e 100644
--- a/api/test-removed.txt
+++ b/api/test-removed.txt
@@ -199,6 +199,15 @@
 
 }
 
+package android.test.mock {
+
+  public class MockPackageManager extends android.content.pm.PackageManager {
+    method public deprecated java.lang.String getDefaultBrowserPackageName(int);
+    method public deprecated boolean setDefaultBrowserPackageName(java.lang.String, int);
+  }
+
+}
+
 package android.text.format {
 
   public class DateFormat {
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index 4f7a109..6302d74 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -159,6 +159,7 @@
                 "       am stack start <DISPLAY_ID> <INTENT>\n" +
                 "       am stack movetask <TASK_ID> <STACK_ID> [true|false]\n" +
                 "       am stack resize <STACK_ID> <LEFT,TOP,RIGHT,BOTTOM>\n" +
+                "       am stack resize-docked-stack <LEFT,TOP,RIGHT,BOTTOM> [<TASK_LEFT,TASK_TOP,TASK_RIGHT,TASK_BOTTOM>]\n" +
                 "       am stack size-docked-stack-test: <STEP_SIZE> <l|t|r|b> [DELAY_MS]\n" +
                 "       am stack move-top-activity-to-pinned-stack: <STACK_ID> <LEFT,TOP,RIGHT,BOTTOM>\n" +
                 "       am stack positiontask <TASK_ID> <STACK_ID> <POSITION>\n" +
@@ -299,7 +300,11 @@
                 "am stack movetask: move <TASK_ID> from its current stack to the top (true) or" +
                 "   bottom (false) of <STACK_ID>.\n" +
                 "\n" +
-                "am stack resize: change <STACK_ID> size and position to <LEFT,TOP,RIGHT,BOTTOM>." +
+                "am stack resize: change <STACK_ID> size and position to <LEFT,TOP,RIGHT,BOTTOM>.\n" +
+                "\n" +
+                "am stack resize-docked-stack: change docked stack to <LEFT,TOP,RIGHT,BOTTOM>\n" +
+                "   and supplying temporary different task bounds indicated by\n" +
+                "   <TASK_LEFT,TOP,RIGHT,BOTTOM>\n" +
                 "\n" +
                 "am stack size-docked-stack-test: test command for sizing docked stack by\n" +
                 "   <STEP_SIZE> increments from the side <l>eft, <t>op, <r>ight, or <b>ottom\n" +
@@ -1683,6 +1688,9 @@
             case "resize":
                 runStackResize();
                 break;
+            case "resize-docked-stack":
+                runStackResizeDocked();
+                break;
             case "positiontask":
                 runStackPositionTask();
                 break;
@@ -1751,6 +1759,20 @@
         resizeStack(stackId, bounds, 0);
     }
 
+    private void runStackResizeDocked() throws Exception {
+        final Rect bounds = getBounds();
+        final Rect taskBounds = getBounds();
+        if (bounds == null || taskBounds == null) {
+            System.err.println("Error: invalid input bounds");
+            return;
+        }
+        try {
+            mAm.resizeDockedStack(bounds, taskBounds, null, null, null);
+        } catch (RemoteException e) {
+            showError("Error: resizing docked stack " + e);
+        }
+    }
+
     private void resizeStack(int stackId, Rect bounds, int delayMs) throws Exception {
         if (bounds == null) {
             showError("Error: invalid input bounds");
diff --git a/core/java/android/annotation/AppIdInt.java b/core/java/android/annotation/AppIdInt.java
new file mode 100644
index 0000000..29838dd
--- /dev/null
+++ b/core/java/android/annotation/AppIdInt.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.annotation;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Denotes that the annotated element is a multi-user application ID. This is
+ * <em>not</em> the same as a UID.
+ *
+ * @hide
+ */
+@Retention(SOURCE)
+@Target({METHOD, PARAMETER, FIELD})
+public @interface AppIdInt {
+}
diff --git a/core/java/android/annotation/UserIdInt.java b/core/java/android/annotation/UserIdInt.java
new file mode 100644
index 0000000..7b9ce25
--- /dev/null
+++ b/core/java/android/annotation/UserIdInt.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.annotation;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Denotes that the annotated element is a multi-user user ID. This is
+ * <em>not</em> the same as a UID.
+ *
+ * @hide
+ */
+@Retention(SOURCE)
+@Target({METHOD, PARAMETER, FIELD})
+public @interface UserIdInt {
+}
diff --git a/core/java/android/app/ActionBar.java b/core/java/android/app/ActionBar.java
index 3e6b595..6fc0d74 100644
--- a/core/java/android/app/ActionBar.java
+++ b/core/java/android/app/ActionBar.java
@@ -1082,6 +1082,10 @@
         return false;
     }
 
+    /** @hide */
+    public void onDestroy() {
+    }
+
     /**
      * Common implementation for requestFocus that takes in the Toolbar and moves focus
      * to the contents. This makes the ViewGroups containing the toolbar allow focus while it stays
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 800ebc6..64642ac 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -62,7 +62,6 @@
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.drawable.Drawable;
-import android.graphics.Rect;
 import android.media.AudioManager;
 import android.media.session.MediaController;
 import android.net.Uri;
@@ -1703,6 +1702,10 @@
             mSearchManager.stopSearch();
         }
 
+        if (mActionBar != null) {
+            mActionBar.onDestroy();
+        }
+
         getApplication().dispatchActivityDestroyed(this);
     }
 
@@ -2208,14 +2211,22 @@
      * @param toolbar Toolbar to set as the Activity's action bar
      */
     public void setActionBar(@Nullable Toolbar toolbar) {
-        if (getActionBar() instanceof WindowDecorActionBar) {
+        final ActionBar ab = getActionBar();
+        if (ab instanceof WindowDecorActionBar) {
             throw new IllegalStateException("This Activity already has an action bar supplied " +
                     "by the window decor. Do not request Window.FEATURE_ACTION_BAR and set " +
                     "android:windowActionBar to false in your theme to use a Toolbar instead.");
         }
-        // Clear out the MenuInflater to make sure that it is valid for the new Action Bar
+
+        // If we reach here then we're setting a new action bar
+        // First clear out the MenuInflater to make sure that it is valid for the new Action Bar
         mMenuInflater = null;
 
+        // If we have an action bar currently, destroy it
+        if (ab != null) {
+            ab.onDestroy();
+        }
+
         ToolbarActionBar tbab = new ToolbarActionBar(toolbar, getTitle(), this);
         mActionBar = tbab;
         mWindow.setCallback(tbab.getWrappedWindowCallback());
@@ -2795,17 +2806,15 @@
 
 
     /**
-     * Called to move the window and its activity/task to a different stack container.
-     * For example, a window can move between
-     * {@link android.app.ActivityManager.StackId#FULLSCREEN_WORKSPACE_STACK_ID} stack and
-     * {@link android.app.ActivityManager.StackId#FREEFORM_WORKSPACE_STACK_ID} stack.
+     * Moves the activity from
+     * {@link android.app.ActivityManager.StackId#FREEFORM_WORKSPACE_STACK_ID} to
+     * {@link android.app.ActivityManager.StackId#FULLSCREEN_WORKSPACE_STACK_ID} stack.
      *
-     * @param stackId stack Id to change to.
      * @hide
      */
     @Override
-    public void changeWindowStack(int stackId) throws RemoteException {
-        ActivityManagerNative.getDefault().moveActivityToStack(mToken, stackId);
+    public void exitFreeformMode() throws RemoteException {
+        ActivityManagerNative.getDefault().exitFreeformMode(mToken);
     }
 
     /** Returns the current stack Id for the window.
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index 3a3aa92..4bea112 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -332,10 +332,9 @@
         {
             data.enforceInterface(IActivityManager.descriptor);
             final int taskId = data.readInt();
-            final int launchStackId = data.readInt();
             final Bundle options =
                     data.readInt() == 0 ? null : Bundle.CREATOR.createFromParcel(data);
-            final int result = startActivityFromRecents(taskId, launchStackId, options);
+            final int result = startActivityFromRecents(taskId, options);
             reply.writeNoException();
             reply.writeInt(result);
             return true;
@@ -571,6 +570,14 @@
             return true;
         }
 
+        case ACTIVITY_RELAUNCHED_TRANSACTION: {
+            data.enforceInterface(IActivityManager.descriptor);
+            IBinder token = data.readStrongBinder();
+            activityRelaunched(token);
+            reply.writeNoException();
+            return true;
+        }
+
         case GET_CALLING_PACKAGE_TRANSACTION: {
             data.enforceInterface(IActivityManager.descriptor);
             IBinder token = data.readStrongBinder();
@@ -786,6 +793,39 @@
             return true;
         }
 
+        case RESIZE_DOCKED_STACK_TRANSACTION: {
+            data.enforceInterface(IActivityManager.descriptor);
+            final boolean hasBounds = data.readInt() != 0;
+            Rect bounds = null;
+            if (hasBounds) {
+                bounds = Rect.CREATOR.createFromParcel(data);
+            }
+            final boolean hasTempDockedTaskBounds = data.readInt() != 0;
+            Rect tempDockedTaskBounds = null;
+            if (hasTempDockedTaskBounds) {
+                tempDockedTaskBounds = Rect.CREATOR.createFromParcel(data);
+            }
+            final boolean hasTempDockedTaskInsetBounds = data.readInt() != 0;
+            Rect tempDockedTaskInsetBounds = null;
+            if (hasTempDockedTaskInsetBounds) {
+                tempDockedTaskInsetBounds = Rect.CREATOR.createFromParcel(data);
+            }
+            final boolean hasTempOtherTaskBounds = data.readInt() != 0;
+            Rect tempOtherTaskBounds = null;
+            if (hasTempOtherTaskBounds) {
+                tempOtherTaskBounds = Rect.CREATOR.createFromParcel(data);
+            }
+            final boolean hasTempOtherTaskInsetBounds = data.readInt() != 0;
+            Rect tempOtherTaskInsetBounds = null;
+            if (hasTempOtherTaskInsetBounds) {
+                tempOtherTaskInsetBounds = Rect.CREATOR.createFromParcel(data);
+            }
+            resizeDockedStack(bounds, tempDockedTaskBounds, tempDockedTaskInsetBounds,
+                    tempOtherTaskBounds, tempOtherTaskInsetBounds);
+            reply.writeNoException();
+            return true;
+        }
+
         case POSITION_TASK_IN_STACK_TRANSACTION: {
             data.enforceInterface(IActivityManager.descriptor);
             int taskId = data.readInt();
@@ -2712,11 +2752,10 @@
             reply.writeInt(stackId);
             return true;
         }
-        case MOVE_ACTIVITY_TO_STACK_TRANSACTION: {
+        case EXIT_FREEFORM_MODE_TRANSACTION: {
             data.enforceInterface(IActivityManager.descriptor);
             IBinder token = data.readStrongBinder();
-            int stackId = data.readInt();
-            moveActivityToStack(token, stackId);
+            exitFreeformMode(token);
             reply.writeNoException();
             return true;
         }
@@ -3088,13 +3127,12 @@
         data.recycle();
         return result != 0;
     }
-    public int startActivityFromRecents(int taskId, int launchStackId, Bundle options)
+    public int startActivityFromRecents(int taskId, Bundle options)
             throws RemoteException {
         Parcel data = Parcel.obtain();
         Parcel reply = Parcel.obtain();
         data.writeInterfaceToken(IActivityManager.descriptor);
         data.writeInt(taskId);
-        data.writeInt(launchStackId);
         if (options == null) {
             data.writeInt(0);
         } else {
@@ -3382,6 +3420,17 @@
         data.recycle();
         reply.recycle();
     }
+    public void activityRelaunched(IBinder token) throws RemoteException
+    {
+        Parcel data = Parcel.obtain();
+        Parcel reply = Parcel.obtain();
+        data.writeInterfaceToken(IActivityManager.descriptor);
+        data.writeStrongBinder(token);
+        mRemote.transact(ACTIVITY_RELAUNCHED_TRANSACTION, data, reply, 0);
+        reply.readException();
+        data.recycle();
+        reply.recycle();
+    }
     public String getCallingPackage(IBinder token) throws RemoteException
     {
         Parcel data = Parcel.obtain();
@@ -3692,6 +3741,50 @@
         reply.recycle();
     }
     @Override
+    public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds,
+            Rect tempDockedTaskInsetBounds,
+            Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds)
+            throws RemoteException
+    {
+        Parcel data = Parcel.obtain();
+        Parcel reply = Parcel.obtain();
+        data.writeInterfaceToken(IActivityManager.descriptor);
+        if (dockedBounds != null) {
+            data.writeInt(1);
+            dockedBounds.writeToParcel(data, 0);
+        } else {
+            data.writeInt(0);
+        }
+        if (tempDockedTaskBounds != null) {
+            data.writeInt(1);
+            tempDockedTaskBounds.writeToParcel(data, 0);
+        } else {
+            data.writeInt(0);
+        }
+        if (tempDockedTaskInsetBounds != null) {
+            data.writeInt(1);
+            tempDockedTaskInsetBounds.writeToParcel(data, 0);
+        } else {
+            data.writeInt(0);
+        }
+        if (tempOtherTaskBounds != null) {
+            data.writeInt(1);
+            tempOtherTaskBounds.writeToParcel(data, 0);
+        } else {
+            data.writeInt(0);
+        }
+        if (tempOtherTaskInsetBounds != null) {
+            data.writeInt(1);
+            tempOtherTaskInsetBounds.writeToParcel(data, 0);
+        } else {
+            data.writeInt(0);
+        }
+        mRemote.transact(RESIZE_DOCKED_STACK_TRANSACTION, data, reply, 0);
+        reply.readException();
+        data.recycle();
+        reply.recycle();
+    }
+    @Override
     public void positionTaskInStack(int taskId, int stackId, int position) throws RemoteException
     {
         Parcel data = Parcel.obtain();
@@ -6363,13 +6456,12 @@
     }
 
     @Override
-    public void moveActivityToStack(IBinder token, int stackId) throws RemoteException {
+    public void exitFreeformMode(IBinder token) throws RemoteException {
         Parcel data = Parcel.obtain();
         Parcel reply = Parcel.obtain();
         data.writeInterfaceToken(IActivityManager.descriptor);
         data.writeStrongBinder(token);
-        data.writeInt(stackId);
-        mRemote.transact(MOVE_ACTIVITY_TO_STACK_TRANSACTION, data, reply, 0);
+        mRemote.transact(EXIT_FREEFORM_MODE_TRANSACTION, data, reply, 0);
         reply.readException();
         data.recycle();
         reply.recycle();
diff --git a/core/java/android/app/ActivityOptions.java b/core/java/android/app/ActivityOptions.java
index cee1aa5..e596a68 100644
--- a/core/java/android/app/ActivityOptions.java
+++ b/core/java/android/app/ActivityOptions.java
@@ -17,6 +17,7 @@
 package android.app;
 
 import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT;
+import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
 
 import android.content.Context;
 import android.content.Intent;
@@ -67,7 +68,8 @@
      * The bounds (window size) that the activity should be launched in. Set to null explicitly for
      * full screen. If the key is not found, previous bounds will be preserved.
      * NOTE: This value is ignored on devices that don't have
-     * {@link android.content.pm.PackageManager#FEATURE_FREEFORM_WINDOW_MANAGEMENT} enabled.
+     * {@link android.content.pm.PackageManager#FEATURE_FREEFORM_WINDOW_MANAGEMENT} or
+     * {@link android.content.pm.PackageManager#FEATURE_PICTURE_IN_PICTURE} enabled.
      * @hide
      */
     public static final String KEY_LAUNCH_BOUNDS = "android:activity.launchBounds";
@@ -145,6 +147,12 @@
     private static final String KEY_ANIM_SPECS = "android:activity.animSpecs";
 
     /**
+     * The stack id the activity should be launched into.
+     * @hide
+     */
+    private static final String KEY_LAUNCH_STACK_ID = "android.activity.launchStackId";
+
+    /**
      * Where the docked stack should be positioned.
      * @hide
      */
@@ -215,6 +223,7 @@
     private int mResultCode;
     private int mExitCoordinatorIndex;
     private PendingIntent mUsageTimeReport;
+    private int mLaunchStackId = INVALID_STACK_ID;
     private int mDockCreateMode = DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT;
     private AppTransitionAnimationSpec mAnimSpecs[];
 
@@ -754,6 +763,7 @@
                 mExitCoordinatorIndex = opts.getInt(KEY_EXIT_COORDINATOR_INDEX);
                 break;
         }
+        mLaunchStackId = opts.getInt(KEY_LAUNCH_STACK_ID, INVALID_STACK_ID);
         mDockCreateMode = opts.getInt(KEY_DOCK_CREATE_MODE, DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT);
         if (opts.containsKey(KEY_ANIM_SPECS)) {
             Parcelable[] specs = opts.getParcelableArray(KEY_ANIM_SPECS);
@@ -901,7 +911,19 @@
     }
 
     /** @hide */
-    public int getDockCreateMode() { return mDockCreateMode; }
+    public int getLaunchStackId() {
+        return mLaunchStackId;
+    }
+
+    /** @hide */
+    public void setLaunchStackId(int launchStackId) {
+        mLaunchStackId = launchStackId;
+    }
+
+    /** @hide */
+    public int getDockCreateMode() {
+        return mDockCreateMode;
+    }
 
     /** @hide */
     public void setDockCreateMode(int dockCreateMode) {
@@ -1049,6 +1071,7 @@
                 b.putInt(KEY_EXIT_COORDINATOR_INDEX, mExitCoordinatorIndex);
                 break;
         }
+        b.putInt(KEY_LAUNCH_STACK_ID, mLaunchStackId);
         b.putInt(KEY_DOCK_CREATE_MODE, mDockCreateMode);
         if (mAnimSpecs != null) {
             b.putParcelableArray(KEY_ANIM_SPECS, mAnimSpecs);
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index ed168d1..4531a74 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -101,6 +101,9 @@
 import android.view.WindowManagerGlobal;
 import android.renderscript.RenderScriptCacheDir;
 import android.security.keystore.AndroidKeyStoreProvider;
+import android.system.Os;
+import android.system.OsConstants;
+import android.system.ErrnoException;
 
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.app.IVoiceInteractor;
@@ -820,48 +823,6 @@
 
             setCoreSettings(coreSettings);
 
-            /*
-             * Two possible indications that this package could be
-             * sharing its runtime with other packages:
-             *
-             * 1.) the sharedUserId attribute is set in the manifest,
-             *     indicating a request to share a VM with other
-             *     packages with the same sharedUserId.
-             *
-             * 2.) the application element of the manifest has an
-             *     attribute specifying a non-default process name,
-             *     indicating the desire to run in another packages VM.
-             *
-             * If sharing is enabled we do not have a unique application
-             * in a process and therefore cannot rely on the package
-             * name inside the runtime.
-             */
-            IPackageManager pm = getPackageManager();
-            android.content.pm.PackageInfo pi = null;
-            try {
-                pi = pm.getPackageInfo(appInfo.packageName, 0, UserHandle.myUserId());
-            } catch (RemoteException e) {
-            }
-            if (pi != null) {
-                boolean sharedUserIdSet = (pi.sharedUserId != null);
-                boolean processNameNotDefault =
-                (pi.applicationInfo != null &&
-                 !appInfo.packageName.equals(pi.applicationInfo.processName));
-                boolean sharable = (sharedUserIdSet || processNameNotDefault);
-
-                // Tell the VMRuntime about the application, unless it is shared
-                // inside a process.
-                if (!sharable) {
-                    final List<String> codePaths = new ArrayList<>();
-                    codePaths.add(appInfo.sourceDir);
-                    if (appInfo.splitSourceDirs != null) {
-                        Collections.addAll(codePaths, appInfo.splitSourceDirs);
-                    }
-                    VMRuntime.registerAppInfo(appInfo.packageName, appInfo.dataDir,
-                            codePaths.toArray(new String[codePaths.size()]));
-                }
-            }
-
             AppBindData data = new AppBindData();
             data.processName = processName;
             data.appInfo = appInfo;
@@ -4161,6 +4122,15 @@
                             r.pendingIntents = pendingNewIntents;
                         }
                     }
+
+                    // For each relaunch request, activity manager expects an answer
+                    if (!r.onlyLocalRequest && fromServer) {
+                        try {
+                            ActivityManagerNative.getDefault().activityRelaunched(token);
+                        } catch (RemoteException e) {
+                            e.printStackTrace();
+                        }
+                    }
                     break;
                 }
             }
@@ -4275,6 +4245,13 @@
         ActivityClientRecord r = mActivities.get(tmp.token);
         if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handling relaunch of " + r);
         if (r == null) {
+            if (!tmp.onlyLocalRequest) {
+                try {
+                    ActivityManagerNative.getDefault().activityRelaunched(tmp.token);
+                } catch (RemoteException e) {
+                    // If the system process has died, it's game over for everyone.
+                }
+            }
             return;
         }
 
@@ -4320,6 +4297,14 @@
         r.overrideConfig = tmp.overrideConfig;
 
         handleLaunchActivity(r, currentIntent);
+
+        if (!tmp.onlyLocalRequest) {
+            try {
+                ActivityManagerNative.getDefault().activityRelaunched(r.token);
+            } catch (RemoteException e) {
+                // If the system process has died, it's game over for everyone.
+            }
+        }
     }
 
     private void callCallActivityOnSaveInstanceState(ActivityClientRecord r) {
@@ -4673,6 +4658,87 @@
         }
     }
 
+    private static void setupJitProfileSupport(LoadedApk loadedApk, File cacheDir) {
+        final ApplicationInfo appInfo = loadedApk.getApplicationInfo();
+        if (isSharingRuntime(appInfo)) {
+            // If sharing is enabled we do not have a unique application
+            // in a process and therefore cannot rely on the package
+            // name inside the runtime.
+            return;
+        }
+        final List<String> codePaths = new ArrayList<>();
+        if ((appInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) {
+            codePaths.add(appInfo.sourceDir);
+        }
+        if (appInfo.splitSourceDirs != null) {
+            Collections.addAll(codePaths, appInfo.splitSourceDirs);
+        }
+
+        if (codePaths.isEmpty()) {
+            // If there are no code paths there's no need to setup a profile file and register with
+            // the runtime,
+            return;
+        }
+
+        // Add an extension to the file name to better reveal its intended use.
+        // Keep in sync with BackgroundDexOptService.
+        final String profileExtension = ".prof";
+        final File profileFile = new File(cacheDir, loadedApk.mPackageName + profileExtension);
+        if (!profileFile.exists()) {
+            FileDescriptor fd = null;
+            try {
+                final int permissions = 0600;  // read-write for user.
+                fd = Os.open(profileFile.getAbsolutePath(), OsConstants.O_CREAT, permissions);
+                Os.fchmod(fd, permissions);
+                Os.fchown(fd, appInfo.uid, appInfo.uid);
+            } catch (ErrnoException e) {
+                Log.w(TAG, "Unable to create jit profile file " + profileFile, e);
+                try {
+                    Os.unlink(profileFile.getAbsolutePath());
+                } catch (ErrnoException unlinkErr) {
+                    Log.v(TAG, "Unable to unlink jit profile file " + profileFile, unlinkErr);
+                }
+                return;
+            } finally {
+                IoUtils.closeQuietly(fd);
+            }
+        }
+
+        VMRuntime.registerAppInfo(profileFile.getAbsolutePath(), appInfo.dataDir,
+                codePaths.toArray(new String[codePaths.size()]));
+    }
+
+    /*
+     * Two possible indications that this package could be
+     * sharing its runtime with other packages:
+     *
+     * 1) the sharedUserId attribute is set in the manifest,
+     *    indicating a request to share a VM with other
+     *    packages with the same sharedUserId.
+     *
+     * 2) the application element of the manifest has an
+     *    attribute specifying a non-default process name,
+     *    indicating the desire to run in another packages VM.
+     */
+    private static boolean isSharingRuntime(ApplicationInfo appInfo) {
+        IPackageManager pm = getPackageManager();
+        android.content.pm.PackageInfo pi = null;
+        try {
+            pi = pm.getPackageInfo(appInfo.packageName, 0, UserHandle.myUserId());
+        } catch (RemoteException e) {
+        }
+        if (pi != null) {
+            boolean sharedUserIdSet = (pi.sharedUserId != null);
+            boolean processNameNotDefault = (pi.applicationInfo != null) &&
+                    !appInfo.packageName.equals(pi.applicationInfo.processName);
+            boolean sharable = sharedUserIdSet || processNameNotDefault;
+            return sharable;
+        }
+        // We couldn't get information for the package. Be pessimistic and assume
+        // it's sharing the runtime.
+        return true;
+    }
+
     private void updateDefaultDensity() {
         if (mCurDefaultDisplayDpi != Configuration.DENSITY_DPI_UNDEFINED
                 && mCurDefaultDisplayDpi != DisplayMetrics.DENSITY_DEVICE
@@ -4876,12 +4942,14 @@
                         + "due to missing cache directory");
             }
 
-            // Use codeCacheDir to store generated/compiled graphics code
+            // Use codeCacheDir to store generated/compiled graphics code and jit profiling data.
             final File codeCacheDir = appContext.getCodeCacheDir();
             if (codeCacheDir != null) {
                 setupGraphicsSupport(data.info, codeCacheDir);
+                setupJitProfileSupport(data.info, codeCacheDir);
             } else {
-                Log.e(TAG, "Unable to setupGraphicsSupport due to missing code-cache directory");
+                Log.e(TAG, "Unable to setupGraphicsSupport and setupJitProfileSupport " +
+                        "due to missing code-cache directory");
             }
         }
 
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index 77721e6..42b18384 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -42,7 +42,6 @@
 import android.content.pm.InstrumentationInfo;
 import android.content.pm.IntentFilterVerificationInfo;
 import android.content.pm.KeySet;
-import android.content.pm.ManifestDigest;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageInstaller;
 import android.content.pm.PackageItemInfo;
@@ -214,10 +213,15 @@
     }
 
     @Override
-    public int[] getPackageGids(String packageName)
+    public int[] getPackageGids(String packageName) throws NameNotFoundException {
+        return getPackageGids(packageName, 0);
+    }
+
+    @Override
+    public int[] getPackageGids(String packageName, int flags)
             throws NameNotFoundException {
         try {
-            int[] gids = mPM.getPackageGids(packageName, mContext.getUserId());
+            int[] gids = mPM.getPackageGidsEtc(packageName, flags, mContext.getUserId());
             if (gids != null) {
                 return gids;
             }
@@ -229,10 +233,20 @@
     }
 
     @Override
-    public int getPackageUid(String packageName, int userHandle)
+    public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
+        return getPackageUidAsUser(packageName, flags, mContext.getUserId());
+    }
+
+    @Override
+    public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
+        return getPackageUidAsUser(packageName, 0, userId);
+    }
+
+    @Override
+    public int getPackageUidAsUser(String packageName, int flags, int userId)
             throws NameNotFoundException {
         try {
-            int uid = mPM.getPackageUid(packageName, userHandle);
+            int uid = mPM.getPackageUidEtc(packageName, flags, userId);
             if (uid >= 0) {
                 return uid;
             }
@@ -591,12 +605,12 @@
     @SuppressWarnings("unchecked")
     @Override
     public List<PackageInfo> getInstalledPackages(int flags) {
-        return getInstalledPackages(flags, mContext.getUserId());
+        return getInstalledPackagesAsUser(flags, mContext.getUserId());
     }
 
     /** @hide */
     @Override
-    public List<PackageInfo> getInstalledPackages(int flags, int userId) {
+    public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
         try {
             ParceledListSlice<PackageInfo> slice = mPM.getInstalledPackages(flags, userId);
             return slice.getList();
@@ -780,7 +794,7 @@
      * @hide
      */
     @Override
-    public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags, int userId) {
+    public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
         try {
             return mPM.queryIntentReceivers(
                 intent,
@@ -794,7 +808,7 @@
 
     @Override
     public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
-        return queryBroadcastReceivers(intent, flags, mContext.getUserId());
+        return queryBroadcastReceiversAsUser(intent, flags, mContext.getUserId());
     }
 
     @Override
@@ -1421,7 +1435,7 @@
     public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
                                String installerPackageName) {
         final VerificationParams verificationParams = new VerificationParams(null, null,
-                null, VerificationParams.NO_UID, null);
+                null, VerificationParams.NO_UID);
         installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
                 installerPackageName, verificationParams, null, mContext.getUserId());
     }
@@ -1429,9 +1443,9 @@
     @Override
     public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer,
             int flags, String installerPackageName, Uri verificationURI,
-            ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {
+            ContainerEncryptionParams encryptionParams) {
         final VerificationParams verificationParams = new VerificationParams(verificationURI, null,
-                null, VerificationParams.NO_UID, manifestDigest);
+                null, VerificationParams.NO_UID);
         installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
                 installerPackageName, verificationParams, encryptionParams, mContext.getUserId());
     }
@@ -1455,7 +1469,7 @@
     public void installPackageAsUser(Uri packageURI, PackageInstallObserver observer, int flags,
                String installerPackageName, int userId) {
         final VerificationParams verificationParams = new VerificationParams(null, null,
-                null, VerificationParams.NO_UID, null);
+                null, VerificationParams.NO_UID);
         installCommon(packageURI, observer, flags, installerPackageName, verificationParams, null,
                 userId);
     }
@@ -1463,10 +1477,10 @@
     @Override
     public void installPackageWithVerification(Uri packageURI,
             PackageInstallObserver observer, int flags, String installerPackageName,
-            Uri verificationURI, ManifestDigest manifestDigest,
+            Uri verificationURI,
             ContainerEncryptionParams encryptionParams) {
         final VerificationParams verificationParams = new VerificationParams(verificationURI, null,
-                null, VerificationParams.NO_UID, manifestDigest);
+                null, VerificationParams.NO_UID);
         installCommon(packageURI, observer, flags, installerPackageName, verificationParams,
                 encryptionParams, mContext.getUserId());
     }
@@ -1547,7 +1561,7 @@
     }
 
     @Override
-    public int getIntentVerificationStatus(String packageName, int userId) {
+    public int getIntentVerificationStatusAsUser(String packageName, int userId) {
         try {
             return mPM.getIntentVerificationStatus(packageName, userId);
         } catch (RemoteException e) {
@@ -1557,7 +1571,7 @@
     }
 
     @Override
-    public boolean updateIntentVerificationStatus(String packageName, int status, int userId) {
+    public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
         try {
             return mPM.updateIntentVerificationStatus(packageName, status, userId);
         } catch (RemoteException e) {
@@ -1587,7 +1601,7 @@
     }
 
     @Override
-    public String getDefaultBrowserPackageName(int userId) {
+    public String getDefaultBrowserPackageNameAsUser(int userId) {
         try {
             return mPM.getDefaultBrowserPackageName(userId);
         } catch (RemoteException e) {
@@ -1597,7 +1611,7 @@
     }
 
     @Override
-    public boolean setDefaultBrowserPackageName(String packageName, int userId) {
+    public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
         try {
             return mPM.setDefaultBrowserPackageName(packageName, userId);
         } catch (RemoteException e) {
@@ -1868,7 +1882,7 @@
     }
 
     @Override
-    public void getPackageSizeInfo(String packageName, int userHandle,
+    public void getPackageSizeInfoAsUser(String packageName, int userHandle,
             IPackageStatsObserver observer) {
         try {
             mPM.getPackageSizeInfo(packageName, userHandle, observer);
@@ -1915,7 +1929,7 @@
     }
 
     @Override
-    public void addPreferredActivity(IntentFilter filter, int match,
+    public void addPreferredActivityAsUser(IntentFilter filter, int match,
             ComponentName[] set, ComponentName activity, int userId) {
         try {
             mPM.addPreferredActivity(filter, match, set, activity, userId);
diff --git a/core/java/android/app/BackStackRecord.java b/core/java/android/app/BackStackRecord.java
index 984a186..a147cc8 100644
--- a/core/java/android/app/BackStackRecord.java
+++ b/core/java/android/app/BackStackRecord.java
@@ -719,7 +719,7 @@
                     Fragment f = op.fragment;
                     int containerId = f.mContainerId;
                     if (mManager.mAdded != null) {
-                        for (int i = 0; i < mManager.mAdded.size(); i++) {
+                        for (int i = mManager.mAdded.size() - 1; i >= 0; i--) {
                             Fragment old = mManager.mAdded.get(i);
                             if (FragmentManagerImpl.DEBUG) {
                                 Log.v(TAG,
diff --git a/core/java/android/app/DownloadManager.java b/core/java/android/app/DownloadManager.java
index fb0e79b..ed4bb28 100644
--- a/core/java/android/app/DownloadManager.java
+++ b/core/java/android/app/DownloadManager.java
@@ -27,6 +27,7 @@
 import android.net.ConnectivityManager;
 import android.net.NetworkPolicyManager;
 import android.net.Uri;
+import android.os.Build;
 import android.os.Environment;
 import android.os.ParcelFileDescriptor;
 import android.provider.Downloads;
@@ -105,8 +106,17 @@
     public final static String COLUMN_LOCAL_URI = "local_uri";
 
     /**
-     * The pathname of the file where the download is stored.
+     * Path to the downloaded file on disk.
+     * <p>
+     * Note that apps may not have filesystem permissions to directly access
+     * this path. Instead of trying to open this path directly, apps should use
+     * {@link ContentResolver#openFileDescriptor(Uri, String)} to gain access.
+     *
+     * @deprecated apps should transition to using
+     *             {@link ContentResolver#openFileDescriptor(Uri, String)}
+     *             instead.
      */
+    @Deprecated
     public final static String COLUMN_LOCAL_FILENAME = "local_filename";
 
     /**
@@ -908,16 +918,22 @@
         }
     }
 
-    private ContentResolver mResolver;
-    private String mPackageName;
+    private final ContentResolver mResolver;
+    private final String mPackageName;
+
     private Uri mBaseUri = Downloads.Impl.CONTENT_URI;
+    private boolean mAccessFilename;
 
     /**
      * @hide
      */
-    public DownloadManager(ContentResolver resolver, String packageName) {
-        mResolver = resolver;
-        mPackageName = packageName;
+    public DownloadManager(Context context) {
+        mResolver = context.getContentResolver();
+        mPackageName = context.getPackageName();
+
+        // Callers can access filename columns when targeting old platform
+        // versions; otherwise we throw telling them it's deprecated.
+        mAccessFilename = context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N;
     }
 
     /**
@@ -933,6 +949,11 @@
         }
     }
 
+    /** {@hide} */
+    public void setAccessFilename(boolean accessFilename) {
+        mAccessFilename = accessFilename;
+    }
+
     /**
      * Enqueue a new download.  The download will start automatically once the download manager is
      * ready to execute it and connectivity is available.
@@ -997,7 +1018,7 @@
         if (underlyingCursor == null) {
             return null;
         }
-        return new CursorTranslator(underlyingCursor, mBaseUri);
+        return new CursorTranslator(underlyingCursor, mBaseUri, mAccessFilename);
     }
 
     /**
@@ -1265,11 +1286,13 @@
      * underlying data.
      */
     private static class CursorTranslator extends CursorWrapper {
-        private Uri mBaseUri;
+        private final Uri mBaseUri;
+        private final boolean mAccessFilename;
 
-        public CursorTranslator(Cursor cursor, Uri baseUri) {
+        public CursorTranslator(Cursor cursor, Uri baseUri, boolean accessFilename) {
             super(cursor);
             mBaseUri = baseUri;
+            mAccessFilename = accessFilename;
         }
 
         @Override
@@ -1290,8 +1313,19 @@
 
         @Override
         public String getString(int columnIndex) {
-            return (getColumnName(columnIndex).equals(COLUMN_LOCAL_URI)) ? getLocalUri() :
-                    super.getString(columnIndex);
+            final String columnName = getColumnName(columnIndex);
+            switch (columnName) {
+                case COLUMN_LOCAL_URI:
+                    return getLocalUri();
+                case COLUMN_LOCAL_FILENAME:
+                    if (!mAccessFilename) {
+                        throw new IllegalArgumentException(
+                                "COLUMN_LOCAL_FILENAME is deprecated;"
+                                        + " use ContentResolver.openFileDescriptor() instead");
+                    }
+                default:
+                    return super.getString(columnIndex);
+            }
         }
 
         private String getLocalUri() {
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 61b1bc8..8804c8b 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -92,7 +92,7 @@
             int userId) throws RemoteException;
     public boolean startNextMatchingActivity(IBinder callingActivity,
             Intent intent, Bundle options) throws RemoteException;
-    public int startActivityFromRecents(int taskId, int launchStackId, Bundle options)
+    public int startActivityFromRecents(int taskId, Bundle options)
             throws RemoteException;
     public boolean finishActivity(IBinder token, int code, Intent data, int finishTask)
             throws RemoteException;
@@ -122,6 +122,7 @@
             PersistableBundle persistentState, CharSequence description) throws RemoteException;
     public void activitySlept(IBinder token) throws RemoteException;
     public void activityDestroyed(IBinder token) throws RemoteException;
+    public void activityRelaunched(IBinder token) throws RemoteException;
     public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration,
             int[] verticalSizeConfigurations, int[] smallestWidthConfigurations)
             throws RemoteException;
@@ -145,7 +146,31 @@
     public void moveTaskToDockedStack(int taskId, int createMode, boolean toTop, boolean animate,
             Rect initialBounds) throws RemoteException;
     public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) throws RemoteException;
-    public void resizeStack(int stackId, Rect bounds, boolean allowResizeInDockedMode) throws RemoteException;
+    public void resizeStack(int stackId, Rect bounds, boolean allowResizeInDockedMode)
+            throws RemoteException;
+
+    /**
+     * Resizes the docked stack, and all other stacks as the result of the dock stack bounds change.
+     *
+     * @param dockedBounds The bounds for the docked stack.
+     * @param tempDockedTaskBounds The temporary bounds for the tasks in the docked stack, which
+     *                             might be different from the stack bounds to allow more
+     *                             flexibility while resizing, or {@code null} if they should be the
+     *                             same as the stack bounds.
+     * @param tempDockedTaskInsetBounds The temporary bounds for the tasks to calculate the insets.
+     *                                  When resizing, we usually "freeze" the layout of a task. To
+     *                                  achieve that, we also need to "freeze" the insets, which
+     *                                  gets achieved by changing task bounds but not bounds used
+     *                                  to calculate the insets in this transient state
+     * @param tempOtherTaskBounds The temporary bounds for the tasks in all other stacks, or
+     *                            {@code null} if they should be the same as the stack bounds.
+     * @param tempOtherTaskInsetBounds Like {@code tempDockedTaskInsetBounds}, but for the other
+     *                                 stacks.
+     * @throws RemoteException
+     */
+    public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds,
+            Rect tempDockedTaskInsetBounds,
+            Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) throws RemoteException;
     public void positionTaskInStack(int taskId, int stackId, int position) throws RemoteException;
     public List<StackInfo> getAllStackInfos() throws RemoteException;
     public StackInfo getStackInfo(int stackId) throws RemoteException;
@@ -539,7 +564,7 @@
     public boolean stopBinderTrackingAndDump(ParcelFileDescriptor fd) throws RemoteException;
 
     public int getActivityStackId(IBinder token) throws RemoteException;
-    public void moveActivityToStack(IBinder token, int stackId) throws RemoteException;
+    public void exitFreeformMode(IBinder token) throws RemoteException;
 
     public void suppressResizeConfigChanges(boolean suppress) throws RemoteException;
 
@@ -908,7 +933,7 @@
     int STOP_BINDER_TRACKING_AND_DUMP_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 341;
     int POSITION_TASK_IN_STACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 342;
     int GET_ACTIVITY_STACK_ID_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 343;
-    int MOVE_ACTIVITY_TO_STACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 344;
+    int EXIT_FREEFORM_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 344;
     int REPORT_SIZE_CONFIGURATIONS = IBinder.FIRST_CALL_TRANSACTION + 345;
     int MOVE_TASK_TO_DOCKED_STACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 346;
     int SUPPRESS_RESIZE_CONFIG_CHANGES_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 347;
@@ -920,6 +945,8 @@
     int IN_PICTURE_IN_PICTURE_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 353;
     int KILL_PACKAGE_DEPENDENTS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 354;
     int ENTER_PICTURE_IN_PICTURE_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 355;
-    int SET_VR_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 356;
+    int ACTIVITY_RELAUNCHED_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 356;
     int GET_URI_PERMISSION_OWNER_FOR_ACTIVITY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 357;
+    int RESIZE_DOCKED_STACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 358;
+    int SET_VR_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 359;
 }
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index abe9822..e60cb03 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -78,6 +78,8 @@
     void setOnNotificationPostedTrimFromListener(in INotificationListener token, int trim);
     void setInterruptionFilter(String pkg, int interruptionFilter);
 
+    void setImportanceFromAssistant(in INotificationListener token, String key, int importance, CharSequence explanation);
+
     ComponentName getEffectsSuppressor();
     boolean matchesCallFilter(in Bundle extras);
     boolean isSystemConditionProviderEnabled(String path);
diff --git a/core/java/android/app/ITaskStackListener.aidl b/core/java/android/app/ITaskStackListener.aidl
index 4b0935c..560e22a 100644
--- a/core/java/android/app/ITaskStackListener.aidl
+++ b/core/java/android/app/ITaskStackListener.aidl
@@ -18,5 +18,9 @@
 
 /** @hide */
 oneway interface ITaskStackListener {
+    /** Called whenever there are changes to the state of tasks in a stack. */
     void onTaskStackChanged();
+
+    /** Called whenever an Activity is moved to the pinned stack from another stack. */
+    void onActivityPinned();
 }
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 85d9831..9a3c820 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -637,10 +637,12 @@
         public static final int SUPPRESSED_EFFECTS_UNSET = -1;
         public static final int SUPPRESSED_EFFECT_LIGHTS = 1 << 0;
         public static final int SUPPRESSED_EFFECT_PEEK = 1 << 1;
+        public static final int SUPPRESSED_EFFECT_SCREEN_ON = 1 << 2;
 
         private static final int[] ALL_SUPPRESSED_EFFECTS = {
                 SUPPRESSED_EFFECT_LIGHTS,
                 SUPPRESSED_EFFECT_PEEK,
+                SUPPRESSED_EFFECT_SCREEN_ON,
         };
 
         /**
@@ -750,6 +752,7 @@
             switch (effect) {
                 case SUPPRESSED_EFFECT_LIGHTS: return "SUPPRESSED_EFFECT_LIGHTS";
                 case SUPPRESSED_EFFECT_PEEK: return "SUPPRESSED_EFFECT_PEEK";
+                case SUPPRESSED_EFFECT_SCREEN_ON: return "SUPPRESSED_EFFECT_SCREEN_ON";
                 case SUPPRESSED_EFFECTS_UNSET: return "SUPPRESSED_EFFECTS_UNSET";
                 default: return "UNKNOWN_" + effect;
             }
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java
index 288a2cb..89d52f2 100644
--- a/core/java/android/app/SystemServiceRegistry.java
+++ b/core/java/android/app/SystemServiceRegistry.java
@@ -247,7 +247,7 @@
                 new CachedServiceFetcher<DownloadManager>() {
             @Override
             public DownloadManager createService(ContextImpl ctx) {
-                return new DownloadManager(ctx.getContentResolver(), ctx.getPackageName());
+                return new DownloadManager(ctx);
             }});
 
         registerService(Context.BATTERY_SERVICE, BatteryManager.class,
diff --git a/core/java/android/app/UiAutomation.java b/core/java/android/app/UiAutomation.java
index f7848f9..8475840 100644
--- a/core/java/android/app/UiAutomation.java
+++ b/core/java/android/app/UiAutomation.java
@@ -22,6 +22,7 @@
 import android.accessibilityservice.IAccessibilityServiceClient;
 import android.accessibilityservice.IAccessibilityServiceConnection;
 import android.annotation.NonNull;
+import android.annotation.TestApi;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Point;
@@ -856,6 +857,7 @@
      *
      * @hide
      */
+    @TestApi
     public boolean grantRuntimePermission(String packageName, String permission,
             UserHandle userHandle) {
         synchronized (mLock) {
@@ -884,6 +886,7 @@
      *
      * @hide
      */
+    @TestApi
     public boolean revokeRuntimePermission(String packageName, String permission,
             UserHandle userHandle) {
         synchronized (mLock) {
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index eda0982..08e9b1e 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -88,13 +88,15 @@
 
     private final Context mContext;
     private final IDevicePolicyManager mService;
+    private boolean mParentInstance;
 
     private static final String REMOTE_EXCEPTION_MESSAGE =
             "Failed to talk with device policy manager service";
 
-    private DevicePolicyManager(Context context) {
+    private DevicePolicyManager(Context context, boolean parentInstance) {
         this(context, IDevicePolicyManager.Stub.asInterface(
                         ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)));
+        mParentInstance = parentInstance;
     }
 
     /** @hide */
@@ -106,7 +108,7 @@
 
     /** @hide */
     public static DevicePolicyManager create(Context context) {
-        DevicePolicyManager me = new DevicePolicyManager(context);
+        DevicePolicyManager me = new DevicePolicyManager(context, false);
         return me.mService != null ? me : null;
     }
 
@@ -1031,7 +1033,7 @@
     public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
         if (mService != null) {
             try {
-                mService.setPasswordQuality(admin, quality);
+                mService.setPasswordQuality(admin, quality, mParentInstance);
             } catch (RemoteException e) {
                 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
             }
@@ -1052,7 +1054,7 @@
     public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
         if (mService != null) {
             try {
-                return mService.getPasswordQuality(admin, userHandle);
+                return mService.getPasswordQuality(admin, userHandle, mParentInstance);
             } catch (RemoteException e) {
                 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
             }
@@ -1622,7 +1624,7 @@
     public boolean isActivePasswordSufficient() {
         if (mService != null) {
             try {
-                return mService.isActivePasswordSufficient(myUserId());
+                return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
             } catch (RemoteException e) {
                 Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
             }
@@ -1791,6 +1793,9 @@
      * not acceptable for the current constraints or if the user has not been decrypted yet.
      */
     public boolean resetPassword(String password, int flags) {
+        if (mParentInstance) {
+            throw new SecurityException("Reset password does not work across profiles.");
+        }
         if (mService != null) {
             try {
                 return mService.resetPassword(password, flags);
@@ -3060,6 +3065,8 @@
      *
      * <p>If the device owner information is {@code null} or empty then the device owner info is
      * cleared and the user owner info is shown on the lock screen if it is set.
+     * <p>If the device owner information contains only whitespaces then the message on the lock
+     * screen will be blank and the user will not be allowed to change it.
      *
      * @param admin The name of the admin component to check.
      * @param info Device owner information which will be displayed instead of the user
@@ -4802,4 +4809,148 @@
             Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
         }
     }
+
+    /**
+     * Called by a device admin to set the short support message. This will
+     * be displayed to the user in settings screens where funtionality has
+     * been disabled by the admin.
+     *
+     * The message should be limited to a short statement such as
+     * "This setting is disabled by your administrator. Contact someone@example.com
+     *  for support."
+     * If the message is longer than 200 characters it may be truncated.
+     *
+     * @see #setLongSupportMessage
+     *
+     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+     * @param message Short message to be displayed to the user in settings or null to
+     *        clear the existing message.
+     */
+    public void setShortSupportMessage(@NonNull ComponentName admin,
+            @Nullable String message) {
+        if (mService != null) {
+            try {
+                mService.setShortSupportMessage(admin, message);
+            } catch (RemoteException e) {
+                Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
+            }
+        }
+    }
+
+    /**
+     * Called by a device admin to get the short support message.
+     *
+     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+     * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
+     *         or null if no message has been set.
+     */
+    public String getShortSupportMessage(@NonNull ComponentName admin) {
+        if (mService != null) {
+            try {
+                return mService.getShortSupportMessage(admin);
+            } catch (RemoteException e) {
+                Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Called by a device admin to set the long support message. This will
+     * be displayed to the user in the device administators settings screen.
+     *
+     * @see #setShortSupportMessage
+     *
+     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+     * @param message Long message to be displayed to the user in settings or null to
+     *        clear the existing message.
+     */
+    public void setLongSupportMessage(@NonNull ComponentName admin,
+            @Nullable String message) {
+        if (mService != null) {
+            try {
+                mService.setLongSupportMessage(admin, message);
+            } catch (RemoteException e) {
+                Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
+            }
+        }
+    }
+
+    /**
+     * Called by a device admin to get the long support message.
+     *
+     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+     * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
+     *         or null if no message has been set.
+     */
+    public String getLongSupportMessage(@NonNull ComponentName admin) {
+        if (mService != null) {
+            try {
+                return mService.getLongSupportMessage(admin);
+            } catch (RemoteException e) {
+                Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Called by the system to get the short support message.
+     *
+     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+     * @param userHandle user id the admin is running as.
+     * @return The message set by {@link #setShortSupportMessage(ComponentName, String)}
+     *
+     * @hide
+     */
+    public String getShortSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
+        if (mService != null) {
+            try {
+                return mService.getShortSupportMessageForUser(admin, userHandle);
+            } catch (RemoteException e) {
+                Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
+            }
+        }
+        return null;
+    }
+
+
+    /**
+     * Called by the system to get the long support message.
+     *
+     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+     * @param userHandle user id the admin is running as.
+     * @return The message set by {@link #setLongSupportMessage(ComponentName, String)}
+     *
+     * @hide
+     */
+    public String getLongSupportMessageForUser(@NonNull ComponentName admin, int userHandle) {
+        if (mService != null) {
+            try {
+                return mService.getLongSupportMessageForUser(admin, userHandle);
+            } catch (RemoteException e) {
+                Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Obtains a {@link DevicePolicyManager} whose calls act on the parent profile.
+     *
+     * <p> Note only some methods will work on the parent Manager.
+     *
+     * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
+     */
+    public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
+        try {
+            if (!mService.isManagedProfile(admin)) {
+                throw new SecurityException("The current user does not have a parent profile.");
+            }
+            return new DevicePolicyManager(mContext, true);
+        } catch (RemoteException re) {
+            Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
+            return null;
+        }
+    }
 }
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index 30ce682..754cb43 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -35,8 +35,8 @@
  * {@hide}
  */
 interface IDevicePolicyManager {
-    void setPasswordQuality(in ComponentName who, int quality);
-    int getPasswordQuality(in ComponentName who, int userHandle);
+    void setPasswordQuality(in ComponentName who, int quality, boolean parent);
+    int getPasswordQuality(in ComponentName who, int userHandle, boolean parent);
 
     void setPasswordMinimumLength(in ComponentName who, int length);
     int getPasswordMinimumLength(in ComponentName who, int userHandle);
@@ -67,7 +67,7 @@
 
     long getPasswordExpiration(in ComponentName who, int userHandle);
 
-    boolean isActivePasswordSufficient(int userHandle);
+    boolean isActivePasswordSufficient(int userHandle, boolean parent);
     int getCurrentFailedPasswordAttempts(int userHandle);
     int getProfileWithMinimumFailedPasswordsForWipe(int userHandle);
 
@@ -245,4 +245,12 @@
     boolean isSystemOnlyUser(in ComponentName admin);
     String getWifiMacAddress();
     void reboot(in ComponentName admin);
+
+    void setShortSupportMessage(in ComponentName admin, in String message);
+    String getShortSupportMessage(in ComponentName admin);
+    void setLongSupportMessage(in ComponentName admin, in String message);
+    String getLongSupportMessage(in ComponentName admin);
+
+    String getShortSupportMessageForUser(in ComponentName admin, int userHandle);
+    String getLongSupportMessageForUser(in ComponentName admin, int userHandle);
 }
diff --git a/core/java/android/app/job/JobScheduler.java b/core/java/android/app/job/JobScheduler.java
index a1c11f3..6e96da5 100644
--- a/core/java/android/app/job/JobScheduler.java
+++ b/core/java/android/app/job/JobScheduler.java
@@ -50,18 +50,15 @@
      */
     public static final int RESULT_FAILURE = 0;
     /**
-     * Returned from {@link #schedule(JobInfo)} if this application has made too many requests for
-     * work over too short a time.
+     * Returned from {@link #schedule(JobInfo)} if this job has been successfully scheduled.
      */
-    // TODO: Determine if this is necessary.
     public static final int RESULT_SUCCESS = 1;
 
     /**
      * @param job The job you wish scheduled. See
      * {@link android.app.job.JobInfo.Builder JobInfo.Builder} for more detail on the sorts of jobs
      * you can schedule.
-     * @return If >0, this int returns the jobId of the successfully scheduled job.
-     * Otherwise you have to compare the return value to the error codes defined in this class.
+     * @return An int representing ({@link #RESULT_SUCCESS} or {@link #RESULT_FAILURE}).
      */
     public abstract int schedule(JobInfo job);
 
diff --git a/core/java/android/content/ContentProviderClient.java b/core/java/android/content/ContentProviderClient.java
index d12595f..16b5a4b 100644
--- a/core/java/android/content/ContentProviderClient.java
+++ b/core/java/android/content/ContentProviderClient.java
@@ -19,6 +19,7 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.res.AssetFileDescriptor;
+import android.database.CrossProcessCursorWrapper;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Bundle;
@@ -32,27 +33,34 @@
 import android.util.Log;
 
 import com.android.internal.annotations.GuardedBy;
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.Preconditions;
 
 import dalvik.system.CloseGuard;
 
 import java.io.FileNotFoundException;
 import java.util.ArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
- * The public interface object used to interact with a {@link ContentProvider}. This is obtained by
- * calling {@link ContentResolver#acquireContentProviderClient}. This object must be released
- * using {@link #release} in order to indicate to the system that the {@link ContentProvider} is
- * no longer needed and can be killed to free up resources.
- *
- * <p>Note that you should generally create a new ContentProviderClient instance
- * for each thread that will be performing operations.  Unlike
+ * The public interface object used to interact with a specific
+ * {@link ContentProvider}.
+ * <p>
+ * Instances can be obtained by calling
+ * {@link ContentResolver#acquireContentProviderClient} or
+ * {@link ContentResolver#acquireUnstableContentProviderClient}. Instances must
+ * be released using {@link #close()} in order to indicate to the system that
+ * the underlying {@link ContentProvider} is no longer needed and can be killed
+ * to free up resources.
+ * <p>
+ * Note that you should generally create a new ContentProviderClient instance
+ * for each thread that will be performing operations. Unlike
  * {@link ContentResolver}, the methods here such as {@link #query} and
- * {@link #openFile} are not thread safe -- you must not call
- * {@link #release()} on the ContentProviderClient those calls are made from
- * until you are finished with the data they have returned.
+ * {@link #openFile} are not thread safe -- you must not call {@link #close()}
+ * on the ContentProviderClient those calls are made from until you are finished
+ * with the data they have returned.
  */
-public class ContentProviderClient {
+public class ContentProviderClient implements AutoCloseable {
     private static final String TAG = "ContentProviderClient";
 
     @GuardedBy("ContentProviderClient.class")
@@ -63,22 +71,23 @@
     private final String mPackageName;
     private final boolean mStable;
 
-    private final CloseGuard mGuard = CloseGuard.get();
+    private final AtomicBoolean mClosed = new AtomicBoolean();
+    private final CloseGuard mCloseGuard = CloseGuard.get();
 
     private long mAnrTimeout;
     private NotRespondingRunnable mAnrRunnable;
 
-    private boolean mReleased;
-
     /** {@hide} */
-    ContentProviderClient(
+    @VisibleForTesting
+    public ContentProviderClient(
             ContentResolver contentResolver, IContentProvider contentProvider, boolean stable) {
         mContentResolver = contentResolver;
         mContentProvider = contentProvider;
         mPackageName = contentResolver.mPackageName;
+
         mStable = stable;
 
-        mGuard.open("release");
+        mCloseGuard.open("close");
     }
 
     /** {@hide} */
@@ -133,8 +142,14 @@
                 remoteCancellationSignal = mContentProvider.createCancellationSignal();
                 cancellationSignal.setRemote(remoteCancellationSignal);
             }
-            return mContentProvider.query(mPackageName, url, projection, selection, selectionArgs,
-                    sortOrder, remoteCancellationSignal);
+            final Cursor cursor = mContentProvider.query(mPackageName, url, projection, selection,
+                    selectionArgs, sortOrder, remoteCancellationSignal);
+            if ("com.google.android.gms".equals(mPackageName)) {
+                // They're casting to a concrete subclass, sigh
+                return cursor;
+            } else {
+                return new CursorWrapperInner(cursor);
+            }
         } catch (DeadObjectException e) {
             if (!mStable) {
                 mContentResolver.unstableProviderDied(mContentProvider);
@@ -446,29 +461,42 @@
     }
 
     /**
-     * Call this to indicate to the system that the associated {@link ContentProvider} is no
-     * longer needed by this {@link ContentProviderClient}.
-     * @return true if this was release, false if it was already released
+     * Closes this client connection, indicating to the system that the
+     * underlying {@link ContentProvider} is no longer needed.
      */
+    @Override
+    public void close() {
+        closeInternal();
+    }
+
+    /**
+     * @deprecated replaced by {@link #close()}.
+     */
+    @Deprecated
     public boolean release() {
-        synchronized (this) {
-            if (mReleased) {
-                throw new IllegalStateException("Already released");
-            }
-            mReleased = true;
-            mGuard.close();
+        return closeInternal();
+    }
+
+    private boolean closeInternal() {
+        mCloseGuard.close();
+        if (mClosed.compareAndSet(false, true)) {
             if (mStable) {
                 return mContentResolver.releaseProvider(mContentProvider);
             } else {
                 return mContentResolver.releaseUnstableProvider(mContentProvider);
             }
+        } else {
+            return false;
         }
     }
 
     @Override
     protected void finalize() throws Throwable {
-        if (mGuard != null) {
-            mGuard.warnIfOpen();
+        try {
+            mCloseGuard.warnIfOpen();
+            close();
+        } finally {
+            super.finalize();
         }
     }
 
@@ -502,4 +530,29 @@
             mContentResolver.appNotRespondingViaProvider(mContentProvider);
         }
     }
+
+    private final class CursorWrapperInner extends CrossProcessCursorWrapper {
+        private final CloseGuard mCloseGuard = CloseGuard.get();
+
+        CursorWrapperInner(Cursor cursor) {
+            super(cursor);
+            mCloseGuard.open("close");
+        }
+
+        @Override
+        public void close() {
+            mCloseGuard.close();
+            super.close();
+        }
+
+        @Override
+        protected void finalize() throws Throwable {
+            try {
+                mCloseGuard.warnIfOpen();
+                close();
+            } finally {
+                super.finalize();
+            }
+        }
+    }
 }
diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java
index 9d0ebc2..684a85e 100644
--- a/core/java/android/content/ContentResolver.java
+++ b/core/java/android/content/ContentResolver.java
@@ -20,6 +20,8 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.RequiresPermission;
+import android.annotation.TestApi;
+import android.annotation.UserIdInt;
 import android.app.ActivityManagerNative;
 import android.app.ActivityThread;
 import android.app.AppGlobals;
@@ -47,11 +49,11 @@
 import android.util.EventLog;
 import android.util.Log;
 
-import dalvik.system.CloseGuard;
-
 import com.android.internal.util.ArrayUtils;
 import com.android.internal.util.Preconditions;
 
+import dalvik.system.CloseGuard;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -59,9 +61,9 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Random;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * This class provides applications access to the content model.
@@ -514,8 +516,9 @@
             maybeLogQueryToEventLog(durationMillis, uri, projection, selection, sortOrder);
 
             // Wrap the cursor object into CursorWrapperInner object.
-            CursorWrapperInner wrapper = new CursorWrapperInner(qCursor,
-                    stableProvider != null ? stableProvider : acquireProvider(uri));
+            final IContentProvider provider = (stableProvider != null) ? stableProvider
+                    : acquireProvider(uri);
+            final CursorWrapperInner wrapper = new CursorWrapperInner(qCursor, provider);
             stableProvider = null;
             qCursor = null;
             return wrapper;
@@ -1609,7 +1612,7 @@
 
     /** @hide - designated user version */
     public final void registerContentObserver(Uri uri, boolean notifyForDescendents,
-            ContentObserver observer, int userHandle) {
+            ContentObserver observer, @UserIdInt int userHandle) {
         try {
             getContentService().registerContentObserver(uri, notifyForDescendents,
                     observer.getContentObserver(), userHandle);
@@ -1683,7 +1686,7 @@
      * @hide
      */
     public void notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork,
-            int userHandle) {
+            @UserIdInt int userHandle) {
         try {
             getContentService().notifyChange(
                     uri, observer == null ? null : observer.getContentObserver(),
@@ -1824,7 +1827,7 @@
      * @see #requestSync(Account, String, Bundle)
      * @hide
      */
-    public static void requestSyncAsUser(Account account, String authority, int userId,
+    public static void requestSyncAsUser(Account account, String authority, @UserIdInt int userId,
             Bundle extras) {
         if (extras == null) {
             throw new IllegalArgumentException("Must specify extras.");
@@ -1921,7 +1924,7 @@
      * @see #cancelSync(Account, String)
      * @hide
      */
-    public static void cancelSyncAsUser(Account account, String authority, int userId) {
+    public static void cancelSyncAsUser(Account account, String authority, @UserIdInt int userId) {
         try {
             getContentService().cancelSyncAsUser(account, authority, null, userId);
         } catch (RemoteException e) {
@@ -1944,7 +1947,7 @@
      * @see #getSyncAdapterTypes()
      * @hide
      */
-    public static SyncAdapterType[] getSyncAdapterTypesAsUser(int userId) {
+    public static SyncAdapterType[] getSyncAdapterTypesAsUser(@UserIdInt int userId) {
         try {
             return getContentService().getSyncAdapterTypesAsUser(userId);
         } catch (RemoteException e) {
@@ -1956,8 +1959,9 @@
      * @hide
      * Returns the package names of syncadapters that match a given user and authority.
      */
+    @TestApi
     public static String[] getSyncAdapterPackagesForAuthorityAsUser(String authority,
-            int userId) {
+            @UserIdInt int userId) {
         try {
             return getContentService().getSyncAdapterPackagesForAuthorityAsUser(authority, userId);
         } catch (RemoteException e) {
@@ -1987,7 +1991,7 @@
      * @hide
      */
     public static boolean getSyncAutomaticallyAsUser(Account account, String authority,
-            int userId) {
+            @UserIdInt int userId) {
         try {
             return getContentService().getSyncAutomaticallyAsUser(account, authority, userId);
         } catch (RemoteException e) {
@@ -2013,7 +2017,7 @@
      * @hide
      */
     public static void setSyncAutomaticallyAsUser(Account account, String authority, boolean sync,
-            int userId) {
+            @UserIdInt int userId) {
         try {
             getContentService().setSyncAutomaticallyAsUser(account, authority, sync, userId);
         } catch (RemoteException e) {
@@ -2172,7 +2176,8 @@
      * @see #getIsSyncable(Account, String)
      * @hide
      */
-    public static int getIsSyncableAsUser(Account account, String authority, int userId) {
+    public static int getIsSyncableAsUser(Account account, String authority,
+            @UserIdInt int userId) {
         try {
             return getContentService().getIsSyncableAsUser(account, authority, userId);
         } catch (RemoteException e) {
@@ -2215,7 +2220,7 @@
      * @see #getMasterSyncAutomatically()
      * @hide
      */
-    public static boolean getMasterSyncAutomaticallyAsUser(int userId) {
+    public static boolean getMasterSyncAutomaticallyAsUser(@UserIdInt int userId) {
         try {
             return getContentService().getMasterSyncAutomaticallyAsUser(userId);
         } catch (RemoteException e) {
@@ -2239,7 +2244,7 @@
      * @see #setMasterSyncAutomatically(boolean)
      * @hide
      */
-    public static void setMasterSyncAutomaticallyAsUser(boolean sync, int userId) {
+    public static void setMasterSyncAutomaticallyAsUser(boolean sync, @UserIdInt int userId) {
         try {
             getContentService().setMasterSyncAutomaticallyAsUser(sync, userId);
         } catch (RemoteException e) {
@@ -2319,7 +2324,7 @@
      * @see #getCurrentSyncs()
      * @hide
      */
-    public static List<SyncInfo> getCurrentSyncsAsUser(int userId) {
+    public static List<SyncInfo> getCurrentSyncsAsUser(@UserIdInt int userId) {
         try {
             return getContentService().getCurrentSyncsAsUser(userId);
         } catch (RemoteException e) {
@@ -2347,7 +2352,7 @@
      * @hide
      */
     public static SyncStatusInfo getSyncStatusAsUser(Account account, String authority,
-            int userId) {
+            @UserIdInt int userId) {
         try {
             return getContentService().getSyncStatusAsUser(account, authority, null, userId);
         } catch (RemoteException e) {
@@ -2371,7 +2376,8 @@
      * @see #requestSync(Account, String, Bundle)
      * @hide
      */
-    public static boolean isSyncPendingAsUser(Account account, String authority, int userId) {
+    public static boolean isSyncPendingAsUser(Account account, String authority,
+            @UserIdInt int userId) {
         try {
             return getContentService().isSyncPendingAsUser(account, authority, null, userId);
         } catch (RemoteException e) {
@@ -2503,41 +2509,31 @@
 
     private final class CursorWrapperInner extends CrossProcessCursorWrapper {
         private final IContentProvider mContentProvider;
-        public static final String TAG="CursorWrapperInner";
+        private final AtomicBoolean mProviderReleased = new AtomicBoolean();
 
         private final CloseGuard mCloseGuard = CloseGuard.get();
-        private boolean mProviderReleased;
 
-        CursorWrapperInner(Cursor cursor, IContentProvider icp) {
+        CursorWrapperInner(Cursor cursor, IContentProvider contentProvider) {
             super(cursor);
-            mContentProvider = icp;
+            mContentProvider = contentProvider;
             mCloseGuard.open("close");
         }
 
         @Override
         public void close() {
+            mCloseGuard.close();
             super.close();
-            ContentResolver.this.releaseProvider(mContentProvider);
-            mProviderReleased = true;
 
-            if (mCloseGuard != null) {
-                mCloseGuard.close();
+            if (mProviderReleased.compareAndSet(false, true)) {
+                ContentResolver.this.releaseProvider(mContentProvider);
             }
         }
 
         @Override
         protected void finalize() throws Throwable {
             try {
-                if (mCloseGuard != null) {
-                    mCloseGuard.warnIfOpen();
-                }
-
-                if (!mProviderReleased && mContentProvider != null) {
-                    // Even though we are using CloseGuard, log this anyway so that
-                    // application developers always see the message in the log.
-                    Log.w(TAG, "Cursor finalized without prior close()");
-                    ContentResolver.this.releaseProvider(mContentProvider);
-                }
+                mCloseGuard.warnIfOpen();
+                close();
             } finally {
                 super.finalize();
             }
@@ -2546,7 +2542,7 @@
 
     private final class ParcelFileDescriptorInner extends ParcelFileDescriptor {
         private final IContentProvider mContentProvider;
-        private boolean mProviderReleased;
+        private final AtomicBoolean mProviderReleased = new AtomicBoolean();
 
         ParcelFileDescriptorInner(ParcelFileDescriptor pfd, IContentProvider icp) {
             super(pfd);
@@ -2555,9 +2551,8 @@
 
         @Override
         public void releaseResources() {
-            if (!mProviderReleased) {
+            if (mProviderReleased.compareAndSet(false, true)) {
                 ContentResolver.this.releaseProvider(mContentProvider);
-                mProviderReleased = true;
             }
         }
     }
@@ -2584,7 +2579,9 @@
 
     private static IContentService sContentService;
     private final Context mContext;
+
     final String mPackageName;
+
     private static final String TAG = "ContentResolver";
 
     /** @hide */
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 67bdad5..a6036bb 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -30,6 +30,8 @@
 import android.annotation.StyleRes;
 import android.annotation.StyleableRes;
 import android.annotation.SystemApi;
+import android.annotation.TestApi;
+import android.annotation.UserIdInt;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.content.res.AssetManager;
@@ -3967,7 +3969,8 @@
      *
      * @hide
      */
-    public abstract int getUserId();
+    @TestApi
+    public abstract @UserIdInt int getUserId();
 
     /**
      * Return a new Context object for the current Context but whose resources
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 0f3ca10..35cd2be 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -3604,6 +3604,15 @@
     public static final String EXTRA_USER_ID = "android.intent.extra.USER_ID";
 
     /**
+     * An int representing the task id to be retrieved. This is used when a launch from recents is
+     * intercepted by another action such as credentials confirmation to remember which task should
+     * be resumed when complete.
+     *
+     * @hide
+     */
+    public static final String EXTRA_TASK_ID = "android.intent.extra.TASK_ID";
+
+    /**
      * An Intent[] describing additional, alternate choices you would like shown with
      * {@link #ACTION_CHOOSER}.
      *
@@ -4169,11 +4178,18 @@
 
     /**
      * Internal flag used to indicate that a system component has done their
-     * homework and verified their encryption-aware behavior.
+     * homework and verified that they correctly handle packages and components
+     * that come and go over time. In particular:
+     * <ul>
+     * <li>Apps installed on external storage, which will appear to be
+     * uninstalled while the the device is ejected.
+     * <li>Apps with encryption unaware components, which will appear to not
+     * exist while the device is locked.
+     * </ul>
      *
      * @hide
      */
-    public static final int FLAG_DEBUG_ENCRYPTION_TRIAGED = 0x00000100;
+    public static final int FLAG_DEBUG_TRIAGED_MISSING = 0x00000100;
 
     /**
      * If set, the new activity is not kept in the history stack.  As soon as
diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java
index 326735e..dedf07f5 100644
--- a/core/java/android/content/pm/ActivityInfo.java
+++ b/core/java/android/content/pm/ActivityInfo.java
@@ -281,6 +281,29 @@
      * {@see android.app.Activity#setVrMode(boolean)}.
      */
     public static final int FLAG_ENABLE_VR_MODE = 0x8000;
+
+    /**
+     * Bit in {@link #flags} indicating if the activity is resizeable to any dimension.
+     * See {@link android.R.attr#resizeableActivity}.
+     * @hide
+     */
+    public static final int FLAG_RESIZEABLE = 0x10000;
+
+    /**
+     * Bit in {@link #flags} indicating if the activity is supports picture-in-picture form of
+     * multi-window mode. See {@link android.R.attr#supportsPictureInPicture}.
+     * @hide
+     */
+    public static final int FLAG_SUPPORTS_PICTURE_IN_PICTURE = 0x20000;
+
+    /**
+     * Bit in {@link #flags} indicating if the activity is always focusable regardless of if it is
+     * in a task/stack whose activities are normally not focusable.
+     * See android.R.attr#alwaysFocusable.
+     * @hide
+     */
+    public static final int FLAG_ALWAYS_FOCUSABLE = 0x40000;
+
     /**
      * @hide Bit in {@link #flags}: If set, this component will only be seen
      * by the system user.  Only works with broadcast receivers.  Set from the
@@ -670,20 +693,6 @@
      */
     public String parentActivityName;
 
-    /**
-     * Value indicating if the activity is resizeable to any dimension.
-     * See {@link android.R.attr#resizeableActivity}.
-     * @hide
-     */
-    public boolean resizeable;
-
-    /**
-     * Value indicating if the activity is supports picture-in-picture form of multi-window mode.
-     * See {@link android.R.attr#supportsPictureInPicture}.
-     * @hide
-     */
-    public boolean supportsPip;
-
     /** @hide */
     public static final int LOCK_TASK_LAUNCH_MODE_DEFAULT = 0;
     /** @hide */
@@ -735,8 +744,6 @@
         uiOptions = orig.uiOptions;
         parentActivityName = orig.parentActivityName;
         maxRecents = orig.maxRecents;
-        resizeable = orig.resizeable;
-        supportsPip = orig.supportsPip;
         lockTaskLaunchMode = orig.lockTaskLaunchMode;
         layout = orig.layout;
     }
@@ -791,7 +798,6 @@
             pw.println(prefix + " uiOptions=0x" + Integer.toHexString(uiOptions));
         }
         if ((flags&DUMP_FLAG_DETAILS) != 0) {
-            pw.println(prefix + "resizeable=" + resizeable + " supportsPip=" + supportsPip);
             pw.println(prefix + "lockTaskLaunchMode="
                     + lockTaskLaunchModeToString(lockTaskLaunchMode));
         }
@@ -829,8 +835,6 @@
         dest.writeString(parentActivityName);
         dest.writeInt(persistableMode);
         dest.writeInt(maxRecents);
-        dest.writeInt(resizeable ? 1 : 0);
-        dest.writeInt(supportsPip ? 1 : 0);
         dest.writeInt(lockTaskLaunchMode);
         if (layout != null) {
             dest.writeInt(1);
@@ -871,8 +875,6 @@
         parentActivityName = source.readString();
         persistableMode = source.readInt();
         maxRecents = source.readInt();
-        resizeable = (source.readInt() == 1);
-        supportsPip = (source.readInt() == 1);
         lockTaskLaunchMode = source.readInt();
         if (source.readInt() == 1) {
             layout = new Layout(source);
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index fe279d1..0168908 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -16,6 +16,7 @@
 
 package android.content.pm;
 
+import android.annotation.TestApi;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.Resources;
 import android.graphics.drawable.Drawable;
@@ -803,7 +804,12 @@
     public boolean hasRtlSupport() {
         return (flags & FLAG_SUPPORTS_RTL) == FLAG_SUPPORTS_RTL;
     }
-    
+
+    /** {@hide} */
+    public boolean hasCode() {
+        return (flags & FLAG_HAS_CODE) != 0;
+    }
+
     public static class DisplayNameComparator
             implements Comparator<ApplicationInfo> {
         public DisplayNameComparator(PackageManager pm) {
@@ -1069,6 +1075,7 @@
     /**
      * @hide
      */
+    @TestApi
     public boolean isSystemApp() {
         return (flags & ApplicationInfo.FLAG_SYSTEM) != 0;
     }
@@ -1076,6 +1083,7 @@
     /**
      * @hide
      */
+    @TestApi
     public boolean isPrivilegedApp() {
         return (privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
     }
diff --git a/core/java/android/content/pm/ManifestDigest.java b/core/java/android/content/pm/ManifestDigest.java
deleted file mode 100644
index e7dc764..0000000
--- a/core/java/android/content/pm/ManifestDigest.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.content.pm;
-
-import com.android.internal.util.HexDump;
-
-import android.annotation.SystemApi;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.util.Slog;
-
-import java.io.BufferedInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.DigestInputStream;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
-
-import libcore.io.IoUtils;
-
-/**
- * Represents the manifest digest for a package. This is suitable for comparison
- * of two packages to know whether the manifests are identical.
- *
- * @hide
- */
-@SystemApi
-public class ManifestDigest implements Parcelable {
-    private static final String TAG = "ManifestDigest";
-
-    /** The digest of the manifest in our preferred order. */
-    private final byte[] mDigest;
-
-    /** What we print out first when toString() is called. */
-    private static final String TO_STRING_PREFIX = "ManifestDigest {mDigest=";
-
-    /** Digest algorithm to use. */
-    private static final String DIGEST_ALGORITHM = "SHA-256";
-
-    ManifestDigest(byte[] digest) {
-        mDigest = digest;
-    }
-
-    private ManifestDigest(Parcel source) {
-        mDigest = source.createByteArray();
-    }
-
-    static ManifestDigest fromInputStream(InputStream fileIs) {
-        if (fileIs == null) {
-            return null;
-        }
-
-        final MessageDigest md;
-        try {
-            md = MessageDigest.getInstance(DIGEST_ALGORITHM);
-        } catch (NoSuchAlgorithmException e) {
-            throw new RuntimeException(DIGEST_ALGORITHM + " must be available", e);
-        }
-
-        final DigestInputStream dis = new DigestInputStream(new BufferedInputStream(fileIs), md);
-        try {
-            byte[] readBuffer = new byte[8192];
-            while (dis.read(readBuffer, 0, readBuffer.length) != -1) {
-                // not using
-            }
-        } catch (IOException e) {
-            Slog.w(TAG, "Could not read manifest");
-            return null;
-        } finally {
-            IoUtils.closeQuietly(dis);
-        }
-
-        final byte[] digest = md.digest();
-        return new ManifestDigest(digest);
-    }
-
-    @Override
-    public int describeContents() {
-        return 0;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (!(o instanceof ManifestDigest)) {
-            return false;
-        }
-
-        final ManifestDigest other = (ManifestDigest) o;
-
-        return this == other || Arrays.equals(mDigest, other.mDigest);
-    }
-
-    @Override
-    public int hashCode() {
-        return Arrays.hashCode(mDigest);
-    }
-
-    @Override
-    public String toString() {
-        final StringBuilder sb = new StringBuilder(TO_STRING_PREFIX.length()
-                + (mDigest.length * 3) + 1);
-
-        sb.append(TO_STRING_PREFIX);
-
-        final int N = mDigest.length;
-        for (int i = 0; i < N; i++) {
-            final byte b = mDigest[i];
-            HexDump.appendByteAsHex(sb, b, false);
-            sb.append(',');
-        }
-        sb.append('}');
-
-        return sb.toString();
-    }
-
-    @Override
-    public void writeToParcel(Parcel dest, int flags) {
-        dest.writeByteArray(mDigest);
-    }
-
-    public static final Parcelable.Creator<ManifestDigest> CREATOR
-            = new Parcelable.Creator<ManifestDigest>() {
-        public ManifestDigest createFromParcel(Parcel source) {
-            return new ManifestDigest(source);
-        }
-
-        public ManifestDigest[] newArray(int size) {
-            return new ManifestDigest[size];
-        }
-    };
-
-}
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 69f508e..9d94b74 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -27,6 +27,8 @@
 import android.annotation.SdkConstant.SdkConstantType;
 import android.annotation.StringRes;
 import android.annotation.SystemApi;
+import android.annotation.UserIdInt;
+import android.annotation.TestApi;
 import android.annotation.XmlRes;
 import android.app.PackageDeleteObserver;
 import android.app.PackageInstallObserver;
@@ -93,6 +95,109 @@
     }
 
     /**
+     * As a guiding principle:
+     * <p>
+     * {@code GET_} flags are used to request additional data that may have been
+     * elided to save wire space.
+     * <p>
+     * {@code MATCH_} flags are used to include components or packages that
+     * would have otherwise been omitted from a result set by current system
+     * state.
+     */
+
+    /** @hide */
+    @IntDef(flag = true, value = {
+            GET_ACTIVITIES,
+            GET_RECEIVERS,
+            GET_SERVICES,
+            GET_PROVIDERS,
+            GET_INSTRUMENTATION,
+            GET_INTENT_FILTERS,
+            GET_SIGNATURES,
+            GET_META_DATA,
+            GET_GIDS,
+            GET_SHARED_LIBRARY_FILES,
+            GET_URI_PERMISSION_PATTERNS,
+            GET_PERMISSIONS,
+            GET_CONFIGURATIONS,
+            MATCH_UNINSTALLED_PACKAGES,
+            MATCH_DISABLED_COMPONENTS,
+            MATCH_DISABLED_UNTIL_USED_COMPONENTS,
+            MATCH_DEBUG_TRIAGED_MISSING,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface PackageInfoFlags {}
+
+    /** @hide */
+    @IntDef(flag = true, value = {
+            GET_META_DATA,
+            GET_SHARED_LIBRARY_FILES,
+            MATCH_UNINSTALLED_PACKAGES,
+            MATCH_SYSTEM_ONLY,
+            MATCH_DEBUG_TRIAGED_MISSING,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface ApplicationInfoFlags {}
+
+    /** @hide */
+    @IntDef(flag = true, value = {
+            GET_META_DATA,
+            GET_SHARED_LIBRARY_FILES,
+            MATCH_UNINSTALLED_PACKAGES,
+            MATCH_DISABLED_COMPONENTS,
+            MATCH_DISABLED_UNTIL_USED_COMPONENTS,
+            MATCH_ALL,
+            MATCH_DEFAULT_ONLY,
+            MATCH_ENCRYPTION_AWARE,
+            MATCH_ENCRYPTION_AWARE_AND_UNAWARE,
+            MATCH_ENCRYPTION_UNAWARE,
+            MATCH_SYSTEM_ONLY,
+            MATCH_DEBUG_TRIAGED_MISSING,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface ComponentInfoFlags {}
+
+    /** @hide */
+    @IntDef(flag = true, value = {
+            GET_META_DATA,
+            GET_SHARED_LIBRARY_FILES,
+            GET_RESOLVED_FILTER,
+            MATCH_UNINSTALLED_PACKAGES,
+            MATCH_DISABLED_COMPONENTS,
+            MATCH_DISABLED_UNTIL_USED_COMPONENTS,
+            MATCH_ALL,
+            MATCH_DEFAULT_ONLY,
+            MATCH_ENCRYPTION_AWARE,
+            MATCH_ENCRYPTION_AWARE_AND_UNAWARE,
+            MATCH_ENCRYPTION_UNAWARE,
+            MATCH_SYSTEM_ONLY,
+            MATCH_DEBUG_TRIAGED_MISSING,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface ResolveInfoFlags {}
+
+    /** @hide */
+    @IntDef(flag = true, value = {
+            GET_META_DATA,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface PermissionInfoFlags {}
+
+    /** @hide */
+    @IntDef(flag = true, value = {
+            GET_META_DATA,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface PermissionGroupInfoFlags {}
+
+    /** @hide */
+    @IntDef(flag = true, value = {
+            GET_META_DATA,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface InstrumentationInfoFlags {}
+
+    /**
      * {@link PackageInfo} flag: return information about
      * activities in the package in {@link PackageInfo#activities}.
      */
@@ -161,9 +266,15 @@
     public static final int GET_GIDS                    = 0x00000100;
 
     /**
+     * @deprecated replaced with {@link #MATCH_DISABLED_COMPONENTS}
+     */
+    @Deprecated
+    public static final int GET_DISABLED_COMPONENTS = 0x00000200;
+
+    /**
      * {@link PackageInfo} flag: include disabled components in the returned info.
      */
-    public static final int GET_DISABLED_COMPONENTS     = 0x00000200;
+    public static final int MATCH_DISABLED_COMPONENTS = 0x00000200;
 
     /**
      * {@link ApplicationInfo} flag: return the
@@ -190,6 +301,12 @@
     public static final int GET_PERMISSIONS               = 0x00001000;
 
     /**
+     * @deprecated replaced with {@link #MATCH_UNINSTALLED_PACKAGES}
+     */
+    @Deprecated
+    public static final int GET_UNINSTALLED_PACKAGES = 0x00002000;
+
+    /**
      * Flag parameter to retrieve some information about all applications (even
      * uninstalled ones) which have data directories. This state could have
      * resulted if applications have been deleted with flag
@@ -199,7 +316,7 @@
      * Note: this flag may cause less information about currently installed
      * applications to be returned.
      */
-    public static final int GET_UNINSTALLED_PACKAGES = 0x00002000;
+    public static final int MATCH_UNINSTALLED_PACKAGES = 0x00002000;
 
     /**
      * {@link PackageInfo} flag: return information about
@@ -211,12 +328,18 @@
     public static final int GET_CONFIGURATIONS = 0x00004000;
 
     /**
+     * @deprecated replaced with {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS}.
+     */
+    @Deprecated
+    public static final int GET_DISABLED_UNTIL_USED_COMPONENTS = 0x00008000;
+
+    /**
      * {@link PackageInfo} flag: include disabled components which are in
      * that state only because of {@link #COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED}
      * in the returned info.  Note that if you set this flag, applications
      * that are in this disabled state will be reported as enabled.
      */
-    public static final int GET_DISABLED_UNTIL_USED_COMPONENTS = 0x00008000;
+    public static final int MATCH_DISABLED_UNTIL_USED_COMPONENTS = 0x00008000;
 
     /**
      * Resolution and querying flag: if set, only filters that support the
@@ -227,48 +350,55 @@
     public static final int MATCH_DEFAULT_ONLY  = 0x00010000;
 
     /**
-     * Querying flag: if set and if the platform is doing any filtering of the results, then
-     * the filtering will not happen. This is a synonym for saying that all results should
-     * be returned.
+     * Querying flag: if set and if the platform is doing any filtering of the
+     * results, then the filtering will not happen. This is a synonym for saying
+     * that all results should be returned.
+     * <p>
+     * <em>This flag should be used with extreme care.</em>
      */
     public static final int MATCH_ALL = 0x00020000;
 
     /**
-     * {@link PackageInfo} flag: include only components which are encryption
-     * unaware in the returned info, regardless of the current user state.
+     * Querying flag: include only components which are encryption unaware in
+     * the returned info, regardless of the current user state.
      */
-    public static final int MATCH_ENCRYPTION_UNAWARE_ONLY = 0x00040000;
+    public static final int MATCH_ENCRYPTION_UNAWARE = 0x00040000;
 
     /**
-     * {@link PackageInfo} flag: include only components which are encryption
-     * aware in the returned info, regardless of the current user state.
+     * Querying flag: include only components which are encryption aware in the
+     * returned info, regardless of the current user state.
      */
-    public static final int MATCH_ENCRYPTION_AWARE_ONLY = 0x00080000;
+    public static final int MATCH_ENCRYPTION_AWARE = 0x00080000;
 
     /**
-     * {@link PackageInfo} flag: include both encryption aware and unaware
-     * components in the returned info, regardless of the current user state.
+     * Querying flag: include both encryption aware and unaware components in
+     * the returned info, regardless of the current user state.
      */
-    public static final int MATCH_ENCRYPTION_AWARE_AND_UNAWARE = MATCH_ENCRYPTION_AWARE_ONLY
-            | MATCH_ENCRYPTION_UNAWARE_ONLY;
+    public static final int MATCH_ENCRYPTION_AWARE_AND_UNAWARE = MATCH_ENCRYPTION_AWARE
+            | MATCH_ENCRYPTION_UNAWARE;
 
     /**
-     * {@link PackageInfo} flag: include only components from applications that
-     * are marked with {@link ApplicationInfo#FLAG_SYSTEM}.
-     *
-     * @hide
+     * Querying flag: include only components from applications that are marked
+     * with {@link ApplicationInfo#FLAG_SYSTEM}.
      */
     public static final int MATCH_SYSTEM_ONLY = 0x00100000;
 
     /**
-     * {@link PackageInfo} flag: use the default encryption matching behavior
-     * based on user state. Internal flag used to indicate that a system
-     * component has done their homework and verified their encryption-aware
-     * behavior.
+     * Internal flag used to indicate that a system component has done their
+     * homework and verified that they correctly handle packages and components
+     * that come and go over time. In particular:
+     * <ul>
+     * <li>Apps installed on external storage, which will appear to be
+     * uninstalled while the the device is ejected.
+     * <li>Apps with encryption unaware components, which will appear to not
+     * exist while the device is locked.
+     * </ul>
      *
+     * @see #MATCH_UNINSTALLED_PACKAGES
+     * @see #MATCH_ENCRYPTION_AWARE_AND_UNAWARE
      * @hide
      */
-    public static final int MATCH_ENCRYPTION_DEFAULT = 0x10000000;
+    public static final int MATCH_DEBUG_TRIAGED_MISSING = 0x10000000;
 
     /**
      * Flag for {@link addCrossProfileIntentFilter}: if this flag is set:
@@ -1819,7 +1949,6 @@
     /**
      * Feature for {@link #getSystemAvailableFeatures} and
      * {@link #hasSystemFeature}: This device supports ethernet.
-     * @hide
      */
     @SdkConstant(SdkConstantType.FEATURE)
     public static final String FEATURE_ETHERNET = "android.hardware.ethernet";
@@ -2100,9 +2229,6 @@
     /**
      * Retrieve overall information about an application package that is
      * installed on the system.
-     * <p>
-     * Throws {@link NameNotFoundException} if a package with the given name can
-     * not be found on the system.
      *
      * @param packageName The full name (i.e. com.google.apps.contacts) of the
      *            desired package.
@@ -2120,6 +2246,8 @@
      *         applications (which includes installed applications as well as
      *         applications with data directory i.e. applications which had been
      *         deleted with {@code DONT_DELETE_DATA} flag set).
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      * @see #GET_ACTIVITIES
      * @see #GET_GIDS
      * @see #GET_CONFIGURATIONS
@@ -2131,16 +2259,13 @@
      * @see #GET_SIGNATURES
      * @see #GET_UNINSTALLED_PACKAGES
      */
-    public abstract PackageInfo getPackageInfo(String packageName, int flags)
+    public abstract PackageInfo getPackageInfo(String packageName, @PackageInfoFlags int flags)
             throws NameNotFoundException;
 
     /**
      * @hide
      * Retrieve overall information about an application package that is
      * installed on the system.
-     * <p>
-     * Throws {@link NameNotFoundException} if a package with the given name can
-     * not be found on the system.
      *
      * @param packageName The full name (i.e. com.google.apps.contacts) of the
      *            desired package.
@@ -2159,6 +2284,8 @@
      *         applications (which includes installed applications as well as
      *         applications with data directory i.e. applications which had been
      *         deleted with {@code DONT_DELETE_DATA} flag set).
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      * @see #GET_ACTIVITIES
      * @see #GET_GIDS
      * @see #GET_CONFIGURATIONS
@@ -2171,8 +2298,8 @@
      * @see #GET_UNINSTALLED_PACKAGES
      */
     @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS)
-    public abstract PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
-            throws NameNotFoundException;
+    public abstract PackageInfo getPackageInfoAsUser(String packageName,
+            @PackageInfoFlags int flags, @UserIdInt int userId) throws NameNotFoundException;
 
     /**
      * Map from the current package names in use on the device to whatever
@@ -2214,9 +2341,6 @@
      * through packages. The current implementation will look for a main
      * activity in the category {@link Intent#CATEGORY_LEANBACK_LAUNCHER}, or
      * return null if no main leanback activities are found.
-     * <p>
-     * Throws {@link NameNotFoundException} if a package with the given name
-     * cannot be found on the system.
      *
      * @param packageName The name of the package to inspect.
      * @return Returns either a fully-qualified Intent that can be used to launch
@@ -2228,39 +2352,73 @@
     /**
      * Return an array of all of the secondary group-ids that have been assigned
      * to a package.
-     * <p>
-     * Throws {@link NameNotFoundException} if a package with the given name
-     * cannot be found on the system.
      *
      * @param packageName The full name (i.e. com.google.apps.contacts) of the
      *            desired package.
      * @return Returns an int array of the assigned gids, or null if there are
      *         none.
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      */
     public abstract int[] getPackageGids(String packageName)
             throws NameNotFoundException;
 
     /**
-     * @hide Return the uid associated with the given package name for the
-     * given user.
-     *
-     * <p>Throws {@link NameNotFoundException} if a package with the given
-     * name can not be found on the system.
+     * Return an array of all of the secondary group-ids that have been assigned
+     * to a package.
      *
      * @param packageName The full name (i.e. com.google.apps.contacts) of the
-     *                    desired package.
-     * @param userHandle The user handle identifier to look up the package under.
-     *
-     * @return Returns an integer uid who owns the given package name.
+     *            desired package.
+     * @return Returns an int array of the assigned gids, or null if there are
+     *         none.
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      */
-    public abstract int getPackageUid(String packageName, int userHandle)
+    public abstract int[] getPackageGids(String packageName, @PackageInfoFlags int flags)
             throws NameNotFoundException;
 
     /**
-     * Retrieve all of the information we know about a particular permission.
+     * Return the UID associated with the given package name.
      *
-     * <p>Throws {@link NameNotFoundException} if a permission with the given
-     * name cannot be found on the system.
+     * @param packageName The full name (i.e. com.google.apps.contacts) of the
+     *            desired package.
+     * @return Returns an integer UID who owns the given package name.
+     * @throws NameNotFoundException if a package with the given name can not be
+     *             found on the system.
+     */
+    public abstract int getPackageUid(String packageName, @PackageInfoFlags int flags)
+            throws NameNotFoundException;
+
+    /**
+     * Return the UID associated with the given package name.
+     *
+     * @param packageName The full name (i.e. com.google.apps.contacts) of the
+     *            desired package.
+     * @param userId The user handle identifier to look up the package under.
+     * @return Returns an integer UID who owns the given package name.
+     * @throws NameNotFoundException if a package with the given name can not be
+     *             found on the system.
+     * @hide
+     */
+    public abstract int getPackageUidAsUser(String packageName, @UserIdInt int userId)
+            throws NameNotFoundException;
+
+    /**
+     * Return the UID associated with the given package name.
+     *
+     * @param packageName The full name (i.e. com.google.apps.contacts) of the
+     *            desired package.
+     * @param userId The user handle identifier to look up the package under.
+     * @return Returns an integer UID who owns the given package name.
+     * @throws NameNotFoundException if a package with the given name can not be
+     *             found on the system.
+     * @hide
+     */
+    public abstract int getPackageUidAsUser(String packageName, @PackageInfoFlags int flags,
+            @UserIdInt int userId) throws NameNotFoundException;
+
+    /**
+     * Retrieve all of the information we know about a particular permission.
      *
      * @param name The fully qualified name (i.e. com.google.permission.LOGIN)
      *             of the permission you are interested in.
@@ -2269,16 +2427,15 @@
      *
      * @return Returns a {@link PermissionInfo} containing information about the
      *         permission.
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      */
-    public abstract PermissionInfo getPermissionInfo(String name, int flags)
+    public abstract PermissionInfo getPermissionInfo(String name, @PermissionInfoFlags int flags)
             throws NameNotFoundException;
 
     /**
      * Query for all of the permissions associated with a particular group.
      *
-     * <p>Throws {@link NameNotFoundException} if the given group does not
-     * exist.
-     *
      * @param group The fully qualified name (i.e. com.google.permission.LOGIN)
      *             of the permission group you are interested in.  Use null to
      *             find all of the permissions not associated with a group.
@@ -2287,17 +2444,16 @@
      *
      * @return Returns a list of {@link PermissionInfo} containing information
      * about all of the permissions in the given group.
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      */
     public abstract List<PermissionInfo> queryPermissionsByGroup(String group,
-            int flags) throws NameNotFoundException;
+            @PermissionInfoFlags int flags) throws NameNotFoundException;
 
     /**
      * Retrieve all of the information we know about a particular group of
      * permissions.
      *
-     * <p>Throws {@link NameNotFoundException} if a permission group with the given
-     * name cannot be found on the system.
-     *
      * @param name The fully qualified name (i.e. com.google.permission_group.APPS)
      *             of the permission you are interested in.
      * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
@@ -2305,9 +2461,11 @@
      *
      * @return Returns a {@link PermissionGroupInfo} containing information
      * about the permission.
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      */
     public abstract PermissionGroupInfo getPermissionGroupInfo(String name,
-            int flags) throws NameNotFoundException;
+            @PermissionGroupInfoFlags int flags) throws NameNotFoundException;
 
     /**
      * Retrieve all of the known permission groups in the system.
@@ -2318,15 +2476,13 @@
      * @return Returns a list of {@link PermissionGroupInfo} containing
      * information about all of the known permission groups.
      */
-    public abstract List<PermissionGroupInfo> getAllPermissionGroups(int flags);
+    public abstract List<PermissionGroupInfo> getAllPermissionGroups(
+            @PermissionGroupInfoFlags int flags);
 
     /**
      * Retrieve all of the information we know about a particular
      * package/application.
      *
-     * <p>Throws {@link NameNotFoundException} if an application with the given
-     * package name cannot be found on the system.
-     *
      * @param packageName The full name (i.e. com.google.apps.contacts) of an
      *                    application.
      * @param flags Additional option flags. Use any combination of
@@ -2342,21 +2498,20 @@
      *         installed applications as well as applications
      *         with data directory ie applications which had been
      *         deleted with {@code DONT_DELETE_DATA} flag set).
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      *
      * @see #GET_META_DATA
      * @see #GET_SHARED_LIBRARY_FILES
      * @see #GET_UNINSTALLED_PACKAGES
      */
     public abstract ApplicationInfo getApplicationInfo(String packageName,
-            int flags) throws NameNotFoundException;
+            @ApplicationInfoFlags int flags) throws NameNotFoundException;
 
     /**
      * Retrieve all of the information we know about a particular activity
      * class.
      *
-     * <p>Throws {@link NameNotFoundException} if an activity with the given
-     * class name cannot be found on the system.
-     *
      * @param component The full component name (i.e.
      * com.google.apps.contacts/com.google.apps.contacts.ContactsList) of an Activity
      * class.
@@ -2365,21 +2520,20 @@
      * to modify the data (in ApplicationInfo) returned.
      *
      * @return {@link ActivityInfo} containing information about the activity.
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      *
      * @see #GET_INTENT_FILTERS
      * @see #GET_META_DATA
      * @see #GET_SHARED_LIBRARY_FILES
      */
     public abstract ActivityInfo getActivityInfo(ComponentName component,
-            int flags) throws NameNotFoundException;
+            @ComponentInfoFlags int flags) throws NameNotFoundException;
 
     /**
      * Retrieve all of the information we know about a particular receiver
      * class.
      *
-     * <p>Throws {@link NameNotFoundException} if a receiver with the given
-     * class name cannot be found on the system.
-     *
      * @param component The full component name (i.e.
      * com.google.apps.calendar/com.google.apps.calendar.CalendarAlarm) of a Receiver
      * class.
@@ -2388,21 +2542,20 @@
      * to modify the data returned.
      *
      * @return {@link ActivityInfo} containing information about the receiver.
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      *
      * @see #GET_INTENT_FILTERS
      * @see #GET_META_DATA
      * @see #GET_SHARED_LIBRARY_FILES
      */
     public abstract ActivityInfo getReceiverInfo(ComponentName component,
-            int flags) throws NameNotFoundException;
+            @ComponentInfoFlags int flags) throws NameNotFoundException;
 
     /**
      * Retrieve all of the information we know about a particular service
      * class.
      *
-     * <p>Throws {@link NameNotFoundException} if a service with the given
-     * class name cannot be found on the system.
-     *
      * @param component The full component name (i.e.
      * com.google.apps.media/com.google.apps.media.BackgroundPlayback) of a Service
      * class.
@@ -2411,20 +2564,19 @@
      * to modify the data returned.
      *
      * @return ServiceInfo containing information about the service.
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      *
      * @see #GET_META_DATA
      * @see #GET_SHARED_LIBRARY_FILES
      */
     public abstract ServiceInfo getServiceInfo(ComponentName component,
-            int flags) throws NameNotFoundException;
+            @ComponentInfoFlags int flags) throws NameNotFoundException;
 
     /**
      * Retrieve all of the information we know about a particular content
      * provider class.
      *
-     * <p>Throws {@link NameNotFoundException} if a provider with the given
-     * class name cannot be found on the system.
-     *
      * @param component The full component name (i.e.
      * com.google.providers.media/com.google.providers.media.MediaProvider) of a
      * ContentProvider class.
@@ -2433,12 +2585,14 @@
      * to modify the data returned.
      *
      * @return ProviderInfo containing information about the service.
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      *
      * @see #GET_META_DATA
      * @see #GET_SHARED_LIBRARY_FILES
      */
     public abstract ProviderInfo getProviderInfo(ComponentName component,
-            int flags) throws NameNotFoundException;
+            @ComponentInfoFlags int flags) throws NameNotFoundException;
 
     /**
      * Return a List of all packages that are installed
@@ -2474,7 +2628,7 @@
      * @see #GET_SIGNATURES
      * @see #GET_UNINSTALLED_PACKAGES
      */
-    public abstract List<PackageInfo> getInstalledPackages(int flags);
+    public abstract List<PackageInfo> getInstalledPackages(@PackageInfoFlags int flags);
 
     /**
      * Return a List of all installed packages that are currently
@@ -2507,7 +2661,7 @@
      * @see #GET_UNINSTALLED_PACKAGES
      */
     public abstract List<PackageInfo> getPackagesHoldingPermissions(
-            String[] permissions, int flags);
+            String[] permissions, @PackageInfoFlags int flags);
 
     /**
      * Return a List of all packages that are installed on the device, for a specific user.
@@ -2546,7 +2700,8 @@
      *
      * @hide
      */
-    public abstract List<PackageInfo> getInstalledPackages(int flags, int userId);
+    public abstract List<PackageInfo> getInstalledPackagesAsUser(@PackageInfoFlags int flags,
+            @UserIdInt int userId);
 
     /**
      * Check whether a particular package has been granted a particular
@@ -2858,8 +3013,9 @@
      * shared user.
      *
      * @param sharedUserName The shared user name whose uid is to be retrieved.
-     * @return Returns the uid associated with the shared user, or  NameNotFoundException
-     * if the shared user name is not being used by any installed packages
+     * @return Returns the UID associated with the shared user.
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      * @hide
      */
     public abstract int getUidForSharedUser(String sharedUserName)
@@ -2886,7 +3042,7 @@
      * @see #GET_SHARED_LIBRARY_FILES
      * @see #GET_UNINSTALLED_PACKAGES
      */
-    public abstract List<ApplicationInfo> getInstalledApplications(int flags);
+    public abstract List<ApplicationInfo> getInstalledApplications(@ApplicationInfoFlags int flags);
 
     /**
      * Gets the ephemeral applications the user recently used. Requires
@@ -3021,7 +3177,7 @@
      * @see #GET_INTENT_FILTERS
      * @see #GET_RESOLVED_FILTER
      */
-    public abstract ResolveInfo resolveActivity(Intent intent, int flags);
+    public abstract ResolveInfo resolveActivity(Intent intent, @ResolveInfoFlags int flags);
 
     /**
      * Determine the best action to perform for a given Intent for a given user. This
@@ -3054,7 +3210,8 @@
      *
      * @hide
      */
-    public abstract ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId);
+    public abstract ResolveInfo resolveActivityAsUser(Intent intent, @ResolveInfoFlags int flags,
+            @UserIdInt int userId);
 
     /**
      * Retrieve all activities that can be performed for the given intent.
@@ -3077,7 +3234,7 @@
      * @see #GET_RESOLVED_FILTER
      */
     public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
-            int flags);
+            @ResolveInfoFlags int flags);
 
     /**
      * Retrieve all activities that can be performed for the given intent, for a specific user.
@@ -3101,8 +3258,7 @@
      * @hide
      */
     public abstract List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
-            int flags, int userId);
-
+            @ResolveInfoFlags int flags, @UserIdInt int userId);
 
     /**
      * Retrieve a set of activities that should be presented to the user as
@@ -3134,7 +3290,7 @@
      * @see #GET_RESOLVED_FILTER
      */
     public abstract List<ResolveInfo> queryIntentActivityOptions(
-            ComponentName caller, Intent[] specifics, Intent intent, int flags);
+            ComponentName caller, Intent[] specifics, Intent intent, @ResolveInfoFlags int flags);
 
     /**
      * Retrieve all receivers that can handle a broadcast of the given intent.
@@ -3151,7 +3307,7 @@
      * @see #GET_RESOLVED_FILTER
      */
     public abstract List<ResolveInfo> queryBroadcastReceivers(Intent intent,
-            int flags);
+            @ResolveInfoFlags int flags);
 
     /**
      * Retrieve all receivers that can handle a broadcast of the given intent, for a specific
@@ -3170,8 +3326,8 @@
      * @see #GET_RESOLVED_FILTER
      * @hide
      */
-    public abstract List<ResolveInfo> queryBroadcastReceivers(Intent intent,
-            int flags, int userId);
+    public abstract List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent,
+            @ResolveInfoFlags int flags, @UserIdInt int userId);
 
     /**
      * Determine the best service to handle for a given Intent.
@@ -3187,7 +3343,7 @@
      * @see #GET_INTENT_FILTERS
      * @see #GET_RESOLVED_FILTER
      */
-    public abstract ResolveInfo resolveService(Intent intent, int flags);
+    public abstract ResolveInfo resolveService(Intent intent, @ResolveInfoFlags int flags);
 
     /**
      * Retrieve all services that can match the given intent.
@@ -3205,7 +3361,7 @@
      * @see #GET_RESOLVED_FILTER
      */
     public abstract List<ResolveInfo> queryIntentServices(Intent intent,
-            int flags);
+            @ResolveInfoFlags int flags);
 
     /**
      * Retrieve all services that can match the given intent for a given user.
@@ -3226,11 +3382,11 @@
      * @hide
      */
     public abstract List<ResolveInfo> queryIntentServicesAsUser(Intent intent,
-            int flags, int userId);
+            @ResolveInfoFlags int flags, @UserIdInt int userId);
 
     /** {@hide} */
     public abstract List<ResolveInfo> queryIntentContentProvidersAsUser(
-            Intent intent, int flags, int userId);
+            Intent intent, @ResolveInfoFlags int flags, @UserIdInt int userId);
 
     /**
      * Retrieve all providers that can match the given intent.
@@ -3244,7 +3400,8 @@
      * @see #GET_INTENT_FILTERS
      * @see #GET_RESOLVED_FILTER
      */
-    public abstract List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags);
+    public abstract List<ResolveInfo> queryIntentContentProviders(Intent intent,
+            @ResolveInfoFlags int flags);
 
     /**
      * Find a single content provider by its base path name.
@@ -3256,7 +3413,7 @@
      *         else null.
      */
     public abstract ProviderInfo resolveContentProvider(String name,
-            int flags);
+            @ComponentInfoFlags int flags);
 
     /**
      * Find a single content provider by its base path name.
@@ -3269,7 +3426,8 @@
      *         else null.
      * @hide
      */
-    public abstract ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId);
+    public abstract ProviderInfo resolveContentProviderAsUser(String name,
+            @ComponentInfoFlags int flags, @UserIdInt int userId);
 
     /**
      * Retrieve content provider information.
@@ -3290,15 +3448,12 @@
      *         <em>If there are no matching providers, null is returned.</em>
      */
     public abstract List<ProviderInfo> queryContentProviders(
-            String processName, int uid, int flags);
+            String processName, int uid, @ComponentInfoFlags int flags);
 
     /**
      * Retrieve all of the information we know about a particular
      * instrumentation class.
      *
-     * <p>Throws {@link NameNotFoundException} if instrumentation with the
-     * given class name cannot be found on the system.
-     *
      * @param className The full name (i.e.
      *                  com.google.apps.contacts.InstrumentList) of an
      *                  Instrumentation class.
@@ -3306,9 +3461,11 @@
      *
      * @return InstrumentationInfo containing information about the
      *         instrumentation.
+     * @throws NameNotFoundException if a package with the given name cannot be
+     *             found on the system.
      */
-    public abstract InstrumentationInfo getInstrumentationInfo(
-            ComponentName className, int flags) throws NameNotFoundException;
+    public abstract InstrumentationInfo getInstrumentationInfo(ComponentName className,
+            @InstrumentationInfoFlags int flags) throws NameNotFoundException;
 
     /**
      * Retrieve information about available instrumentation code.  May be used
@@ -3324,8 +3481,8 @@
      *         matching available Instrumentation.  Returns an empty list if
      *         there is no instrumentation available for the given package.
      */
-    public abstract List<InstrumentationInfo> queryInstrumentation(
-            String targetPackage, int flags);
+    public abstract List<InstrumentationInfo> queryInstrumentation(String targetPackage,
+            @InstrumentationInfoFlags int flags);
 
     /**
      * Retrieve an image from a package.  This is a low-level API used by
@@ -3728,8 +3885,8 @@
             throws NameNotFoundException;
 
     /** @hide */
-    public abstract Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
-            throws NameNotFoundException;
+    public abstract Resources getResourcesForApplicationAsUser(String appPackageName,
+            @UserIdInt int userId) throws NameNotFoundException;
 
     /**
      * Retrieve overall information about an application package defined
@@ -3761,14 +3918,13 @@
      * @see #GET_SIGNATURES
      *
      */
-    public PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags) {
+    public PackageInfo getPackageArchiveInfo(String archiveFilePath, @PackageInfoFlags int flags) {
         final PackageParser parser = new PackageParser();
         final File apkFile = new File(archiveFilePath);
         try {
             PackageParser.Package pkg = parser.parseMonolithicPackage(apkFile, 0);
             if ((flags & GET_SIGNATURES) != 0) {
                 parser.collectCertificates(pkg, 0);
-                parser.collectManifestDigest(pkg);
             }
             PackageUserState state = new PackageUserState();
             return PackageParser.generatePackageInfo(pkg, null, flags, 0, 0, null, state);
@@ -3828,14 +3984,12 @@
      * @param verificationURI The location of the supplementary verification
      *            file. This can be a 'file:' or a 'content:' URI. May be
      *            {@code null}.
-     * @param manifestDigest an object that holds the digest of the package
-     *            which can be used to verify ownership. May be {@code null}.
      * @param encryptionParams if the package to be installed is encrypted,
      *            these parameters describing the encryption and authentication
      *            used. May be {@code null}.
      * @hide
      * @deprecated Use {@link #installPackageWithVerification(Uri,
-     *             PackageInstallObserver, int, String, Uri, ManifestDigest,
+     *             PackageInstallObserver, int, String, Uri,
      *             ContainerEncryptionParams)} instead. This method will
      *             continue to be supported but the older observer interface
      *             will not get additional failure details.
@@ -3843,7 +3997,7 @@
     // @SystemApi
     public abstract void installPackageWithVerification(Uri packageURI,
             IPackageInstallObserver observer, int flags, String installerPackageName,
-            Uri verificationURI, ManifestDigest manifestDigest,
+            Uri verificationURI,
             ContainerEncryptionParams encryptionParams);
 
     /**
@@ -3932,7 +4086,7 @@
             Manifest.permission.INTERACT_ACROSS_USERS_FULL})
     public abstract void installPackageAsUser(
             Uri packageURI, PackageInstallObserver observer, int flags,
-            String installerPackageName, int userId);
+            String installerPackageName, @UserIdInt int userId);
 
     /**
      * Similar to
@@ -3952,8 +4106,6 @@
      * @param verificationURI The location of the supplementary verification
      *            file. This can be a 'file:' or a 'content:' URI. May be
      *            {@code null}.
-     * @param manifestDigest an object that holds the digest of the package
-     *            which can be used to verify ownership. May be {@code null}.
      * @param encryptionParams if the package to be installed is encrypted,
      *            these parameters describing the encryption and authentication
      *            used. May be {@code null}.
@@ -3961,7 +4113,7 @@
      */
     public abstract void installPackageWithVerification(Uri packageURI,
             PackageInstallObserver observer, int flags, String installerPackageName,
-            Uri verificationURI, ManifestDigest manifestDigest,
+            Uri verificationURI,
             ContainerEncryptionParams encryptionParams);
 
     /**
@@ -4007,7 +4159,7 @@
      @RequiresPermission(anyOf = {
             Manifest.permission.INSTALL_PACKAGES,
             Manifest.permission.INTERACT_ACROSS_USERS_FULL})
-    public abstract int installExistingPackageAsUser(String packageName, int userId)
+    public abstract int installExistingPackageAsUser(String packageName, @UserIdInt int userId)
             throws NameNotFoundException;
 
     /**
@@ -4105,7 +4257,7 @@
      *
      * @hide
      */
-    public abstract int getIntentVerificationStatus(String packageName, int userId);
+    public abstract int getIntentVerificationStatusAsUser(String packageName, @UserIdInt int userId);
 
     /**
      * Allow to change the status of a Intent Verification status for all IntentFilter of an App.
@@ -4127,8 +4279,8 @@
      *
      * @hide
      */
-    public abstract boolean updateIntentVerificationStatus(String packageName, int status,
-            int userId);
+    public abstract boolean updateIntentVerificationStatusAsUser(String packageName, int status,
+            @UserIdInt int userId);
 
     /**
      * Get the list of IntentFilterVerificationInfo for a specific package and User.
@@ -4168,7 +4320,8 @@
      *
      * @hide
      */
-    public abstract String getDefaultBrowserPackageName(int userId);
+    @TestApi
+    public abstract String getDefaultBrowserPackageNameAsUser(@UserIdInt int userId);
 
     /**
      * Set the default Browser package name for a specific user.
@@ -4182,7 +4335,8 @@
      *
      * @hide
      */
-    public abstract boolean setDefaultBrowserPackageName(String packageName, int userId);
+    public abstract boolean setDefaultBrowserPackageNameAsUser(String packageName,
+            @UserIdInt int userId);
 
     /**
      * Change the installer associated with a given package.  There are limitations
@@ -4241,7 +4395,7 @@
             Manifest.permission.DELETE_PACKAGES,
             Manifest.permission.INTERACT_ACROSS_USERS_FULL})
     public abstract void deletePackageAsUser(
-            String packageName, IPackageDeleteObserver observer, int flags, int userId);
+            String packageName, IPackageDeleteObserver observer, int flags, @UserIdInt int userId);
 
     /**
      * Retrieve the package name of the application that installed a package. This identifies
@@ -4354,7 +4508,7 @@
      * should have the {@link android.Manifest.permission#GET_PACKAGE_SIZE} permission.
      *
      * @param packageName The name of the package whose size information is to be retrieved
-     * @param userHandle The user whose size information should be retrieved.
+     * @param userId The user whose size information should be retrieved.
      * @param observer An observer callback to get notified when the operation
      * is complete.
      * {@link android.content.pm.IPackageStatsObserver#onGetStatsCompleted(PackageStats, boolean)}
@@ -4365,17 +4519,17 @@
      *
      * @hide
      */
-    public abstract void getPackageSizeInfo(String packageName, int userHandle,
+    public abstract void getPackageSizeInfoAsUser(String packageName, @UserIdInt int userId,
             IPackageStatsObserver observer);
 
     /**
-     * Like {@link #getPackageSizeInfo(String, int, IPackageStatsObserver)}, but
+     * Like {@link #getPackageSizeInfoAsUser(String, int, IPackageStatsObserver)}, but
      * returns the size for the calling user.
      *
      * @hide
      */
     public void getPackageSizeInfo(String packageName, IPackageStatsObserver observer) {
-        getPackageSizeInfo(packageName, UserHandle.myUserId(), observer);
+        getPackageSizeInfoAsUser(packageName, UserHandle.myUserId(), observer);
     }
 
     /**
@@ -4423,7 +4577,7 @@
      * @see #GET_SERVICES
      * @see #GET_SIGNATURES
      */
-    public abstract List<PackageInfo> getPreferredPackages(int flags);
+    public abstract List<PackageInfo> getPreferredPackages(@PackageInfoFlags int flags);
 
     /**
      * @deprecated This is a protected API that should not have been available
@@ -4454,8 +4608,8 @@
             to.
      * @hide
      */
-    public void addPreferredActivity(IntentFilter filter, int match,
-            ComponentName[] set, ComponentName activity, int userId) {
+    public void addPreferredActivityAsUser(IntentFilter filter, int match,
+            ComponentName[] set, ComponentName activity, @UserIdInt int userId) {
         throw new RuntimeException("Not implemented. Must override in a subclass.");
     }
 
@@ -4489,7 +4643,7 @@
      */
     @Deprecated
     public void replacePreferredActivityAsUser(IntentFilter filter, int match,
-           ComponentName[] set, ComponentName activity, int userId) {
+           ComponentName[] set, ComponentName activity, @UserIdInt int userId) {
         throw new RuntimeException("Not implemented. Must override in a subclass.");
     }
 
@@ -4717,7 +4871,7 @@
      * @hide
      */
     public abstract boolean setPackageSuspendedAsUser(
-            String packageName, boolean suspended, int userId);
+            String packageName, boolean suspended, @UserIdInt int userId);
 
     /** {@hide} */
     public static boolean isMoveStatusFinished(int status) {
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index f445cf8..236cf64a 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -1032,31 +1032,6 @@
     }
 
     /**
-     * Gathers the {@link ManifestDigest} for {@code pkg} if it exists in the
-     * APK. If it successfully scanned the package and found the
-     * {@code AndroidManifest.xml}, {@code true} is returned.
-     */
-    public void collectManifestDigest(Package pkg) throws PackageParserException {
-        pkg.manifestDigest = null;
-
-        // TODO: extend to gather digest for split APKs
-        try {
-            final StrictJarFile jarFile = new StrictJarFile(pkg.baseCodePath);
-            try {
-                final ZipEntry je = jarFile.findEntry(ANDROID_MANIFEST_FILENAME);
-                if (je != null) {
-                    pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
-                }
-            } finally {
-                jarFile.close();
-            }
-        } catch (IOException | RuntimeException e) {
-            throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
-                    "Failed to collect manifest digest");
-        }
-    }
-
-    /**
      * Collect certificates from all the APKs described in the given package,
      * populating {@link Package#mSignatures}. Also asserts that all APK
      * contents are signed correctly and consistently.
@@ -3223,12 +3198,19 @@
                 a.info.flags |= ActivityInfo.FLAG_RESUME_WHILE_PAUSING;
             }
 
-            a.info.resizeable = sa.getBoolean(
-                    R.styleable.AndroidManifestActivity_resizeableActivity,
-                    owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N);
+            if (sa.getBoolean(R.styleable.AndroidManifestActivity_resizeableActivity,
+                    owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N)) {
+                a.info.flags |= ActivityInfo.FLAG_RESIZEABLE;
 
-            a.info.supportsPip = a.info.resizeable ? sa.getBoolean(
-                    R.styleable.AndroidManifestActivity_supportsPictureInPicture, false) : false;
+                if (sa.getBoolean(R.styleable.AndroidManifestActivity_supportsPictureInPicture,
+                        false)) {
+                    a.info.flags |= ActivityInfo.FLAG_SUPPORTS_PICTURE_IN_PICTURE;
+                }
+            }
+
+            if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysFocusable, false)) {
+                a.info.flags |= ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
+            }
 
             a.info.screenOrientation = sa.getInt(
                     R.styleable.AndroidManifestActivity_screenOrientation,
@@ -4492,12 +4474,6 @@
         /* The required account type without which this application will not function */
         public String mRequiredAccountType;
 
-        /**
-         * Digest suitable for comparing whether this package's manifest is the
-         * same as another.
-         */
-        public ManifestDigest manifestDigest;
-
         public String mOverlayTarget;
         public int mOverlayPriority;
         public boolean mTrustedOverlay;
diff --git a/core/java/android/content/pm/ParceledListSlice.java b/core/java/android/content/pm/ParceledListSlice.java
index cfb4473..945858e6 100644
--- a/core/java/android/content/pm/ParceledListSlice.java
+++ b/core/java/android/content/pm/ParceledListSlice.java
@@ -24,6 +24,7 @@
 import android.util.Log;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -50,6 +51,10 @@
 
     private final List<T> mList;
 
+    public static <T extends Parcelable> ParceledListSlice<T> emptyList() {
+        return new ParceledListSlice<T>(Collections.<T> emptyList());
+    }
+
     public ParceledListSlice(List<T> list) {
         mList = list;
     }
diff --git a/core/java/android/content/pm/ResolveInfo.java b/core/java/android/content/pm/ResolveInfo.java
index d5d3007..c9be6ed 100644
--- a/core/java/android/content/pm/ResolveInfo.java
+++ b/core/java/android/content/pm/ResolveInfo.java
@@ -172,7 +172,8 @@
      */
     public boolean handleAllWebDataURI;
 
-    private ComponentInfo getComponentInfo() {
+    /** {@hide} */
+    public ComponentInfo getComponentInfo() {
         if (activityInfo != null) return activityInfo;
         if (serviceInfo != null) return serviceInfo;
         if (providerInfo != null) return providerInfo;
diff --git a/core/java/android/content/pm/VerificationParams.java b/core/java/android/content/pm/VerificationParams.java
index e5119b6..f90d295 100644
--- a/core/java/android/content/pm/VerificationParams.java
+++ b/core/java/android/content/pm/VerificationParams.java
@@ -16,7 +16,6 @@
 
 package android.content.pm;
 
-import android.content.pm.ManifestDigest;
 import android.net.Uri;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -51,12 +50,6 @@
     private int mInstallerUid;
 
     /**
-     * An object that holds the digest of the package which can be used to
-     * verify ownership.
-     */
-    private final ManifestDigest mManifestDigest;
-
-    /**
      * Creates verification specifications for installing with application verification.
      *
      * @param verificationURI The location of the supplementary verification
@@ -67,16 +60,13 @@
      *            May be {@code null}.
      * @param originatingUid UID of the application that the install request originated
      *            from, or NO_UID if not present
-     * @param manifestDigest an object that holds the digest of the package
-     *            which can be used to verify ownership. May be {@code null}.
      */
     public VerificationParams(Uri verificationURI, Uri originatingURI, Uri referrer,
-            int originatingUid, ManifestDigest manifestDigest) {
+            int originatingUid) {
         mVerificationURI = verificationURI;
         mOriginatingURI = originatingURI;
         mReferrer = referrer;
         mOriginatingUid = originatingUid;
-        mManifestDigest = manifestDigest;
         mInstallerUid = NO_UID;
     }
 
@@ -97,10 +87,6 @@
         return mOriginatingUid;
     }
 
-    public ManifestDigest getManifestDigest() {
-        return mManifestDigest;
-    }
-
     /** @return NO_UID when not set */
     public int getInstallerUid() {
         return mInstallerUid;
@@ -155,14 +141,6 @@
             return false;
         }
 
-        if (mManifestDigest == null) {
-            if (other.mManifestDigest != null) {
-                return false;
-            }
-        } else if (!mManifestDigest.equals(other.mManifestDigest)) {
-            return false;
-        }
-
         if (mInstallerUid != other.mInstallerUid) {
             return false;
         }
@@ -178,8 +156,7 @@
         hash += 7 * (mOriginatingURI == null ? 1 : mOriginatingURI.hashCode());
         hash += 11 * (mReferrer == null ? 1 : mReferrer.hashCode());
         hash += 13 * mOriginatingUid;
-        hash += 17 * (mManifestDigest == null ? 1 : mManifestDigest.hashCode());
-        hash += 19 * mInstallerUid;
+        hash += 17 * mInstallerUid;
 
         return hash;
     }
@@ -196,8 +173,6 @@
         sb.append(mReferrer.toString());
         sb.append(",mOriginatingUid=");
         sb.append(mOriginatingUid);
-        sb.append(",mManifestDigest=");
-        sb.append(mManifestDigest.toString());
         sb.append(",mInstallerUid=");
         sb.append(mInstallerUid);
         sb.append('}');
@@ -211,7 +186,6 @@
         dest.writeParcelable(mOriginatingURI, 0);
         dest.writeParcelable(mReferrer, 0);
         dest.writeInt(mOriginatingUid);
-        dest.writeParcelable(mManifestDigest, 0);
         dest.writeInt(mInstallerUid);
     }
 
@@ -221,7 +195,6 @@
         mOriginatingURI = source.readParcelable(Uri.class.getClassLoader());
         mReferrer = source.readParcelable(Uri.class.getClassLoader());
         mOriginatingUid = source.readInt();
-        mManifestDigest = source.readParcelable(ManifestDigest.class.getClassLoader());
         mInstallerUid = source.readInt();
     }
 
diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java
index 7669053..7b0b98d 100644
--- a/core/java/android/content/res/AssetManager.java
+++ b/core/java/android/content/res/AssetManager.java
@@ -16,6 +16,11 @@
 
 package android.content.res;
 
+import android.annotation.AnyRes;
+import android.annotation.ArrayRes;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.StringRes;
 import android.os.ParcelFileDescriptor;
 import android.util.Log;
 import android.util.SparseArray;
@@ -142,80 +147,95 @@
     }
 
     /**
-     * Retrieve the string value associated with a particular resource
-     * identifier for the current configuration / skin.
+     * Retrieves the string value associated with a particular resource
+     * identifier for the current configuration.
+     *
+     * @param resId the resource identifier to load
+     * @return the string value, or {@code null}
      */
-    /*package*/ final CharSequence getResourceText(int ident) {
+    @Nullable
+    final CharSequence getResourceText(@StringRes int resId) {
         synchronized (this) {
-            TypedValue tmpValue = mValue;
-            int block = loadResourceValue(ident, (short) 0, tmpValue, true);
-            if (block >= 0) {
-                if (tmpValue.type == TypedValue.TYPE_STRING) {
-                    return mStringBlocks[block].get(tmpValue.data);
-                }
-                return tmpValue.coerceToString();
+            final TypedValue outValue = mValue;
+            if (getResourceValue(resId, 0, outValue, true)) {
+                return outValue.coerceToString();
             }
+            return null;
         }
-        return null;
     }
 
     /**
-     * Retrieve the string value associated with a particular resource
-     * identifier for the current configuration / skin.
+     * Retrieves the string value associated with a particular resource
+     * identifier for the current configuration.
+     *
+     * @param resId the resource identifier to load
+     * @param bagEntryId
+     * @return the string value, or {@code null}
      */
-    /*package*/ final CharSequence getResourceBagText(int ident, int bagEntryId) {
+    @Nullable
+    final CharSequence getResourceBagText(@StringRes int resId, int bagEntryId) {
         synchronized (this) {
-            TypedValue tmpValue = mValue;
-            int block = loadResourceBagValue(ident, bagEntryId, tmpValue, true);
-            if (block >= 0) {
-                if (tmpValue.type == TypedValue.TYPE_STRING) {
-                    return mStringBlocks[block].get(tmpValue.data);
-                }
-                return tmpValue.coerceToString();
+            final TypedValue outValue = mValue;
+            final int block = loadResourceBagValue(resId, bagEntryId, outValue, true);
+            if (block < 0) {
+                return null;
             }
+            if (outValue.type == TypedValue.TYPE_STRING) {
+                return mStringBlocks[block].get(outValue.data);
+            }
+            return outValue.coerceToString();
         }
-        return null;
     }
 
     /**
-     * Retrieve the string array associated with a particular resource
-     * identifier.
-     * @param id Resource id of the string array
+     * Retrieves the string array associated with a particular resource
+     * identifier for the current configuration.
+     *
+     * @param resId the resource identifier of the string array
+     * @return the string array, or {@code null}
      */
-    /*package*/ final String[] getResourceStringArray(final int id) {
-        String[] retArray = getArrayStringResource(id);
-        return retArray;
+    @Nullable
+    final String[] getResourceStringArray(@ArrayRes int resId) {
+        return getArrayStringResource(resId);
     }
 
-
-    /*package*/ final boolean getResourceValue(int ident,
-                                               int density,
-                                               TypedValue outValue,
-                                               boolean resolveRefs)
-    {
-        int block = loadResourceValue(ident, (short) density, outValue, resolveRefs);
-        if (block >= 0) {
-            if (outValue.type != TypedValue.TYPE_STRING) {
-                return true;
-            }
+    /**
+     * Populates {@code outValue} with the data associated a particular
+     * resource identifier for the current configuration.
+     *
+     * @param resId the resource identifier to load
+     * @param densityDpi the density bucket for which to load the resource
+     * @param outValue the typed value in which to put the data
+     * @param resolveRefs {@code true} to resolve references, {@code false}
+     *                    to leave them unresolved
+     * @return {@code true} if the data was loaded into {@code outValue},
+     *         {@code false} otherwise
+     */
+    final boolean getResourceValue(@AnyRes int resId, int densityDpi, @NonNull TypedValue outValue,
+            boolean resolveRefs) {
+        final int block = loadResourceValue(resId, (short) densityDpi, outValue, resolveRefs);
+        if (block < 0) {
+            return false;
+        }
+        if (outValue.type == TypedValue.TYPE_STRING) {
             outValue.string = mStringBlocks[block].get(outValue.data);
-            return true;
         }
-        return false;
+        return true;
     }
 
     /**
      * Retrieve the text array associated with a particular resource
      * identifier.
-     * @param id Resource id of the string array
+     *
+     * @param resId the resource id of the string array
      */
-    /*package*/ final CharSequence[] getResourceTextArray(final int id) {
-        int[] rawInfoArray = getArrayStringInfo(id);
-        int rawInfoArrayLen = rawInfoArray.length;
+    final CharSequence[] getResourceTextArray(@ArrayRes int resId) {
+        final int[] rawInfoArray = getArrayStringInfo(resId);
+        final int rawInfoArrayLen = rawInfoArray.length;
         final int infoArrayLen = rawInfoArrayLen / 2;
         int block;
         int index;
-        CharSequence[] retArray = new CharSequence[infoArrayLen];
+        final CharSequence[] retArray = new CharSequence[infoArrayLen];
         for (int i = 0, j = 0; i < rawInfoArrayLen; i = i + 2, j++) {
             block = rawInfoArray[i];
             index = rawInfoArray[i + 1];
@@ -223,32 +243,45 @@
         }
         return retArray;
     }
-    
-    /*package*/ final boolean getThemeValue(long theme, int ident,
-            TypedValue outValue, boolean resolveRefs) {
-        int block = loadThemeAttributeValue(theme, ident, outValue, resolveRefs);
-        if (block >= 0) {
-            if (outValue.type != TypedValue.TYPE_STRING) {
-                return true;
-            }
-            StringBlock[] blocks = mStringBlocks;
-            if (blocks == null) {
-                ensureStringBlocks();
-                blocks = mStringBlocks;
-            }
-            outValue.string = blocks[block].get(outValue.data);
-            return true;
+
+    /**
+     * Populates {@code outValue} with the data associated with a particular
+     * resource identifier for the current configuration. Resolves theme
+     * attributes against the specified theme.
+     *
+     * @param theme the native pointer of the theme
+     * @param resId the resource identifier to load
+     * @param outValue the typed value in which to put the data
+     * @param resolveRefs {@code true} to resolve references, {@code false}
+     *                    to leave them unresolved
+     * @return {@code true} if the data was loaded into {@code outValue},
+     *         {@code false} otherwise
+     */
+    final boolean getThemeValue(long theme, @AnyRes int resId, @NonNull TypedValue outValue,
+            boolean resolveRefs) {
+        final int block = loadThemeAttributeValue(theme, resId, outValue, resolveRefs);
+        if (block < 0) {
+            return false;
         }
-        return false;
+        if (outValue.type == TypedValue.TYPE_STRING) {
+            final StringBlock[] blocks = ensureStringBlocks();
+            outValue.string = blocks[block].get(outValue.data);
+        }
+        return true;
     }
 
-    /*package*/ final void ensureStringBlocks() {
-        if (mStringBlocks == null) {
-            synchronized (this) {
-                if (mStringBlocks == null) {
-                    makeStringBlocks(sSystem.mStringBlocks);
-                }
+    /**
+     * Ensures the string blocks are loaded.
+     *
+     * @return the string blocks
+     */
+    @NonNull
+    final StringBlock[] ensureStringBlocks() {
+        synchronized (this) {
+            if (mStringBlocks == null) {
+                makeStringBlocks(sSystem.mStringBlocks);
             }
+            return mStringBlocks;
         }
     }
 
@@ -698,6 +731,18 @@
      */
     public native final String[] getLocales();
 
+    /**
+     * Same as getLocales(), except that locales that are only provided by the system (i.e. those
+     * present in framework-res.apk or its overlays) will not be listed.
+     *
+     * For example, if the "system" assets support English, French, and German, and the additional
+     * assets support Cherokee and French, getLocales() would return
+     * [Cherokee, English, French, German], while getNonSystemLocales() would return
+     * [Cherokee, French].
+     * {@hide}
+     */
+    public native final String[] getNonSystemLocales();
+
     /** {@hide} */
     public native final Configuration[] getSizeConfigurations();
 
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index 60c6e82..7b56eeb 100644
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -151,8 +151,9 @@
 
     private boolean mPreloading;
 
+    // Cyclical cache used for recently-accessed XML files.
     private int mLastCachedXmlBlockIndex = -1;
-    private final int[] mCachedXmlBlockIds = { 0, 0, 0, 0 };
+    private final String[] mCachedXmlBlockFiles = new String[4];
     private final XmlBlock[] mCachedXmlBlocks = new XmlBlock[4];
 
     final AssetManager mAssets;
@@ -866,6 +867,11 @@
         try {
             getValueForDensity(id, density, value, true);
 
+            // If the drawable's XML lives in our current density qualifier,
+            // it's okay to use a scaled version from the cache. Otherwise, we
+            // need to actually load the drawable from XML.
+            final boolean useCache = value.density == mMetrics.densityDpi;
+
             /*
              * Pretend the requested density is actually the display density. If
              * the drawable returned is not the requested density, then force it
@@ -881,7 +887,7 @@
                 }
             }
 
-            return loadDrawable(value, id, theme);
+            return loadDrawable(value, id, theme, useCache);
         } finally {
             releaseTempTypedValue(value);
         }
@@ -1976,7 +1982,21 @@
 
             if (setLocalesToDefault || mResolvedLocale == null
                     || (configChanges & Configuration.NATIVE_CONFIG_LOCALE) != 0) {
-                mResolvedLocale = locales.getFirstMatch(mAssets.getLocales());
+                if (locales.size() == 1) {
+                    // This is an optimization to avoid the JNI call(s) when the result of
+                    // getFirstMatchWithEnglishSupported() does not depend on the supported locales.
+                    mResolvedLocale = locales.getPrimary();
+                } else {
+                    String[] supportedLocales = mAssets.getNonSystemLocales();
+                    if (LocaleList.isPseudoLocalesOnly(supportedLocales)) {
+                        // We fallback to all locales (including system locales) if there was no
+                        // locale specifically supported by the assets. This is to properly support
+                        // apps that only rely on the shared system assets and don't need assets of
+                        // their own.
+                        supportedLocales = mAssets.getLocales();
+                    }
+                    mResolvedLocale = locales.getFirstMatchWithEnglishSupported(supportedLocales);
+                }
             }
             mAssets.setConfiguration(mConfiguration.mcc, mConfiguration.mnc,
                     adjustLanguageTag(mResolvedLocale.toLanguageTag()),
@@ -2351,16 +2371,17 @@
      * tools.
      */
     public final void flushLayoutCache() {
-        synchronized (mCachedXmlBlockIds) {
-            // First see if this block is in our cache.
-            final int num = mCachedXmlBlockIds.length;
-            for (int i=0; i<num; i++) {
-                mCachedXmlBlockIds[i] = -0;
-                XmlBlock oldBlock = mCachedXmlBlocks[i];
+        final String[] cachedXmlBlockFiles = mCachedXmlBlockFiles;
+        final XmlBlock[] cachedXmlBlocks = mCachedXmlBlocks;
+        synchronized (cachedXmlBlockFiles) {
+            final int num = cachedXmlBlockFiles.length;
+            for (int i = 0; i < num; i++) {
+                final XmlBlock oldBlock = cachedXmlBlocks[i];
                 if (oldBlock != null) {
                     oldBlock.close();
                 }
-                mCachedXmlBlocks[i] = null;
+                cachedXmlBlockFiles[i] = null;
+                cachedXmlBlocks[i] = null;
             }
         }
     }
@@ -2437,6 +2458,12 @@
 
     @Nullable
     Drawable loadDrawable(TypedValue value, int id, Theme theme) throws NotFoundException {
+        return loadDrawable(value, id, theme, true);
+    }
+
+    @Nullable
+    Drawable loadDrawable(TypedValue value, int id, Theme theme, boolean useCache)
+            throws NotFoundException {
         try {
             if (TRACE_FOR_PRELOAD) {
                 // Log only framework resources
@@ -2463,16 +2490,17 @@
             }
 
             // First, check whether we have a cached version of this drawable
-            // that was inflated against the specified theme.
-            if (!mPreloading) {
+            // that was inflated against the specified theme. Skip the cache if
+            // we're currently preloading or we're not using the cache.
+            if (!mPreloading && useCache) {
                 final Drawable cachedDrawable = caches.getInstance(key, theme);
                 if (cachedDrawable != null) {
                     return cachedDrawable;
                 }
             }
 
-            // Next, check preloaded drawables. These may contain unresolved theme
-            // attributes.
+            // Next, check preloaded drawables. Preloaded drawables may contain
+            // unresolved theme attributes.
             final ConstantState cs;
             if (isColorDrawable) {
                 cs = sPreloadedColorDrawables.get(key);
@@ -2500,8 +2528,9 @@
             }
 
             // If we were able to obtain a drawable, store it in the appropriate
-            // cache: preload, not themed, null theme, or theme-specific.
-            if (dr != null) {
+            // cache: preload, not themed, null theme, or theme-specific. Don't
+            // pollute the cache with drawables loaded from a foreign density.
+            if (dr != null && useCache) {
                 dr.setChangingConfigurations(value.changingConfigurations);
                 cacheDrawable(value, isColorDrawable, caches, theme, canApplyTheme, key, dr);
             }
@@ -2730,7 +2759,16 @@
         return csl;
     }
 
-    /*package*/ XmlResourceParser loadXmlResourceParser(int id, String type)
+    /**
+     * Loads an XML parser for the specified file.
+     *
+     * @param id the resource identifier for the file
+     * @param type the type of resource (used for logging)
+     * @return a parser for the specified XML file
+     * @throws NotFoundException if the file could not be loaded
+     */
+    @NonNull
+    XmlResourceParser loadXmlResourceParser(@AnyRes int id, @NonNull String type)
             throws NotFoundException {
         final TypedValue value = obtainTempTypedValue(id);
         try {
@@ -2744,53 +2782,58 @@
             releaseTempTypedValue(value);
         }
     }
-    
-    /*package*/ XmlResourceParser loadXmlResourceParser(String file, int id,
-            int assetCookie, String type) throws NotFoundException {
+
+    /**
+     * Loads an XML parser for the specified file.
+     *
+     * @param file the path for the XML file to parse
+     * @param id the resource identifier for the file
+     * @param assetCookie the asset cookie for the file
+     * @param type the type of resource (used for logging)
+     * @return a parser for the specified XML file
+     * @throws NotFoundException if the file could not be loaded
+     */
+    @NonNull
+    XmlResourceParser loadXmlResourceParser(@NonNull String file, @AnyRes int id,
+            int assetCookie, @NonNull String type) throws NotFoundException {
         if (id != 0) {
             try {
-                // These may be compiled...
-                synchronized (mCachedXmlBlockIds) {
+                final String[] cachedXmlBlockFiles = mCachedXmlBlockFiles;
+                final XmlBlock[] cachedXmlBlocks = mCachedXmlBlocks;
+                synchronized (cachedXmlBlockFiles) {
                     // First see if this block is in our cache.
-                    final int num = mCachedXmlBlockIds.length;
-                    for (int i=0; i<num; i++) {
-                        if (mCachedXmlBlockIds[i] == id) {
-                            //System.out.println("**** REUSING XML BLOCK!  id="
-                            //                   + id + ", index=" + i);
-                            return mCachedXmlBlocks[i].newParser();
+                    final int num = cachedXmlBlockFiles.length;
+                    for (int i = 0; i < num; i++) {
+                        if (cachedXmlBlockFiles[i] != null
+                                && cachedXmlBlockFiles[i].equals(file)) {
+                            return cachedXmlBlocks[i].newParser();
                         }
                     }
 
                     // Not in the cache, create a new block and put it at
                     // the next slot in the cache.
-                    XmlBlock block = mAssets.openXmlBlockAsset(
-                            assetCookie, file);
+                    final XmlBlock block = mAssets.openXmlBlockAsset(assetCookie, file);
                     if (block != null) {
-                        int pos = mLastCachedXmlBlockIndex+1;
-                        if (pos >= num) pos = 0;
+                        final int pos = (mLastCachedXmlBlockIndex + 1) % num;
                         mLastCachedXmlBlockIndex = pos;
-                        XmlBlock oldBlock = mCachedXmlBlocks[pos];
+                        final XmlBlock oldBlock = cachedXmlBlocks[pos];
                         if (oldBlock != null) {
                             oldBlock.close();
                         }
-                        mCachedXmlBlockIds[pos] = id;
-                        mCachedXmlBlocks[pos] = block;
-                        //System.out.println("**** CACHING NEW XML BLOCK!  id="
-                        //                   + id + ", index=" + pos);
+                        cachedXmlBlockFiles[pos] = file;
+                        cachedXmlBlocks[pos] = block;
                         return block.newParser();
                     }
                 }
             } catch (Exception e) {
-                NotFoundException rnf = new NotFoundException(
-                        "File " + file + " from xml type " + type + " resource ID #0x"
-                        + Integer.toHexString(id));
+                final NotFoundException rnf = new NotFoundException("File " + file
+                        + " from xml type " + type + " resource ID #0x" + Integer.toHexString(id));
                 rnf.initCause(e);
                 throw rnf;
             }
         }
 
-        throw new NotFoundException(
-                "File " + file + " from xml type " + type + " resource ID #0x"
+        throw new NotFoundException("File " + file + " from xml type " + type + " resource ID #0x"
                 + Integer.toHexString(id));
     }
 
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index 8ab8991..f642f08 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -19,16 +19,22 @@
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
 
+import android.annotation.CallSuper;
 import android.annotation.DrawableRes;
+import android.annotation.IntDef;
+import android.annotation.MainThread;
 import android.app.ActivityManager;
 import android.app.Dialog;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
+import android.database.ContentObserver;
 import android.graphics.Rect;
 import android.graphics.Region;
+import android.net.Uri;
 import android.os.Bundle;
+import android.os.Handler;
 import android.os.IBinder;
 import android.os.ResultReceiver;
 import android.os.SystemClock;
@@ -68,6 +74,8 @@
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 
 /**
  * InputMethodService provides a standard implementation of an InputMethod,
@@ -634,6 +642,97 @@
     }
 
     /**
+     * A {@link ContentObserver} to monitor {@link Settings.Secure#SHOW_IME_WITH_HARD_KEYBOARD}.
+     *
+     * <p>Note that {@link Settings.Secure#SHOW_IME_WITH_HARD_KEYBOARD} is not a public API.
+     * Basically this functionality still needs to be considered as implementation details.</p>
+     */
+    @MainThread
+    private static final class SettingsObserver extends ContentObserver {
+        @Retention(RetentionPolicy.SOURCE)
+        @IntDef({
+                ShowImeWithHardKeyboardType.UNKNOWN,
+                ShowImeWithHardKeyboardType.FALSE,
+                ShowImeWithHardKeyboardType.TRUE,
+        })
+        private @interface ShowImeWithHardKeyboardType {
+            int UNKNOWN = 0;
+            int FALSE = 1;
+            int TRUE = 2;
+        }
+        @ShowImeWithHardKeyboardType
+        private int mShowImeWithHardKeyboard = ShowImeWithHardKeyboardType.UNKNOWN;
+
+        private final InputMethodService mService;
+
+        private SettingsObserver(InputMethodService service) {
+            super(new Handler(service.getMainLooper()));
+            mService = service;
+        }
+
+        /**
+         * A factory method that internally enforces two-phase initialization to make sure that the
+         * object reference will not be escaped until the object is properly constructed.
+         *
+         * <p>NOTE: Currently {@link SettingsObserver} is accessed only from main thread.  Hence
+         * this enforcement of two-phase initialization may be unnecessary at the moment.</p>
+         *
+         * @param service {@link InputMethodService} that needs to receive the callback.
+         * @return {@link SettingsObserver} that is already registered to
+         * {@link android.content.ContentResolver}. The caller must call
+         * {@link SettingsObserver#unregister()}.
+         */
+        public static SettingsObserver createAndRegister(InputMethodService service) {
+            final SettingsObserver observer = new SettingsObserver(service);
+            // The observer is properly constructed. Let's start accepting the event.
+            service.getContentResolver().registerContentObserver(
+                    Settings.Secure.getUriFor(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD),
+                    false, observer);
+            return observer;
+        }
+
+        void unregister() {
+            mService.getContentResolver().unregisterContentObserver(this);
+        }
+
+        private boolean shouldShowImeWithHardKeyboard() {
+            // Lazily initialize as needed.
+            if (mShowImeWithHardKeyboard == ShowImeWithHardKeyboardType.UNKNOWN) {
+                mShowImeWithHardKeyboard = Settings.Secure.getInt(mService.getContentResolver(),
+                        Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0) != 0 ?
+                        ShowImeWithHardKeyboardType.TRUE : ShowImeWithHardKeyboardType.FALSE;
+            }
+            switch (mShowImeWithHardKeyboard) {
+                case ShowImeWithHardKeyboardType.TRUE:
+                    return true;
+                case ShowImeWithHardKeyboardType.FALSE:
+                    return false;
+                default:
+                    Log.e(TAG, "Unexpected mShowImeWithHardKeyboard=" + mShowImeWithHardKeyboard);
+                    return false;
+            }
+        }
+
+        @Override
+        public void onChange(boolean selfChange, Uri uri) {
+            final Uri showImeWithHardKeyboardUri =
+                    Settings.Secure.getUriFor(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD);
+            if (showImeWithHardKeyboardUri.equals(uri)) {
+                mShowImeWithHardKeyboard = Settings.Secure.getInt(mService.getContentResolver(),
+                        Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0) != 0 ?
+                        ShowImeWithHardKeyboardType.TRUE : ShowImeWithHardKeyboardType.FALSE;
+                mService.updateInputViewShown();
+            }
+        }
+
+        @Override
+        public String toString() {
+            return "SettingsObserver{mShowImeWithHardKeyboard=" + mShowImeWithHardKeyboard  + "}";
+        }
+    }
+    private SettingsObserver mSettingsObserver;
+
+    /**
      * You can call this to customize the theme used by your IME's window.
      * This theme should typically be one that derives from
      * {@link android.R.style#Theme_InputMethod}, which is the default theme
@@ -682,6 +781,7 @@
         super.setTheme(mTheme);
         super.onCreate();
         mImm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
+        mSettingsObserver = SettingsObserver.createAndRegister(this);
         // If the previous IME has occupied non-empty inset in the screen, we need to decide whether
         // we continue to use the same size of the inset or update it
         mShouldClearInsetOfPreviousIme = (mImm.getInputMethodWindowVisibleHeight() > 0);
@@ -764,6 +864,10 @@
             mWindow.getWindow().setWindowAnimations(0);
             mWindow.dismiss();
         }
+        if (mSettingsObserver != null) {
+            mSettingsObserver.unregister();
+            mSettingsObserver = null;
+        }
     }
 
     /**
@@ -1140,21 +1244,28 @@
     public boolean isInputViewShown() {
         return mIsInputViewShown && mWindowVisible;
     }
-    
+
     /**
-     * Override this to control when the soft input area should be shown to
-     * the user.  The default implementation only shows the input view when
-     * there is no hard keyboard or the keyboard is hidden.  If you change what
-     * this returns, you will need to call {@link #updateInputViewShown()}
-     * yourself whenever the returned value may have changed to have it
-     * re-evaluated and applied.
+     * Override this to control when the soft input area should be shown to the user.  The default
+     * implementation returns {@code false} when there is no hard keyboard or the keyboard is hidden
+     * unless the user shows an intention to use software keyboard.  If you change what this
+     * returns, you will need to call {@link #updateInputViewShown()} yourself whenever the returned
+     * value may have changed to have it re-evaluated and applied.
+     *
+     * <p>When you override this method, it is recommended to call
+     * {@code super.onEvaluateInputViewShown()} and return {@code true} when {@code true} is
+     * returned.</p>
      */
+    @CallSuper
     public boolean onEvaluateInputViewShown() {
+        if (mSettingsObserver.shouldShowImeWithHardKeyboard()) {
+            return true;
+        }
         Configuration config = getResources().getConfiguration();
         return config.keyboard == Configuration.KEYBOARD_NOKEYS
                 || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES;
     }
-    
+
     /**
      * Controls the visibility of the candidates display area.  By default
      * it is hidden.
@@ -2483,5 +2594,6 @@
                 + " touchableInsets=" + mTmpInsets.touchableInsets
                 + " touchableRegion=" + mTmpInsets.touchableRegion);
         p.println(" mShouldClearInsetOfPreviousIme=" + mShouldClearInsetOfPreviousIme);
+        p.println(" mSettingsObserver=" + mSettingsObserver);
     }
 }
diff --git a/core/java/android/net/NetworkScorerAppManager.java b/core/java/android/net/NetworkScorerAppManager.java
index ec76b8a..a66ea49 100644
--- a/core/java/android/net/NetworkScorerAppManager.java
+++ b/core/java/android/net/NetworkScorerAppManager.java
@@ -33,6 +33,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -90,13 +91,18 @@
      * @return the list of scorers, or the empty list if there are no valid scorers.
      */
     public static Collection<NetworkScorerAppData> getAllValidScorers(Context context) {
-        List<NetworkScorerAppData> scorers = new ArrayList<>();
+        // Network scorer apps can only run as the primary user so exit early if we're not the
+        // primary user.
+        if (UserHandle.getCallingUserId() != 0 /*USER_SYSTEM*/) {
+            return Collections.emptyList();
+        }
 
+        List<NetworkScorerAppData> scorers = new ArrayList<>();
         PackageManager pm = context.getPackageManager();
         // Only apps installed under the primary user of the device can be scorers.
         // TODO: http://b/23422763
         List<ResolveInfo> receivers =
-                pm.queryBroadcastReceivers(SCORE_INTENT, 0 /* flags */, UserHandle.USER_SYSTEM);
+                pm.queryBroadcastReceiversAsUser(SCORE_INTENT, 0 /* flags */, UserHandle.USER_SYSTEM);
         for (ResolveInfo receiver : receivers) {
             // This field is a misnomer, see android.content.pm.ResolveInfo#activityInfo
             final ActivityInfo receiverInfo = receiver.activityInfo;
@@ -105,8 +111,9 @@
                 continue;
             }
             if (!permission.BROADCAST_NETWORK_PRIVILEGED.equals(receiverInfo.permission)) {
-                // Receiver doesn't require the BROADCAST_NETWORK_PRIVILEGED permission, which means
-                // anyone could trigger network scoring and flood the framework with score requests.
+                // Receiver doesn't require the BROADCAST_NETWORK_PRIVILEGED permission, which
+                // means anyone could trigger network scoring and flood the framework with score
+                // requests.
                 continue;
             }
             if (pm.checkPermission(permission.SCORE_NETWORKS, receiverInfo.packageName) !=
@@ -128,8 +135,8 @@
                 }
             }
 
-            // NOTE: loadLabel will attempt to load the receiver's label and fall back to the app
-            // label if none is present.
+            // NOTE: loadLabel will attempt to load the receiver's label and fall back to the
+            // app label if none is present.
             scorers.add(new NetworkScorerAppData(receiverInfo.packageName,
                     receiverInfo.applicationInfo.uid, receiverInfo.loadLabel(pm),
                     configurationActivityClassName));
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
index 126824f..4159d89 100644
--- a/core/java/android/os/PowerManager.java
+++ b/core/java/android/os/PowerManager.java
@@ -980,6 +980,14 @@
             = "android.os.action.POWER_SAVE_MODE_CHANGED";
 
     /**
+     * Intent that is broadcast when the state of {@link #isPowerSaveMode()} changes.
+     * @hide
+     */
+    @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION)
+    public static final String ACTION_POWER_SAVE_MODE_CHANGED_INTERNAL
+            = "android.os.action.POWER_SAVE_MODE_CHANGED_INTERNAL";
+
+    /**
      * Intent that is broadcast when the state of {@link #isDeviceIdleMode()} changes.
      * This broadcast is only sent to registered receivers.
      */
diff --git a/core/java/android/os/ServiceManager.java b/core/java/android/os/ServiceManager.java
index 13b8b66..2ba4aa4 100644
--- a/core/java/android/os/ServiceManager.java
+++ b/core/java/android/os/ServiceManager.java
@@ -112,8 +112,10 @@
 
     /**
      * Return a list of all currently running services.
+     * @return an array of all currently running services, or <code>null</code> in
+     * case of an exception
      */
-    public static String[] listServices() throws RemoteException {
+    public static String[] listServices() {
         try {
             return getIServiceManager().listServices();
         } catch (RemoteException e) {
diff --git a/core/java/android/os/UserHandle.java b/core/java/android/os/UserHandle.java
index f946ca7..867d0b9 100644
--- a/core/java/android/os/UserHandle.java
+++ b/core/java/android/os/UserHandle.java
@@ -16,7 +16,10 @@
 
 package android.os;
 
+import android.annotation.AppIdInt;
 import android.annotation.SystemApi;
+import android.annotation.TestApi;
+import android.annotation.UserIdInt;
 
 import java.io.PrintWriter;
 
@@ -127,7 +130,7 @@
      * Returns the user id for a given uid.
      * @hide
      */
-    public static int getUserId(int uid) {
+    public static @UserIdInt int getUserId(int uid) {
         if (MU_ENABLED) {
             return uid / PER_USER_RANGE;
         } else {
@@ -136,12 +139,12 @@
     }
 
     /** @hide */
-    public static int getCallingUserId() {
+    public static @UserIdInt int getCallingUserId() {
         return getUserId(Binder.getCallingUid());
     }
 
     /** @hide */
-    public static UserHandle of(int userId) {
+    public static UserHandle of(@UserIdInt int userId) {
         return userId == USER_SYSTEM ? SYSTEM : new UserHandle(userId);
     }
 
@@ -149,7 +152,7 @@
      * Returns the uid that is composed from the userId and the appId.
      * @hide
      */
-    public static int getUid(int userId, int appId) {
+    public static int getUid(@UserIdInt int userId, @AppIdInt int appId) {
         if (MU_ENABLED) {
             return userId * PER_USER_RANGE + (appId % PER_USER_RANGE);
         } else {
@@ -161,7 +164,8 @@
      * Returns the app id (or base uid) for a given uid, stripping out the user id from it.
      * @hide
      */
-    public static int getAppId(int uid) {
+    @TestApi
+    public static @AppIdInt int getAppId(int uid) {
         return uid % PER_USER_RANGE;
     }
 
@@ -169,7 +173,7 @@
      * Returns the gid shared between all apps with this userId.
      * @hide
      */
-    public static int getUserGid(int userId) {
+    public static int getUserGid(@UserIdInt int userId) {
         return getUid(userId, Process.SHARED_USER_GID);
     }
 
@@ -186,7 +190,7 @@
      * Returns the app id for a given shared app gid. Returns -1 if the ID is invalid.
      * @hide
      */
-    public static int getAppIdFromSharedAppGid(int gid) {
+    public static @AppIdInt int getAppIdFromSharedAppGid(int gid) {
         final int appId = getAppId(gid) + Process.FIRST_APPLICATION_UID
                 - Process.FIRST_SHARED_APPLICATION_GID;
         if (appId < 0 || appId >= Process.FIRST_SHARED_APPLICATION_GID) {
@@ -257,7 +261,7 @@
     }
 
     /** @hide */
-    public static int parseUserArg(String arg) {
+    public static @UserIdInt int parseUserArg(String arg) {
         int userId;
         if ("all".equals(arg)) {
             userId = UserHandle.USER_ALL;
@@ -279,7 +283,7 @@
      * @hide
      */
     @SystemApi
-    public static int myUserId() {
+    public static @UserIdInt int myUserId() {
         return getUserId(Process.myUid());
     }
 
@@ -315,7 +319,7 @@
      * @hide
      */
     @SystemApi
-    public int getIdentifier() {
+    public @UserIdInt int getIdentifier() {
         return mHandle;
     }
 
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index 037916a..887dd17 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -20,6 +20,7 @@
 import android.annotation.Nullable;
 import android.annotation.RequiresPermission;
 import android.annotation.SystemApi;
+import android.annotation.UserIdInt;
 import android.app.ActivityManager;
 import android.app.ActivityManagerNative;
 import android.app.admin.DevicePolicyManager;
@@ -601,7 +602,7 @@
      * @return the user handle of this process.
      * @hide
      */
-    public int getUserHandle() {
+    public @UserIdInt int getUserHandle() {
         return UserHandle.myUserId();
     }
 
@@ -671,7 +672,7 @@
      * Returns whether the provided user is an admin user. There can be more than one admin
      * user.
      */
-    public boolean isUserAdmin(int userId) {
+    public boolean isUserAdmin(@UserIdInt int userId) {
         UserInfo user = getUserInfo(userId);
         return user != null && user.isAdmin();
     }
@@ -695,7 +696,7 @@
      * Checks if specified user can have restricted profile.
      * @hide
      */
-    public boolean canHaveRestrictedProfile(int userId) {
+    public boolean canHaveRestrictedProfile(@UserIdInt int userId) {
         try {
             return mService.canHaveRestrictedProfile(userId);
         } catch (RemoteException re) {
@@ -741,7 +742,7 @@
      * Returns whether the specified user is ephemeral.
      * @hide
      */
-    public boolean isUserEphemeral(int userId) {
+    public boolean isUserEphemeral(@UserIdInt int userId) {
         final UserInfo user = getUserInfo(userId);
         return user != null && user.isEphemeral();
     }
@@ -861,7 +862,7 @@
     }
 
     /** {@hide} */
-    public boolean isUserUnlocked(int userId) {
+    public boolean isUserUnlocked(@UserIdInt int userId) {
         // TODO: eventually pivot this back to look at ActivityManager state,
         // but there is race where we can start a non-encryption-aware launcher
         // before that lifecycle has entered the running unlocked state.
@@ -875,7 +876,7 @@
      * @return the UserInfo object for a specific user.
      * @hide
      */
-    public UserInfo getUserInfo(int userHandle) {
+    public UserInfo getUserInfo(@UserIdInt int userHandle) {
         try {
             return mService.getUserInfo(userHandle);
         } catch (RemoteException re) {
@@ -1093,7 +1094,7 @@
      * @return the UserInfo object for the created user, or null if the user could not be created.
      * @hide
      */
-    public UserInfo createProfileForUser(String name, int flags, int userHandle) {
+    public UserInfo createProfileForUser(String name, int flags, @UserIdInt int userHandle) {
         try {
             return mService.createProfileForUser(name, flags, userHandle);
         } catch (RemoteException re) {
@@ -1133,7 +1134,7 @@
      * @param userHandle
      * @return
      */
-    public boolean markGuestForDeletion(int userHandle) {
+    public boolean markGuestForDeletion(@UserIdInt int userHandle) {
         try {
             return mService.markGuestForDeletion(userHandle);
         } catch (RemoteException re) {
@@ -1150,7 +1151,7 @@
      * @param userHandle the id of the profile to enable
      * @hide
      */
-    public void setUserEnabled(int userHandle) {
+    public void setUserEnabled(@UserIdInt int userHandle) {
         try {
             mService.setUserEnabled(userHandle);
         } catch (RemoteException e) {
@@ -1189,7 +1190,7 @@
             Manifest.permission.INTERACT_ACROSS_USERS_FULL,
             Manifest.permission.MANAGE_USERS
     })
-    public @Nullable String getUserAccount(int userHandle) {
+    public @Nullable String getUserAccount(@UserIdInt int userHandle) {
         try {
             return mService.getUserAccount(userHandle);
         } catch (RemoteException re) {
@@ -1206,7 +1207,7 @@
             Manifest.permission.INTERACT_ACROSS_USERS_FULL,
             Manifest.permission.MANAGE_USERS
     })
-    public void setUserAccount(int userHandle, @Nullable String accountName) {
+    public void setUserAccount(@UserIdInt int userHandle, @Nullable String accountName) {
         try {
             mService.setUserAccount(userHandle, accountName);
         } catch (RemoteException re) {
@@ -1259,7 +1260,7 @@
      * @return true if more managed profiles can be added, false if limit has been reached.
      * @hide
      */
-    public boolean canAddMoreManagedProfiles(int userId, boolean allowedToRemoveOne) {
+    public boolean canAddMoreManagedProfiles(@UserIdInt int userId, boolean allowedToRemoveOne) {
         try {
             return mService.canAddMoreManagedProfiles(userId, allowedToRemoveOne);
         } catch (RemoteException re) {
@@ -1279,7 +1280,7 @@
      * @return the list of profiles.
      * @hide
      */
-    public List<UserInfo> getProfiles(int userHandle) {
+    public List<UserInfo> getProfiles(@UserIdInt int userHandle) {
         try {
             return mService.getProfiles(userHandle, false /* enabledOnly */);
         } catch (RemoteException re) {
@@ -1295,7 +1296,7 @@
      * @return true if the two user ids are in the same profile group.
      * @hide
      */
-    public boolean isSameProfileGroup(int userId, int otherUserId) {
+    public boolean isSameProfileGroup(@UserIdInt int userId, int otherUserId) {
         try {
             return mService.isSameProfileGroup(userId, otherUserId);
         } catch (RemoteException re) {
@@ -1314,7 +1315,7 @@
      * @return the list of profiles.
      * @hide
      */
-    public List<UserInfo> getEnabledProfiles(int userHandle) {
+    public List<UserInfo> getEnabledProfiles(@UserIdInt int userHandle) {
         try {
             return mService.getProfiles(userHandle, true /* enabledOnly */);
         } catch (RemoteException re) {
@@ -1352,7 +1353,7 @@
      *
      * @hide
      */
-    public int getCredentialOwnerProfile(int userHandle) {
+    public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
         try {
             return mService.getCredentialOwnerProfile(userHandle);
         } catch (RemoteException re) {
@@ -1367,7 +1368,7 @@
      *
      * @hide
      */
-    public UserInfo getProfileParent(int userHandle) {
+    public UserInfo getProfileParent(@UserIdInt int userHandle) {
         try {
             return mService.getProfileParent(userHandle);
         } catch (RemoteException re) {
@@ -1383,7 +1384,7 @@
      * @param enableQuietMode Whether quiet mode should be enabled or disabled.
      * @hide
      */
-    public void setQuietModeEnabled(int userHandle, boolean enableQuietMode) {
+    public void setQuietModeEnabled(@UserIdInt int userHandle, boolean enableQuietMode) {
         try {
             mService.setQuietModeEnabled(userHandle, enableQuietMode);
         } catch (RemoteException e) {
@@ -1499,7 +1500,7 @@
      * @param userHandle the integer handle of the user, where 0 is the primary user.
      * @hide
      */
-    public boolean removeUser(int userHandle) {
+    public boolean removeUser(@UserIdInt int userHandle) {
         try {
             return mService.removeUser(userHandle);
         } catch (RemoteException re) {
@@ -1516,7 +1517,7 @@
      * @param name the new name for the user
      * @hide
      */
-    public void setUserName(int userHandle, String name) {
+    public void setUserName(@UserIdInt int userHandle, String name) {
         try {
             mService.setUserName(userHandle, name);
         } catch (RemoteException re) {
@@ -1530,7 +1531,7 @@
      * @param icon the bitmap to set as the photo.
      * @hide
      */
-    public void setUserIcon(int userHandle, Bitmap icon) {
+    public void setUserIcon(@UserIdInt int userHandle, Bitmap icon) {
         try {
             mService.setUserIcon(userHandle, icon);
         } catch (RemoteException re) {
@@ -1545,7 +1546,7 @@
      * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default.
      * @hide
      */
-    public Bitmap getUserIcon(int userHandle) {
+    public Bitmap getUserIcon(@UserIdInt int userHandle) {
         try {
             ParcelFileDescriptor fd = mService.getUserIcon(userHandle);
             if (fd != null) {
@@ -1611,7 +1612,7 @@
      * @return a serial number associated with that user, or -1 if the userHandle is not valid.
      * @hide
      */
-    public int getUserSerialNumber(int userHandle) {
+    public int getUserSerialNumber(@UserIdInt int userHandle) {
         try {
             return mService.getUserSerialNumber(userHandle);
         } catch (RemoteException re) {
@@ -1629,7 +1630,7 @@
      * is not valid.
      * @hide
      */
-    public int getUserHandle(int userSerialNumber) {
+    public @UserIdInt int getUserHandle(int userSerialNumber) {
         try {
             return mService.getUserHandle(userSerialNumber);
         } catch (RemoteException re) {
diff --git a/core/java/android/print/IPrintSpooler.aidl b/core/java/android/print/IPrintSpooler.aidl
index c3625b8..469a4ea 100644
--- a/core/java/android/print/IPrintSpooler.aidl
+++ b/core/java/android/print/IPrintSpooler.aidl
@@ -98,5 +98,11 @@
     void writePrintJobData(in ParcelFileDescriptor fd, in PrintJobId printJobId);
     void setClient(IPrintSpoolerClient client);
     void setPrintJobCancelling(in PrintJobId printJobId, boolean cancelling);
-    void removeApprovedPrintService(in ComponentName serviceToRemove);
+
+    /**
+     * Remove all approved print services that are not in the given set.
+     *
+     * @param servicesToKeep The names of the services to keep
+     */
+    void pruneApprovedPrintServices(in List<ComponentName> servicesToKeep);
 }
diff --git a/core/java/android/print/PrinterInfo.java b/core/java/android/print/PrinterInfo.java
index 20d91b2..afef9c0 100644
--- a/core/java/android/print/PrinterInfo.java
+++ b/core/java/android/print/PrinterInfo.java
@@ -410,7 +410,7 @@
          * @see PrinterInfo#STATUS_BUSY
          * @see PrinterInfo#STATUS_UNAVAILABLE
          */
-        public @Nullable Builder setStatus(@Status int status) {
+        public @NonNull Builder setStatus(@Status int status) {
             mPrototype.mStatus = status;
             return this;
         }
diff --git a/core/java/android/printservice/PrintServiceInfo.java b/core/java/android/printservice/PrintServiceInfo.java
index b33ef83..91e01f2 100644
--- a/core/java/android/printservice/PrintServiceInfo.java
+++ b/core/java/android/printservice/PrintServiceInfo.java
@@ -16,6 +16,7 @@
 
 package android.printservice;
 
+import android.annotation.NonNull;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.pm.PackageManager;
@@ -94,6 +95,16 @@
     }
 
     /**
+     * Return the component name for this print service.
+     *
+     * @return The component name for this print service.
+     */
+    public @NonNull ComponentName getComponentName() {
+        return new ComponentName(mResolveInfo.serviceInfo.packageName,
+                mResolveInfo.serviceInfo.name);
+    }
+
+    /**
      * Creates a new instance.
      *
      * @param resolveInfo The service resolve info.
diff --git a/core/java/android/provider/DocumentsContract.java b/core/java/android/provider/DocumentsContract.java
index 084ff77..a401ac2 100644
--- a/core/java/android/provider/DocumentsContract.java
+++ b/core/java/android/provider/DocumentsContract.java
@@ -230,7 +230,6 @@
          * @see #FLAG_SUPPORTS_WRITE
          * @see #FLAG_SUPPORTS_DELETE
          * @see #FLAG_SUPPORTS_THUMBNAIL
-         * @see #FLAG_SUPPORTS_TYPED_DOCUMENT
          * @see #FLAG_DIR_PREFERS_GRID
          * @see #FLAG_DIR_PREFERS_LAST_MODIFIED
          * @see #FLAG_VIRTUAL_DOCUMENT
@@ -349,15 +348,6 @@
         public static final int FLAG_SUPPORTS_MOVE = 1 << 8;
 
         /**
-         * Flag indicating that a document can be converted to alternative types.
-         *
-         * @see #COLUMN_FLAGS
-         * @see DocumentsProvider#openTypedDocument(String, String, Bundle,
-         *      android.os.CancellationSignal)
-         */
-        public static final int FLAG_SUPPORTS_TYPED_DOCUMENT = 1 << 9;
-
-        /**
          * Flag indicating that a document is virtual, and doesn't have byte
          * representation in the MIME type specified as {@link #COLUMN_MIME_TYPE}.
          *
@@ -366,7 +356,7 @@
          * @see DocumentsProvider#openTypedDocument(String, String, Bundle,
          *      android.os.CancellationSignal)
          */
-        public static final int FLAG_VIRTUAL_DOCUMENT = 1 << 10;
+        public static final int FLAG_VIRTUAL_DOCUMENT = 1 << 9;
 
         /**
          * Flag indicating that a document is an archive, and it's contents can be
@@ -378,7 +368,7 @@
          * @see #COLUMN_FLAGS
          * @see DocumentsProvider#queryChildDocuments(String, String[], String)
          */
-        public static final int FLAG_ARCHIVE = 1 << 11;
+        public static final int FLAG_ARCHIVE = 1 << 10;
 
         /**
          * Flag indicating that document titles should be hidden when viewing
diff --git a/core/java/android/provider/DocumentsProvider.java b/core/java/android/provider/DocumentsProvider.java
index e25ba35..94b4157 100644
--- a/core/java/android/provider/DocumentsProvider.java
+++ b/core/java/android/provider/DocumentsProvider.java
@@ -517,13 +517,12 @@
      *            provider.
      * @param signal used by the caller to signal if the request should be
      *            cancelled. May be null.
-     * @see Document#FLAG_SUPPORTS_TYPED_DOCUMENT
      */
     @SuppressWarnings("unused")
     public AssetFileDescriptor openTypedDocument(
             String documentId, String mimeTypeFilter, Bundle opts, CancellationSignal signal)
             throws FileNotFoundException {
-        throw new UnsupportedOperationException("Typed documents not supported");
+        throw new FileNotFoundException("The requested MIME type is not supported.");
     }
 
     /**
diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java
index 48b3c1a..89ac27c9a 100644
--- a/core/java/android/provider/MediaStore.java
+++ b/core/java/android/provider/MediaStore.java
@@ -384,8 +384,14 @@
 
     public interface MediaColumns extends BaseColumns {
         /**
-         * The data stream for the file
-         * <P>Type: DATA STREAM</P>
+         * Path to the file on disk.
+         * <p>
+         * Note that apps may not have filesystem permissions to directly access
+         * this path. Instead of trying to open this path directly, apps should
+         * use {@link ContentResolver#openFileDescriptor(Uri, String)} to gain
+         * access.
+         * <p>
+         * Type: TEXT
          */
         public static final String DATA = "_data";
 
@@ -1149,8 +1155,15 @@
             public static final String DEFAULT_SORT_ORDER = "image_id ASC";
 
             /**
-             * The data stream for the thumbnail
-             * <P>Type: DATA STREAM</P>
+             * Path to the thumbnail file on disk.
+             * <p>
+             * Note that apps may not have filesystem permissions to directly
+             * access this path. Instead of trying to open this path directly,
+             * apps should use
+             * {@link ContentResolver#openFileDescriptor(Uri, String)} to gain
+             * access.
+             * <p>
+             * Type: TEXT
              */
             public static final String DATA = "_data";
 
@@ -1596,8 +1609,15 @@
             public static final String NAME = "name";
 
             /**
-             * The data stream for the playlist file
-             * <P>Type: DATA STREAM</P>
+             * Path to the playlist file on disk.
+             * <p>
+             * Note that apps may not have filesystem permissions to directly
+             * access this path. Instead of trying to open this path directly,
+             * apps should use
+             * {@link ContentResolver#openFileDescriptor(Uri, String)} to gain
+             * access.
+             * <p>
+             * Type: TEXT
              */
             public static final String DATA = "_data";
 
@@ -2192,8 +2212,15 @@
             public static final String DEFAULT_SORT_ORDER = "video_id ASC";
 
             /**
-             * The data stream for the thumbnail
-             * <P>Type: DATA STREAM</P>
+             * Path to the thumbnail file on disk.
+             * <p>
+             * Note that apps may not have filesystem permissions to directly
+             * access this path. Instead of trying to open this path directly,
+             * apps should use
+             * {@link ContentResolver#openFileDescriptor(Uri, String)} to gain
+             * access.
+             * <p>
+             * Type: TEXT
              */
             public static final String DATA = "_data";
 
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index b883f9c..e1391da 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -19,6 +19,7 @@
 import android.annotation.SdkConstant;
 import android.annotation.SdkConstant.SdkConstantType;
 import android.annotation.SystemApi;
+import android.annotation.TestApi;
 import android.app.ActivityThread;
 import android.app.AppOpsManager;
 import android.app.Application;
@@ -1138,6 +1139,19 @@
     /** @hide */ public static final String EXTRA_APP_UID = "app_uid";
     /** @hide */ public static final String EXTRA_APP_PACKAGE = "app_package";
 
+    /**
+     * Activity Action: Show a dialog with disabled by policy message.
+     * <p> If an user action is disabled by policy, this dialog can be triggered to let
+     * the user know about this.
+     * <p>
+     * Input: Nothing.
+     * <p>
+     * Output: Nothing.
+     */
+    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
+    public static final String ACTION_SHOW_ADMIN_SUPPORT_DETAILS
+            = "android.settings.SHOW_ADMIN_SUPPORT_DETAILS";
+
     // End of Intent actions for Settings
 
     /**
@@ -4349,6 +4363,7 @@
          * The currently selected voice interaction service flattened ComponentName.
          * @hide
          */
+        @TestApi
         public static final String VOICE_INTERACTION_SERVICE = "voice_interaction_service";
 
         /**
@@ -4972,19 +4987,22 @@
 
         /**
          * List of the enabled print services.
+         *
+         * N and beyond uses {@link #DISABLED_PRINT_SERVICES}. But this might be used in an upgrade
+         * from pre-N.
+         *
          * @hide
          */
         public static final String ENABLED_PRINT_SERVICES =
             "enabled_print_services";
 
         /**
-         * List of the system print services we enabled on first boot. On
-         * first boot we enable all system, i.e. bundled print services,
-         * once, so they work out-of-the-box.
+         * List of the disabled print services.
+         *
          * @hide
          */
-        public static final String ENABLED_ON_FIRST_BOOT_SYSTEM_PRINT_SERVICES =
-            "enabled_on_first_boot_system_print_services";
+        public static final String DISABLED_PRINT_SERVICES =
+            "disabled_print_services";
 
         /**
          * Setting to always use the default text-to-speech settings regardless
@@ -6374,6 +6392,13 @@
         public static final String DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES
                 = "force_resizable_activities";
 
+        /**
+         * Whether to enable experimental freeform support for windows.
+         * @hide
+         */
+        public static final String DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT
+                = "enable_freeform_support";
+
        /**
         * Whether user has enabled development settings.
         */
diff --git a/core/java/android/security/NetworkSecurityPolicy.java b/core/java/android/security/NetworkSecurityPolicy.java
index 46aa1af..37ec725 100644
--- a/core/java/android/security/NetworkSecurityPolicy.java
+++ b/core/java/android/security/NetworkSecurityPolicy.java
@@ -68,7 +68,6 @@
      * TLS or STARTTLS) is permitted for communicating with {@code hostname} for this process.
      *
      * @see #isCleartextTrafficPermitted()
-     * @hide
      */
     public boolean isCleartextTrafficPermitted(String hostname) {
         return libcore.net.NetworkSecurityPolicy.getInstance()
diff --git a/core/java/android/security/net/config/ApplicationConfig.java b/core/java/android/security/net/config/ApplicationConfig.java
index 71d9d5d..4de36cd 100644
--- a/core/java/android/security/net/config/ApplicationConfig.java
+++ b/core/java/android/security/net/config/ApplicationConfig.java
@@ -120,6 +120,32 @@
         return mTrustManager;
     }
 
+    /**
+     * Returns {@code true} if cleartext traffic is permitted for this application, which is the
+     * case only if all configurations permit cleartext traffic. For finer-grained policy use
+     * {@link #isCleartextTrafficPermitted(String)}.
+     */
+    public boolean isCleartextTrafficPermitted() {
+        ensureInitialized();
+        if (mConfigs != null) {
+            for (Pair<Domain, NetworkSecurityConfig> entry : mConfigs) {
+                if (!entry.second.isCleartextTrafficPermitted()) {
+                    return false;
+                }
+            }
+        }
+
+        return mDefaultConfig.isCleartextTrafficPermitted();
+    }
+
+    /**
+     * Returns {@code true} if cleartext traffic is permitted for this application when connecting
+     * to {@code hostname}.
+     */
+    public boolean isCleartextTrafficPermitted(String hostname) {
+        return getConfigForHostname(hostname).isCleartextTrafficPermitted();
+    }
+
     private void ensureInitialized() {
         synchronized(mLock) {
             if (mInitialized) {
diff --git a/core/java/android/security/net/config/ConfigNetworkSecurityPolicy.java b/core/java/android/security/net/config/ConfigNetworkSecurityPolicy.java
new file mode 100644
index 0000000..e7d17c2
--- /dev/null
+++ b/core/java/android/security/net/config/ConfigNetworkSecurityPolicy.java
@@ -0,0 +1,40 @@
+/**
+ * Copyright (c) 2015, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.security.net.config;
+
+/**
+ * {@link libcore.net.NetworkSecurityPolicy} based on an {@link ApplicationConfig}.
+ *
+ * @hide
+ */
+public class ConfigNetworkSecurityPolicy extends libcore.net.NetworkSecurityPolicy {
+    private final ApplicationConfig mConfig;
+
+    public ConfigNetworkSecurityPolicy(ApplicationConfig config) {
+        mConfig = config;
+    }
+
+    @Override
+    public boolean isCleartextTrafficPermitted() {
+        return mConfig.isCleartextTrafficPermitted();
+    }
+
+    @Override
+    public boolean isCleartextTrafficPermitted(String hostname) {
+        return mConfig.isCleartextTrafficPermitted(hostname);
+    }
+}
diff --git a/core/java/android/security/net/config/NetworkSecurityConfigProvider.java b/core/java/android/security/net/config/NetworkSecurityConfigProvider.java
index 5ebc7ac..0f66873 100644
--- a/core/java/android/security/net/config/NetworkSecurityConfigProvider.java
+++ b/core/java/android/security/net/config/NetworkSecurityConfigProvider.java
@@ -40,5 +40,6 @@
             throw new RuntimeException("Failed to install provider as highest priority provider."
                     + " Provider was installed at position " + pos);
         }
+        libcore.net.NetworkSecurityPolicy.setInstance(new ConfigNetworkSecurityPolicy(config));
     }
 }
diff --git a/core/java/android/service/notification/INotificationAssistant.aidl b/core/java/android/service/notification/INotificationAssistant.aidl
deleted file mode 100644
index 5c5f358..0000000
--- a/core/java/android/service/notification/INotificationAssistant.aidl
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Copyright (c) 2015, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.service.notification;
-
-import android.service.notification.NotificationAdjustment;
-import android.service.notification.IStatusBarNotificationHolder;
-import android.service.notification.NotificationRankingUpdate;
-
-/** @hide */
-interface INotificationAssistant
-{
-    void onListenerConnected(in NotificationRankingUpdate update);
-    void onNotificationPosted(in IStatusBarNotificationHolder notificationHolder,
-            in NotificationRankingUpdate update);
-    void onNotificationRankingUpdate(in NotificationRankingUpdate update);
-    void onListenerHintsChanged(int hints);
-    void onInterruptionFilterChanged(int interruptionFilter);
-    NotificationAdjustment onNotificationEnqueued(in IStatusBarNotificationHolder notificationHolder, int importance, boolean user);
-    void onNotificationVisibilityChanged(String key, long time, boolean visible);
-    void onNotificationClick(String key, long time);
-    void onNotificationActionClick(String key, long time, int actionIndex);
-    void onNotificationRemoved(String key, long time, int reason);
-}
\ No newline at end of file
diff --git a/core/java/android/service/notification/INotificationListener.aidl b/core/java/android/service/notification/INotificationListener.aidl
index e6bf6ba..a0de17f 100644
--- a/core/java/android/service/notification/INotificationListener.aidl
+++ b/core/java/android/service/notification/INotificationListener.aidl
@@ -23,6 +23,7 @@
 /** @hide */
 oneway interface INotificationListener
 {
+    // listeners and assistants
     void onListenerConnected(in NotificationRankingUpdate update);
     void onNotificationPosted(in IStatusBarNotificationHolder notificationHolder,
             in NotificationRankingUpdate update);
@@ -31,4 +32,11 @@
     void onNotificationRankingUpdate(in NotificationRankingUpdate update);
     void onListenerHintsChanged(int hints);
     void onInterruptionFilterChanged(int interruptionFilter);
+
+    // assistants only
+    void onNotificationEnqueued(in IStatusBarNotificationHolder notificationHolder, int importance, boolean user);
+    void onNotificationVisibilityChanged(String key, long time, boolean visible);
+    void onNotificationClick(String key, long time);
+    void onNotificationActionClick(String key, long time, int actionIndex);
+    void onNotificationRemovedReason(String key, long time, int reason);
 }
diff --git a/core/java/android/service/notification/NotificationAdjustment.java b/core/java/android/service/notification/NotificationAdjustment.java
deleted file mode 100644
index c5f0db9..0000000
--- a/core/java/android/service/notification/NotificationAdjustment.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package android.service.notification;
-
-import android.net.Uri;
-import android.os.Parcel;
-import android.os.Parcelable;
-
-public class NotificationAdjustment implements Parcelable {
-    int mImportance;
-    CharSequence mExplanation;
-    Uri mReference;
-
-    /**
-     * Create a notification importance adjustment.
-     *
-     * @param importance The final importance of the notification.
-     * @param explanation A human-readable justification for the adjustment.
-     * @param reference A reference to an external object that augments the
-     *                  explanation, such as a
-     *                  {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI},
-     *                  or null.
-     */
-    public NotificationAdjustment(int importance, CharSequence explanation, Uri reference) {
-        mImportance = importance;
-        mExplanation = explanation;
-        mReference = reference;
-    }
-
-    private NotificationAdjustment(Parcel source) {
-        this(source.readInt(), source.readCharSequence(),
-                (Uri) source.readParcelable(NotificationAdjustment.class.getClassLoader()));
-    }
-
-    @Override
-    public int describeContents() {
-        return 0;
-    }
-
-    @Override
-    public void writeToParcel(Parcel dest, int flags) {
-        dest.writeInt(mImportance);
-        dest.writeCharSequence(mExplanation);
-        dest.writeParcelable(mReference, 0);
-    }
-
-    public static final Parcelable.Creator<NotificationAdjustment> CREATOR
-            = new Parcelable.Creator<NotificationAdjustment>() {
-        @Override
-        public NotificationAdjustment createFromParcel(Parcel source) {
-            return new NotificationAdjustment(source);
-        }
-
-        @Override
-        public NotificationAdjustment[] newArray(int size) {
-            return new NotificationAdjustment[size];
-        }
-    };
-}
diff --git a/core/java/android/service/notification/NotificationAssistantService.java b/core/java/android/service/notification/NotificationAssistantService.java
index 7ce5e1f..3a8956e 100644
--- a/core/java/android/service/notification/NotificationAssistantService.java
+++ b/core/java/android/service/notification/NotificationAssistantService.java
@@ -20,8 +20,11 @@
 import android.app.Notification;
 import android.content.Intent;
 import android.net.Uri;
+import android.os.IBinder;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.os.RemoteException;
+import android.util.Log;
 
 /**
  * A service that helps the user manage notifications by modifying the
@@ -39,6 +42,8 @@
  * &lt;/service></pre>
  */
 public abstract class NotificationAssistantService extends NotificationListenerService {
+    private static final String TAG = "NotificationAssistant";
+
     /**
      * The {@link Intent} that must be declared as handled by the service.
      */
@@ -85,6 +90,36 @@
     /** Notification was canceled because it was an invisible member of a group. */
     public static final int REASON_GROUP_OPTIMIZATION = 13;
 
+    public class Adjustment {
+        int mImportance;
+        CharSequence mExplanation;
+        Uri mReference;
+
+        /**
+         * Create a notification importance adjustment.
+         *
+         * @param importance The final importance of the notification.
+         * @param explanation A human-readable justification for the adjustment.
+         * @param reference A reference to an external object that augments the
+         *                  explanation, such as a
+         *                  {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI},
+         *                  or null.
+         */
+        public Adjustment(int importance, CharSequence explanation, Uri reference) {
+            mImportance = importance;
+            mExplanation = explanation;
+            mReference = reference;
+        }
+    }
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        if (mWrapper == null) {
+            mWrapper = new NotificationAssistantWrapper();
+        }
+        return mWrapper;
+    }
+
     /**
      * A notification was posted by an app. Called before alert.
      *
@@ -93,7 +128,7 @@
      * @param user true if the initial importance reflects an explicit user preference.
      * @return an adjustment or null to take no action, within 100ms.
      */
-    abstract public NotificationAdjustment onNotificationEnqueued(StatusBarNotification sbn,
+    abstract public Adjustment onNotificationEnqueued(StatusBarNotification sbn,
           int importance, boolean user);
 
     /**
@@ -150,9 +185,15 @@
      * @param key the notification key
      * @param adjustment the new importance with an explanation
      */
-    public final void adjustImportance(String key, NotificationAdjustment adjustment)
+    public final void adjustImportance(String key, Adjustment adjustment)
     {
-        // TODO: pack up the adjustment and send it to the NotificationManager.
+        if (!isBound()) return;
+        try {
+            getNotificationInterface().setImportanceFromAssistant(mWrapper, key,
+                    adjustment.mImportance, adjustment.mExplanation);
+        } catch (android.os.RemoteException ex) {
+            Log.v(TAG, "Unable to contact notification manager", ex);
+        }
     }
 
     /**
@@ -160,7 +201,7 @@
      * be fired when the host notification is deleted, or when this annotation
      * is removed or replaced.
      *
-     * @param key the notification key
+     * @param key the key of the notification to be annotated
      * @param annotation the new annotation object
      */
     public final void setAnnotation(String key, Notification annotation)
@@ -171,10 +212,74 @@
     /**
      * Remove the annotation from a notification.
      *
-     * @param key the notification key
+     * @param key the key of the notification to be cleansed of annotatons
      */
     public final void clearAnnotation(String key)
     {
         // TODO: ask the NotificationManager to clear the annotation.
     }
+
+    private class NotificationAssistantWrapper extends NotificationListenerWrapper {
+        @Override
+        public void onNotificationEnqueued(IStatusBarNotificationHolder sbnHolder,
+                                           int importance, boolean user) throws RemoteException {
+            StatusBarNotification sbn;
+            try {
+                sbn = sbnHolder.get();
+            } catch (RemoteException e) {
+                Log.w(TAG, "onNotificationEnqueued: Error receiving StatusBarNotification", e);
+                return;
+            }
+
+            try {
+                Adjustment adjustment =
+                    NotificationAssistantService.this.onNotificationEnqueued(sbn, importance, user);
+                if (adjustment != null) {
+                    adjustImportance(sbn.getKey(), adjustment);
+                }
+            } catch (Throwable t) {
+                Log.w(TAG, "Error running onNotificationEnqueued", t);
+            }
+        }
+
+        @Override
+        public void onNotificationVisibilityChanged(String key, long time, boolean visible)
+                throws RemoteException {
+            try {
+                NotificationAssistantService.this.onNotificationVisibilityChanged(key, time,
+                        visible);
+            } catch (Throwable t) {
+                Log.w(TAG, "Error running onNotificationVisibilityChanged", t);
+            }
+        }
+
+        @Override
+        public void onNotificationClick(String key, long time) throws RemoteException {
+            try {
+                NotificationAssistantService.this.onNotificationClick(key, time);
+            } catch (Throwable t) {
+                Log.w(TAG, "Error running onNotificationClick", t);
+            }
+        }
+
+        @Override
+        public void onNotificationActionClick(String key, long time, int actionIndex)
+                throws RemoteException {
+            try {
+                NotificationAssistantService.this.onNotificationActionClick(key, time, actionIndex);
+            } catch (Throwable t) {
+                Log.w(TAG, "Error running onNotificationActionClick", t);
+            }
+        }
+
+        @Override
+        public void onNotificationRemovedReason(String key, long time, int reason)
+                throws RemoteException {
+            try {
+                NotificationAssistantService.this.onNotificationRemoved(key, time, reason);
+            } catch (Throwable t) {
+                Log.w(TAG, "Error running onNotificationRemoved", t);
+            }
+        }
+    }
 }
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java
index 1e62edc..b42d9ea 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -15,6 +15,7 @@
  */
 
 package android.service.notification;
+import android.service.notification.IStatusBarNotificationHolder;
 
 import android.annotation.SystemApi;
 import android.annotation.SdkConstant;
@@ -122,6 +123,8 @@
             NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
     public static final int SUPPRESSED_EFFECT_PEEK =
             NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
+    public static final int SUPPRESSED_EFFECT_SCREEN_ON =
+            NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON;
 
     /**
      * The full trim of the StatusBarNotification including all its features.
@@ -151,7 +154,8 @@
     @SystemApi
     public static final int TRIM_LIGHT = 1;
 
-    private INotificationListenerWrapper mWrapper = null;
+    /** @hide */
+    protected NotificationListenerWrapper mWrapper = null;
     private RankingMap mRankingMap;
 
     private INotificationManager mNoMan;
@@ -291,7 +295,8 @@
         // optional
     }
 
-    private final INotificationManager getNotificationInterface() {
+    /** @hide */
+    protected final INotificationManager getNotificationInterface() {
         if (mNoMan == null) {
             mNoMan = INotificationManager.Stub.asInterface(
                     ServiceManager.getService(Context.NOTIFICATION_SERVICE));
@@ -634,12 +639,13 @@
     @Override
     public IBinder onBind(Intent intent) {
         if (mWrapper == null) {
-            mWrapper = new INotificationListenerWrapper();
+            mWrapper = new NotificationListenerWrapper();
         }
         return mWrapper;
     }
 
-    private boolean isBound() {
+    /** @hide */
+    protected boolean isBound() {
         if (mWrapper == null) {
             Log.w(TAG, "Notification listener service not yet bound.");
             return false;
@@ -664,7 +670,7 @@
             int currentUser) throws RemoteException {
         mSystemContext = context;
         if (mWrapper == null) {
-            mWrapper = new INotificationListenerWrapper();
+            mWrapper = new NotificationListenerWrapper();
         }
         INotificationManager noMan = getNotificationInterface();
         noMan.registerListener(mWrapper, componentName, currentUser);
@@ -716,7 +722,8 @@
         }
     }
 
-    private class INotificationListenerWrapper extends INotificationListener.Stub {
+    /** @hide */
+    protected class NotificationListenerWrapper extends INotificationListener.Stub {
         @Override
         public void onNotificationPosted(IStatusBarNotificationHolder sbnHolder,
                 NotificationRankingUpdate update) {
@@ -817,6 +824,35 @@
                 Log.w(TAG, "Error running onInterruptionFilterChanged", t);
             }
         }
+
+        @Override
+        public void onNotificationEnqueued(IStatusBarNotificationHolder notificationHolder,
+                                           int importance, boolean user) throws RemoteException {
+            // no-op in the listener
+        }
+
+        @Override
+        public void onNotificationVisibilityChanged(String key, long time, boolean visible)
+                throws RemoteException {
+            // no-op in the listener
+        }
+
+        @Override
+        public void onNotificationClick(String key, long time) throws RemoteException {
+            // no-op in the listener
+        }
+
+        @Override
+        public void onNotificationActionClick(String key, long time, int actionIndex)
+                throws RemoteException {
+            // no-op in the listener
+        }
+
+        @Override
+        public void onNotificationRemovedReason(String key, long time, int reason)
+                throws RemoteException {
+            // no-op in the listener
+        }
     }
 
     private void applyUpdate(NotificationRankingUpdate update) {
@@ -927,7 +963,8 @@
 
         /**
          * Returns the type(s) of visual effects that should be suppressed for this notification.
-         * See {@link #SUPPRESSED_EFFECT_LIGHTS}, {@link #SUPPRESSED_EFFECT_PEEK}}.
+         * See {@link #SUPPRESSED_EFFECT_LIGHTS}, {@link #SUPPRESSED_EFFECT_PEEK},
+         * {@link #SUPPRESSED_EFFECT_SCREEN_ON}.
          */
         public int getSuppressedVisualEffects() {
             return mSuppressedVisualEffects;
diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java
index 541623d..4688843 100644
--- a/core/java/android/service/notification/ZenModeConfig.java
+++ b/core/java/android/service/notification/ZenModeConfig.java
@@ -79,6 +79,7 @@
     private static final boolean DEFAULT_ALLOW_REPEAT_CALLERS = false;
     private static final boolean DEFAULT_ALLOW_PEEK = true;
     private static final boolean DEFAULT_ALLOW_LIGHTS = true;
+    private static final boolean DEFAULT_ALLOW_SCREEN_ON = true;
 
     private static final int XML_VERSION = 2;
     private static final String ZEN_TAG = "zen";
@@ -95,6 +96,7 @@
     private static final String ALLOW_ATT_EVENTS = "events";
     private static final String ALLOW_ATT_PEEK = "peek";
     private static final String ALLOW_ATT_LIGHTS = "lights";
+    private static final String ALLOW_ATT_SCREEN_ON = "screen_on";
 
     private static final String CONDITION_TAG = "condition";
     private static final String CONDITION_ATT_COMPONENT = "component";
@@ -128,6 +130,7 @@
     public int user = UserHandle.USER_SYSTEM;
     public boolean allowPeek = DEFAULT_ALLOW_PEEK;
     public boolean allowLights = DEFAULT_ALLOW_LIGHTS;
+    public boolean allowScreenOn = DEFAULT_ALLOW_SCREEN_ON;
 
     public ZenRule manualRule;
     public ArrayMap<String, ZenRule> automaticRules = new ArrayMap<>();
@@ -156,6 +159,7 @@
         }
         allowPeek = source.readInt() == 1;
         allowLights = source.readInt() == 1;
+        allowScreenOn = source.readInt() == 1;
     }
 
     @Override
@@ -185,6 +189,7 @@
         }
         dest.writeInt(allowPeek ? 1 : 0);
         dest.writeInt(allowLights ? 1 : 0);
+        dest.writeInt(allowScreenOn ? 1 : 0);
     }
 
     @Override
@@ -200,6 +205,7 @@
                 .append(",allowEvents=").append(allowEvents)
                 .append(",allowPeek=").append(allowPeek)
                 .append(",allowLights=").append(allowLights)
+                .append(",allowScreenOn=").append(allowScreenOn)
                 .append(",automaticRules=").append(automaticRules)
                 .append(",manualRule=").append(manualRule)
                 .append(']').toString();
@@ -240,6 +246,9 @@
         if (allowLights != to.allowLights) {
             d.addLine("allowLights", allowLights, to.allowLights);
         }
+        if (allowScreenOn != to.allowScreenOn) {
+            d.addLine("allowScreenOn", allowScreenOn, to.allowScreenOn);
+        }
         final ArraySet<String> allRules = new ArraySet<>();
         addKeys(allRules, automaticRules);
         addKeys(allRules, to.automaticRules);
@@ -339,6 +348,7 @@
                 && other.allowEvents == allowEvents
                 && other.allowPeek == allowPeek
                 && other.allowLights == allowLights
+                && other.allowScreenOn == allowScreenOn
                 && other.user == user
                 && Objects.equals(other.automaticRules, automaticRules)
                 && Objects.equals(other.manualRule, manualRule);
@@ -348,7 +358,7 @@
     public int hashCode() {
         return Objects.hash(allowCalls, allowRepeatCallers, allowMessages, allowCallsFrom,
                 allowMessagesFrom, allowReminders, allowEvents, allowPeek, allowLights,
-                user, automaticRules, manualRule);
+                allowScreenOn, user, automaticRules, manualRule);
     }
 
     private static String toDayList(int[] days) {
@@ -435,6 +445,8 @@
                     }
                     rt.allowPeek = safeBoolean(parser, ALLOW_ATT_PEEK, DEFAULT_ALLOW_PEEK);
                     rt.allowLights = safeBoolean(parser, ALLOW_ATT_LIGHTS, DEFAULT_ALLOW_LIGHTS);
+                    rt.allowScreenOn =
+                            safeBoolean(parser, ALLOW_ATT_SCREEN_ON, DEFAULT_ALLOW_SCREEN_ON);
                 } else if (MANUAL_TAG.equals(tag)) {
                     rt.manualRule = readRuleXml(parser);
                 } else if (AUTOMATIC_TAG.equals(tag)) {
@@ -465,6 +477,7 @@
         out.attribute(null, ALLOW_ATT_MESSAGES_FROM, Integer.toString(allowMessagesFrom));
         out.attribute(null, ALLOW_ATT_PEEK, Boolean.toString(allowPeek));
         out.attribute(null, ALLOW_ATT_LIGHTS, Boolean.toString(allowLights));
+        out.attribute(null, ALLOW_ATT_SCREEN_ON, Boolean.toString(allowScreenOn));
         out.endTag(null, ALLOW_TAG);
 
         if (manualRule != null) {
@@ -643,6 +656,9 @@
         if (!allowLights) {
             suppressedVisualEffects |= Policy.SUPPRESSED_EFFECT_LIGHTS;
         }
+        if (!allowScreenOn) {
+            suppressedVisualEffects |= Policy.SUPPRESSED_EFFECT_SCREEN_ON;
+        }
         priorityCallSenders = sourceToPrioritySenders(allowCallsFrom, priorityCallSenders);
         priorityMessageSenders = sourceToPrioritySenders(allowMessagesFrom, priorityMessageSenders);
         return new Policy(priorityCategories, priorityCallSenders, priorityMessageSenders,
@@ -681,6 +697,8 @@
         if (policy.suppressedVisualEffects != Policy.SUPPRESSED_EFFECTS_UNSET) {
             allowPeek = (policy.suppressedVisualEffects & Policy.SUPPRESSED_EFFECT_PEEK) == 0;
             allowLights = (policy.suppressedVisualEffects & Policy.SUPPRESSED_EFFECT_LIGHTS) == 0;
+            allowScreenOn =
+                    (policy.suppressedVisualEffects & Policy.SUPPRESSED_EFFECT_SCREEN_ON) == 0;
         }
     }
 
diff --git a/core/java/android/service/quicksettings/IQSService.aidl b/core/java/android/service/quicksettings/IQSService.aidl
index 7e70501..75da82f 100644
--- a/core/java/android/service/quicksettings/IQSService.aidl
+++ b/core/java/android/service/quicksettings/IQSService.aidl
@@ -24,4 +24,5 @@
 interface IQSService {
     void updateQsTile(in Tile tile);
     void onShowDialog(in Tile tile);
+    void setTileMode(in ComponentName component, int mode);
 }
diff --git a/core/java/android/service/quicksettings/IQSTileService.aidl b/core/java/android/service/quicksettings/IQSTileService.aidl
index 63a4c5e..4997f75 100644
--- a/core/java/android/service/quicksettings/IQSTileService.aidl
+++ b/core/java/android/service/quicksettings/IQSTileService.aidl
@@ -22,6 +22,7 @@
  * @hide
  */
 oneway interface IQSTileService {
+    void setQSService(in IQSService service);
     void setQSTile(in Tile tile);
     void onTileAdded();
     void onTileRemoved();
diff --git a/core/java/android/service/quicksettings/Tile.java b/core/java/android/service/quicksettings/Tile.java
index a53fc59..6104913 100644
--- a/core/java/android/service/quicksettings/Tile.java
+++ b/core/java/android/service/quicksettings/Tile.java
@@ -37,11 +37,12 @@
     private static final String TAG = "Tile";
 
     private ComponentName mComponentName;
-    private IQSService mService;
     private Icon mIcon;
     private CharSequence mLabel;
     private CharSequence mContentDescription;
 
+    private IQSService mService;
+
     /**
      * @hide
      */
@@ -52,8 +53,14 @@
     /**
      * @hide
      */
-    public Tile(ComponentName componentName, IQSService service) {
+    public Tile(ComponentName componentName) {
         mComponentName = componentName;
+    }
+
+    /**
+     * @hide
+     */
+    public void setService(IQSService service) {
         mService = service;
     }
 
@@ -65,6 +72,13 @@
     }
 
     /**
+     * @hide
+     */
+    public IQSService getQsService() {
+        return mService;
+    }
+
+    /**
      * Gets the current icon for the tile.
      */
     public Icon getIcon() {
@@ -137,21 +151,8 @@
         }
     }
 
-    /**
-     * @hide
-     * Notifies the IQSService that this tile is showing a dialog.
-     */
-    void onShowDialog() {
-        try {
-            mService.onShowDialog(this);
-        } catch (RemoteException e) {
-            Log.e(TAG, "Couldn't onShowDialog");
-        }
-    }
-
     @Override
     public void writeToParcel(Parcel dest, int flags) {
-        dest.writeStrongInterface(mService);
         if (mComponentName != null) {
             dest.writeByte((byte) 1);
             mComponentName.writeToParcel(dest, flags);
@@ -169,7 +170,6 @@
     }
 
     private void readFromParcel(Parcel source) {
-        mService = IQSService.Stub.asInterface(source.readStrongBinder());
         if (source.readByte() != 0) {
             mComponentName = ComponentName.CREATOR.createFromParcel(source);
         } else {
diff --git a/core/java/android/service/quicksettings/TileService.java b/core/java/android/service/quicksettings/TileService.java
index d8787b4..9b50ef5 100644
--- a/core/java/android/service/quicksettings/TileService.java
+++ b/core/java/android/service/quicksettings/TileService.java
@@ -15,8 +15,11 @@
  */
 package android.service.quicksettings;
 
+import android.Manifest;
 import android.app.Dialog;
 import android.app.Service;
+import android.content.ComponentName;
+import android.content.Context;
 import android.content.Intent;
 import android.os.Handler;
 import android.os.IBinder;
@@ -26,29 +29,29 @@
 import android.view.WindowManager;
 
 /**
- * A QSTileService provides the user a tile that can be added to Quick Settings.
+ * A TileService provides the user a tile that can be added to Quick Settings.
  * Quick Settings is a space provided that allows the user to change settings and
  * take quick actions without leaving the context of their current app.
  *
- * <p>The lifecycle of a QSTileService is different from some other services in
+ * <p>The lifecycle of a TileService is different from some other services in
  * that it may be unbound during parts of its lifecycle.  Any of the following
  * lifecycle events can happen indepently in a separate binding/creation of the
  * service.</p>
  *
  * <ul>
- * <li>When a tile is added by the user its QSTileService will be bound to and
+ * <li>When a tile is added by the user its TileService will be bound to and
  * {@link #onTileAdded()} will be called.</li>
  *
  * <li>When a tile should be up to date and listing will be indicated by
  * {@link #onStartListening()} and {@link #onStopListening()}.</li>
  *
- * <li>When the user removes a tile from Quick Settings {@link #onStopListening()}
+ * <li>When the user removes a tile from Quick Settings {@link #onTileRemoved()}
  * will be called.</li>
  * </ul>
- * <p>QSTileService will be detected by tiles that match the {@value #ACTION_QS_TILE}
+ * <p>TileService will be detected by tiles that match the {@value #ACTION_QS_TILE}
  * and require the permission "android.permission.BIND_QUICK_SETTINGS_TILE".
  * The label and icon for the service will be used as the default label and
- * icon for the tile. Here is an example QSTileService declaration.</p>
+ * icon for the tile. Here is an example TileService declaration.</p>
  * <pre class="prettyprint">
  * {@literal
  * <service
@@ -67,15 +70,52 @@
 public class TileService extends Service {
 
     /**
-     * Action that identifies a Service as being a QSTileService.
+     * Action that identifies a Service as being a TileService.
      */
     public static final String ACTION_QS_TILE = "android.service.quicksettings.action.QS_TILE";
 
+    /**
+     * The tile mode hasn't been set yet.
+     * @hide
+     */
+    public static final int TILE_MODE_UNSET = 0;
+
+    /**
+     * Constant to be returned by {@link #onTileAdded}.
+     * <p>
+     * Passive mode is the default mode for tiles.  The System will tell the tile
+     * when it is most important to update by putting it in the listening state.
+     */
+    public static final int TILE_MODE_PASSIVE = 1;
+
+    /**
+     * Constant to be returned by {@link #onTileAdded}.
+     * <p>
+     * Active mode is for tiles which already listen and keep track of their state in their
+     * own process.  These tiles may request to send an update to the System while their process
+     * is alive using {@link #requestListeningState}.  The System will only bind these tiles
+     * on its own when a click needs to occur.
+     */
+    public static final int TILE_MODE_ACTIVE = 2;
+
+    /**
+     * Used to notify SysUI that Listening has be requested.
+     * @hide
+     */
+    public static final String ACTION_REQUEST_LISTENING
+            = "android.service.quicksettings.action.REQUEST_LISTENING";
+
+    /**
+     * @hide
+     */
+    public static final String EXTRA_COMPONENT = "android.service.quicksettings.extra.COMPONENT";
+
     private final H mHandler = new H(Looper.getMainLooper());
 
     private boolean mListening = false;
     private Tile mTile;
     private IBinder mToken;
+    private IQSService mService;
 
     @Override
     public void onDestroy() {
@@ -92,8 +132,12 @@
      * Note that this is not guaranteed to be called between {@link #onCreate()}
      * and {@link #onStartListening()}, it will only be called when the tile is added
      * and not on subsequent binds.
+     *
+     * @see #TILE_MODE_PASSIVE
+     * @see #TILE_MODE_ACTIVE
      */
-    public void onTileAdded() {
+    public int onTileAdded() {
+        return TILE_MODE_PASSIVE;
     }
 
     /**
@@ -138,7 +182,10 @@
         dialog.getWindow().getAttributes().token = mToken;
         dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_QS_DIALOG);
         dialog.show();
-        getQsTile().onShowDialog();
+        try {
+            mService.onShowDialog(mTile);
+        } catch (RemoteException e) {
+        }
     }
 
     /**
@@ -156,6 +203,11 @@
     public IBinder onBind(Intent intent) {
         return new IQSTileService.Stub() {
             @Override
+            public void setQSService(IQSService service) throws RemoteException {
+                mHandler.obtainMessage(H.MSG_SET_SERVICE, service).sendToTarget();
+            }
+
+            @Override
             public void setQSTile(Tile tile) throws RemoteException {
                 mHandler.obtainMessage(H.MSG_SET_TILE, tile).sendToTarget();
             }
@@ -194,6 +246,7 @@
         private static final int MSG_TILE_ADDED = 4;
         private static final int MSG_TILE_REMOVED = 5;
         private static final int MSG_TILE_CLICKED = 6;
+        private static final int MSG_SET_SERVICE = 7;
 
         public H(Looper looper) {
             super(looper);
@@ -202,13 +255,34 @@
         @Override
         public void handleMessage(Message msg) {
             switch (msg.what) {
+                case MSG_SET_SERVICE:
+                    mService = (IQSService) msg.obj;
+                    if (mTile != null) {
+                        mTile.setService(mService);
+                    }
+                    break;
                 case MSG_SET_TILE:
                     mTile = (Tile) msg.obj;
+                    if (mService != null && mTile != null) {
+                        mTile.setService(mService);
+                    }
                     break;
                 case MSG_TILE_ADDED:
-                    TileService.this.onTileAdded();
+                    int mode = TileService.this.onTileAdded();
+                    if (mService == null) {
+                        return;
+                    }
+                    try {
+                        mService.setTileMode(new ComponentName(TileService.this,
+                                TileService.this.getClass()), mode);
+                    } catch (RemoteException e) {
+                    }
                     break;
                 case MSG_TILE_REMOVED:
+                    if (mListening) {
+                        mListening = false;
+                        TileService.this.onStopListening();
+                    }
                     TileService.this.onTileRemoved();
                     break;
                 case MSG_STOP_LISTENING:
@@ -230,4 +304,16 @@
             }
         }
     }
+
+    /**
+     * Requests that a tile be put in the listening state so it can send an update.
+     *
+     * This method is only applicable to tiles that return {@link #TILE_MODE_ACTIVE} from
+     * {@link #onTileAdded()}, and will do nothing otherwise.
+     */
+    public static final void requestListeningState(Context context, ComponentName component) {
+        Intent intent = new Intent(ACTION_REQUEST_LISTENING);
+        intent.putExtra(EXTRA_COMPONENT, component);
+        context.sendBroadcast(intent, Manifest.permission.BIND_QUICK_SETTINGS_TILE);
+    }
 }
diff --git a/core/java/android/text/Editable.java b/core/java/android/text/Editable.java
index a284a00..b3f2c2a 100644
--- a/core/java/android/text/Editable.java
+++ b/core/java/android/text/Editable.java
@@ -40,10 +40,14 @@
      * is Spanned, the spans from it are preserved into the Editable.
      * Existing spans within the Editable that entirely cover the replaced
      * range are retained, but any that were strictly within the range
-     * that was replaced are removed.  As a special case, the cursor
-     * position is preserved even when the entire range where it is
-     * located is replaced.
+     * that was replaced are removed. If the <code>source</code> contains a span
+     * with {@link Spanned#SPAN_PARAGRAPH} flag, and it does not satisfy the
+     * paragraph boundary constraint, it is not retained. As a special case, the
+     * cursor position is preserved even when the entire range where it is located
+     * is replaced.
      * @return  a reference to this object.
+     *
+     * @see Spanned#SPAN_PARAGRAPH
      */
     public Editable replace(int st, int en, CharSequence source, int start, int end);
 
diff --git a/core/java/android/text/SpannableStringBuilder.java b/core/java/android/text/SpannableStringBuilder.java
index 40315ad..4267238 100644
--- a/core/java/android/text/SpannableStringBuilder.java
+++ b/core/java/android/text/SpannableStringBuilder.java
@@ -421,8 +421,17 @@
 
                 // Add span only if this object is not yet used as a span in this string
                 if (getSpanStart(spans[i]) < 0) {
-                    setSpan(false, spans[i], st - csStart + start, en - csStart + start,
-                            sp.getSpanFlags(spans[i]) | SPAN_ADDED);
+                    int copySpanStart = st - csStart + start;
+                    int copySpanEnd = en - csStart + start;
+                    int copySpanFlags = sp.getSpanFlags(spans[i]) | SPAN_ADDED;
+
+                    int flagsStart = (copySpanFlags & START_MASK) >> START_SHIFT;
+                    int flagsEnd = copySpanFlags & END_MASK;
+
+                    if(!isInvalidParagraphStart(copySpanStart, flagsStart) &&
+                            !isInvalidParagraphEnd(copySpanEnd, flagsEnd)) {
+                        setSpan(false, spans[i], copySpanStart, copySpanEnd, copySpanFlags);
+                    }
                 }
             }
             restoreInvariants();
@@ -666,23 +675,13 @@
         checkRange("setSpan", start, end);
 
         int flagsStart = (flags & START_MASK) >> START_SHIFT;
-        if (flagsStart == PARAGRAPH) {
-            if (start != 0 && start != length()) {
-                char c = charAt(start - 1);
-
-                if (c != '\n')
-                    throw new RuntimeException("PARAGRAPH span must start at paragraph boundary");
-            }
+        if(isInvalidParagraphStart(start, flagsStart)) {
+            throw new RuntimeException("PARAGRAPH span must start at paragraph boundary");
         }
 
         int flagsEnd = flags & END_MASK;
-        if (flagsEnd == PARAGRAPH) {
-            if (end != 0 && end != length()) {
-                char c = charAt(end - 1);
-
-                if (c != '\n')
-                    throw new RuntimeException("PARAGRAPH span must end at paragraph boundary");
-            }
+        if(isInvalidParagraphEnd(end, flagsEnd)) {
+            throw new RuntimeException("PARAGRAPH span must end at paragraph boundary");
         }
 
         // 0-length Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
@@ -761,6 +760,28 @@
         }
     }
 
+    private final boolean isInvalidParagraphStart(int start, int flagsStart) {
+        if (flagsStart == PARAGRAPH) {
+            if (start != 0 && start != length()) {
+                char c = charAt(start - 1);
+
+                if (c != '\n') return true;
+            }
+        }
+        return false;
+    }
+
+    private final boolean isInvalidParagraphEnd(int end, int flagsEnd) {
+        if (flagsEnd == PARAGRAPH) {
+            if (end != 0 && end != length()) {
+                char c = charAt(end - 1);
+
+                if (c != '\n') return true;
+            }
+        }
+        return false;
+    }
+
     /**
      * Remove the specified markup object from the buffer.
      */
diff --git a/core/java/android/text/Spanned.java b/core/java/android/text/Spanned.java
index a785d1b..a0d54c2 100644
--- a/core/java/android/text/Spanned.java
+++ b/core/java/android/text/Spanned.java
@@ -81,7 +81,9 @@
      * immediately after a \n character, and if the \n
      * that anchors it is deleted, the endpoint is pulled to the
      * next \n that follows in the buffer (or to the end of
-     * the buffer).
+     * the buffer). If a span with SPAN_PARAGRAPH flag is pasted
+     * into another text and the paragraph boundary constraint
+     * is not satisfied, the span is discarded.
      */
     public static final int SPAN_PARAGRAPH =   0x33;
 
diff --git a/core/java/android/text/method/Touch.java b/core/java/android/text/method/Touch.java
index d9068dc..44811cb 100644
--- a/core/java/android/text/method/Touch.java
+++ b/core/java/android/text/method/Touch.java
@@ -150,6 +150,7 @@
                     ds[0].mX = event.getX();
                     ds[0].mY = event.getY();
 
+                    int nx = widget.getScrollX() + (int) dx;
                     int ny = widget.getScrollY() + (int) dy;
 
                     int padding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
@@ -161,6 +162,8 @@
                     int oldX = widget.getScrollX();
                     int oldY = widget.getScrollY();
 
+                    scrollTo(widget, layout, nx, ny);
+
                     // If we actually scrolled, then cancel the up action.
                     if (oldX != widget.getScrollX() || oldY != widget.getScrollY()) {
                         widget.cancelLongPress();
diff --git a/core/java/android/text/util/Linkify.java b/core/java/android/text/util/Linkify.java
index c119277..fbd9924 100644
--- a/core/java/android/text/util/Linkify.java
+++ b/core/java/android/text/util/Linkify.java
@@ -218,7 +218,7 @@
         ArrayList<LinkSpec> links = new ArrayList<LinkSpec>();
 
         if ((mask & WEB_URLS) != 0) {
-            gatherLinks(links, text, Patterns.WEB_URL,
+            gatherLinks(links, text, Patterns.AUTOLINK_WEB_URL,
                 new String[] { "http://", "https://", "rtsp://" },
                 sUrlMatchFilter, null);
         }
diff --git a/core/java/android/util/LocaleList.java b/core/java/android/util/LocaleList.java
index 1becfb4..f22cde0 100644
--- a/core/java/android/util/LocaleList.java
+++ b/core/java/android/util/LocaleList.java
@@ -28,12 +28,6 @@
 import java.util.HashSet;
 import java.util.Locale;
 
-// TODO: We don't except too many LocaleLists to exist at the same time, and
-// we need access to the data at native level, so we should pass the data
-// down to the native level, create a map of every list seen there, take a
-// pointer back, and just keep that pointer in the Java-level object, so
-// things could be copied very quickly.
-
 /**
  * LocaleList is an immutable list of Locales, typically used to keep an
  * ordered user preferences for locales.
@@ -219,6 +213,20 @@
         }
     }
 
+    private static final String STRING_EN_XA = "en-XA";
+    private static final String STRING_AR_XB = "ar-XB";
+    private static final Locale LOCALE_EN_XA = new Locale("en", "XA");
+    private static final Locale LOCALE_AR_XB = new Locale("ar", "XB");
+    private static final int NUM_PSEUDO_LOCALES = 2;
+
+    private static boolean isPseudoLocale(String locale) {
+        return STRING_EN_XA.equals(locale) || STRING_AR_XB.equals(locale);
+    }
+
+    private static boolean isPseudoLocale(Locale locale) {
+        return LOCALE_EN_XA.equals(locale) || LOCALE_AR_XB.equals(locale);
+    }
+
     private static int matchScore(Locale supported, Locale desired) {
         if (supported.equals(desired)) {
             return 1;  // return early so we don't do unnecessary computation
@@ -226,6 +234,11 @@
         if (!supported.getLanguage().equals(desired.getLanguage())) {
             return 0;
         }
+        if (isPseudoLocale(supported) || isPseudoLocale(desired)) {
+            // The locales are not the same, but the languages are the same, and one of the locales
+            // is a pseudo-locale. So this is not a match.
+            return 0;
+        }
         // There is no match if the two locales use different scripts. This will most imporantly
         // take care of traditional vs simplified Chinese.
         final String supportedScr = getLikelyScript(supported);
@@ -233,24 +246,26 @@
         return supportedScr.equals(desiredScr) ? 1 : 0;
     }
 
-    /**
-     * Returns the first match in the locale list given an unordered array of supported locales
-     * in BCP47 format.
-     *
-     * If the locale list is empty, null would be returned.
-     */
-    @Nullable
-    public Locale getFirstMatch(String[] supportedLocales) {
+    private static final Locale EN_LATN = Locale.forLanguageTag("en-Latn");
+
+    private Locale computeFirstMatch(String[] supportedLocales, boolean assumeEnglishIsSupported) {
         if (mList.length == 1) {  // just one locale, perhaps the most common scenario
             return mList[0];
         }
         if (mList.length == 0) {  // empty locale list
             return null;
         }
-        // TODO: Figure out what to if en-XA or ar-XB are in the locale list
         int bestIndex = Integer.MAX_VALUE;
-        for (String tag : supportedLocales) {
-            final Locale supportedLocale = Locale.forLanguageTag(tag);
+        final int numSupportedLocales =
+                supportedLocales.length + (assumeEnglishIsSupported ? 1 : 0);
+        for (int i = 0; i < numSupportedLocales; i++) {
+            final Locale supportedLocale;
+            if (assumeEnglishIsSupported) {
+                // Try English first, so we can return early if it's in the LocaleList
+                supportedLocale = (i == 0) ? EN_LATN : Locale.forLanguageTag(supportedLocales[i-1]);
+            } else {
+                supportedLocale = Locale.forLanguageTag(supportedLocales[i]);
+            }
             // We expect the average length of locale lists used for locale resolution to be
             // smaller than three, so it's OK to do this as an O(mn) algorithm.
             for (int idx = 0; idx < mList.length; idx++) {
@@ -271,6 +286,47 @@
         }
     }
 
+    /**
+     * Returns the first match in the locale list given an unordered array of supported locales
+     * in BCP47 format.
+     *
+     * If the locale list is empty, null would be returned.
+     */
+    @Nullable
+    public Locale getFirstMatch(String[] supportedLocales) {
+        return computeFirstMatch(supportedLocales, false /* assume English is not supported */);
+    }
+
+    /**
+     * Same as getFirstMatch(), but with English assumed to be supported, even if it's not.
+     * {@hide}
+     */
+    @Nullable
+    public Locale getFirstMatchWithEnglishSupported(String[] supportedLocales) {
+        return computeFirstMatch(supportedLocales, true /* assume English is supported */);
+    }
+
+    /**
+     * Returns true if the array of locale tags only contains empty locales and pseudolocales.
+     * Assumes that there is no repetition in the input.
+     * {@hide}
+     */
+    public static boolean isPseudoLocalesOnly(String[] supportedLocales) {
+        if (supportedLocales.length > NUM_PSEUDO_LOCALES + 1) {
+            // This is for optimization. Since there's no repetition in the input, if we have more
+            // than the number of pseudo-locales plus one for the empty string, it's guaranteed
+            // that we have some meaninful locale in the list, so the list is not "practically
+            // empty".
+            return false;
+        }
+        for (String locale : supportedLocales) {
+            if (!locale.isEmpty() && !isPseudoLocale(locale)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     private final static Object sLock = new Object();
 
     @GuardedBy("sLock")
diff --git a/core/java/android/util/Patterns.java b/core/java/android/util/Patterns.java
index 2cc91b9..9f2bcfd 100644
--- a/core/java/android/util/Patterns.java
+++ b/core/java/android/util/Patterns.java
@@ -109,11 +109,137 @@
         + "|z[amw]))";
 
     /**
-     * Good characters for Internationalized Resource Identifiers (IRI).
-     * This comprises most common used Unicode characters allowed in IRI
-     * as detailed in RFC 3987.
-     * Specifically, those two byte Unicode characters are not included.
+     *  Regular expression to match all IANA top-level domains.
+     *
+     *  List accurate as of 2015/11/24.  List taken from:
+     *  http://data.iana.org/TLD/tlds-alpha-by-domain.txt
+     *  This pattern is auto-generated by frameworks/ex/common/tools/make-iana-tld-pattern.py
+     *
+     *  @hide
      */
+    static final String IANA_TOP_LEVEL_DOMAINS =
+        "(?:"
+        + "(?:aaa|aarp|abb|abbott|abogado|academy|accenture|accountant|accountants|aco|active"
+        + "|actor|ads|adult|aeg|aero|afl|agency|aig|airforce|airtel|allfinanz|alsace|amica|amsterdam"
+        + "|android|apartments|app|apple|aquarelle|aramco|archi|army|arpa|arte|asia|associates"
+        + "|attorney|auction|audio|auto|autos|axa|azure|a[cdefgilmoqrstuwxz])"
+        + "|(?:band|bank|bar|barcelona|barclaycard|barclays|bargains|bauhaus|bayern|bbc|bbva"
+        + "|bcn|beats|beer|bentley|berlin|best|bet|bharti|bible|bid|bike|bing|bingo|bio|biz|black"
+        + "|blackfriday|bloomberg|blue|bms|bmw|bnl|bnpparibas|boats|bom|bond|boo|boots|boutique"
+        + "|bradesco|bridgestone|broadway|broker|brother|brussels|budapest|build|builders|business"
+        + "|buzz|bzh|b[abdefghijmnorstvwyz])"
+        + "|(?:cab|cafe|cal|camera|camp|cancerresearch|canon|capetown|capital|car|caravan|cards"
+        + "|care|career|careers|cars|cartier|casa|cash|casino|cat|catering|cba|cbn|ceb|center|ceo"
+        + "|cern|cfa|cfd|chanel|channel|chat|cheap|chloe|christmas|chrome|church|cipriani|cisco"
+        + "|citic|city|cityeats|claims|cleaning|click|clinic|clothing|cloud|club|clubmed|coach"
+        + "|codes|coffee|college|cologne|com|commbank|community|company|computer|comsec|condos"
+        + "|construction|consulting|contractors|cooking|cool|coop|corsica|country|coupons|courses"
+        + "|credit|creditcard|creditunion|cricket|crown|crs|cruises|csc|cuisinella|cymru|cyou|c[acdfghiklmnoruvwxyz])"
+        + "|(?:dabur|dad|dance|date|dating|datsun|day|dclk|deals|degree|delivery|dell|delta"
+        + "|democrat|dental|dentist|desi|design|dev|diamonds|diet|digital|direct|directory|discount"
+        + "|dnp|docs|dog|doha|domains|doosan|download|drive|durban|dvag|d[ejkmoz])"
+        + "|(?:earth|eat|edu|education|email|emerck|energy|engineer|engineering|enterprises"
+        + "|epson|equipment|erni|esq|estate|eurovision|eus|events|everbank|exchange|expert|exposed"
+        + "|express|e[cegrstu])"
+        + "|(?:fage|fail|fairwinds|faith|family|fan|fans|farm|fashion|feedback|ferrero|film"
+        + "|final|finance|financial|firmdale|fish|fishing|fit|fitness|flights|florist|flowers|flsmidth"
+        + "|fly|foo|football|forex|forsale|forum|foundation|frl|frogans|fund|furniture|futbol|fyi"
+        + "|f[ijkmor])"
+        + "|(?:gal|gallery|game|garden|gbiz|gdn|gea|gent|genting|ggee|gift|gifts|gives|giving"
+        + "|glass|gle|global|globo|gmail|gmo|gmx|gold|goldpoint|golf|goo|goog|google|gop|gov|grainger"
+        + "|graphics|gratis|green|gripe|group|gucci|guge|guide|guitars|guru|g[abdefghilmnpqrstuwy])"
+        + "|(?:hamburg|hangout|haus|healthcare|help|here|hermes|hiphop|hitachi|hiv|hockey|holdings"
+        + "|holiday|homedepot|homes|honda|horse|host|hosting|hoteles|hotmail|house|how|hsbc|hyundai"
+        + "|h[kmnrtu])"
+        + "|(?:ibm|icbc|ice|icu|ifm|iinet|immo|immobilien|industries|infiniti|info|ing|ink|institute"
+        + "|insure|int|international|investments|ipiranga|irish|ist|istanbul|itau|iwc|i[delmnoqrst])"
+        + "|(?:jaguar|java|jcb|jetzt|jewelry|jlc|jll|jobs|joburg|jprs|juegos|j[emop])"
+        + "|(?:kaufen|kddi|kia|kim|kinder|kitchen|kiwi|koeln|komatsu|krd|kred|kyoto|k[eghimnprwyz])"
+        + "|(?:lacaixa|lancaster|land|landrover|lasalle|lat|latrobe|law|lawyer|lds|lease|leclerc"
+        + "|legal|lexus|lgbt|liaison|lidl|life|lifestyle|lighting|limited|limo|linde|link|live"
+        + "|lixil|loan|loans|lol|london|lotte|lotto|love|ltd|ltda|lupin|luxe|luxury|l[abcikrstuvy])"
+        + "|(?:madrid|maif|maison|man|management|mango|market|marketing|markets|marriott|mba"
+        + "|media|meet|melbourne|meme|memorial|men|menu|meo|miami|microsoft|mil|mini|mma|mobi|moda"
+        + "|moe|moi|mom|monash|money|montblanc|mormon|mortgage|moscow|motorcycles|mov|movie|movistar"
+        + "|mtn|mtpc|mtr|museum|mutuelle|m[acdeghklmnopqrstuvwxyz])"
+        + "|(?:nadex|nagoya|name|navy|nec|net|netbank|network|neustar|new|news|nexus|ngo|nhk"
+        + "|nico|ninja|nissan|nokia|nra|nrw|ntt|nyc|n[acefgilopruz])"
+        + "|(?:obi|office|okinawa|omega|one|ong|onl|online|ooo|oracle|orange|org|organic|osaka"
+        + "|otsuka|ovh|om)"
+        + "|(?:page|panerai|paris|partners|parts|party|pet|pharmacy|philips|photo|photography"
+        + "|photos|physio|piaget|pics|pictet|pictures|ping|pink|pizza|place|play|playstation|plumbing"
+        + "|plus|pohl|poker|porn|post|praxi|press|pro|prod|productions|prof|properties|property"
+        + "|protection|pub|p[aefghklmnrstwy])"
+        + "|(?:qpon|quebec|qa)"
+        + "|(?:racing|realtor|realty|recipes|red|redstone|rehab|reise|reisen|reit|ren|rent|rentals"
+        + "|repair|report|republican|rest|restaurant|review|reviews|rich|ricoh|rio|rip|rocher|rocks"
+        + "|rodeo|rsvp|ruhr|run|rwe|ryukyu|r[eosuw])"
+        + "|(?:saarland|sakura|sale|samsung|sandvik|sandvikcoromant|sanofi|sap|sapo|sarl|saxo"
+        + "|sbs|sca|scb|schmidt|scholarships|school|schule|schwarz|science|scor|scot|seat|security"
+        + "|seek|sener|services|seven|sew|sex|sexy|shiksha|shoes|show|shriram|singles|site|ski"
+        + "|sky|skype|sncf|soccer|social|software|sohu|solar|solutions|sony|soy|space|spiegel|spreadbetting"
+        + "|srl|stada|starhub|statoil|stc|stcgroup|stockholm|studio|study|style|sucks|supplies"
+        + "|supply|support|surf|surgery|suzuki|swatch|swiss|sydney|systems|s[abcdeghijklmnortuvxyz])"
+        + "|(?:tab|taipei|tatamotors|tatar|tattoo|tax|taxi|team|tech|technology|tel|telefonica"
+        + "|temasek|tennis|thd|theater|theatre|tickets|tienda|tips|tires|tirol|today|tokyo|tools"
+        + "|top|toray|toshiba|tours|town|toyota|toys|trade|trading|training|travel|trust|tui|t[cdfghjklmnortvwz])"
+        + "|(?:ubs|university|uno|uol|u[agksyz])"
+        + "|(?:vacations|vana|vegas|ventures|versicherung|vet|viajes|video|villas|vin|virgin"
+        + "|vision|vista|vistaprint|viva|vlaanderen|vodka|vote|voting|voto|voyage|v[aceginu])"
+        + "|(?:wales|walter|wang|watch|webcam|website|wed|wedding|weir|whoswho|wien|wiki|williamhill"
+        + "|win|windows|wine|wme|work|works|world|wtc|wtf|w[fs])"
+        + "|(?:\u03b5\u03bb|\u0431\u0435\u043b|\u0434\u0435\u0442\u0438|\u043a\u043e\u043c|\u043c\u043a\u0434"
+        + "|\u043c\u043e\u043d|\u043c\u043e\u0441\u043a\u0432\u0430|\u043e\u043d\u043b\u0430\u0439\u043d"
+        + "|\u043e\u0440\u0433|\u0440\u0443\u0441|\u0440\u0444|\u0441\u0430\u0439\u0442|\u0441\u0440\u0431"
+        + "|\u0443\u043a\u0440|\u049b\u0430\u0437|\u0570\u0561\u0575|\u05e7\u05d5\u05dd|\u0627\u0631\u0627\u0645\u0643\u0648"
+        + "|\u0627\u0644\u0627\u0631\u062f\u0646|\u0627\u0644\u062c\u0632\u0627\u0626\u0631|\u0627\u0644\u0633\u0639\u0648\u062f\u064a\u0629"
+        + "|\u0627\u0644\u0645\u063a\u0631\u0628|\u0627\u0645\u0627\u0631\u0627\u062a|\u0627\u06cc\u0631\u0627\u0646"
+        + "|\u0628\u0627\u0632\u0627\u0631|\u0628\u06be\u0627\u0631\u062a|\u062a\u0648\u0646\u0633"
+        + "|\u0633\u0648\u062f\u0627\u0646|\u0633\u0648\u0631\u064a\u0629|\u0634\u0628\u0643\u0629"
+        + "|\u0639\u0631\u0627\u0642|\u0639\u0645\u0627\u0646|\u0641\u0644\u0633\u0637\u064a\u0646"
+        + "|\u0642\u0637\u0631|\u0643\u0648\u0645|\u0645\u0635\u0631|\u0645\u0644\u064a\u0633\u064a\u0627"
+        + "|\u0645\u0648\u0642\u0639|\u0915\u0949\u092e|\u0928\u0947\u091f|\u092d\u093e\u0930\u0924"
+        + "|\u0938\u0902\u0917\u0920\u0928|\u09ad\u09be\u09b0\u09a4|\u0a2d\u0a3e\u0a30\u0a24|\u0aad\u0abe\u0ab0\u0aa4"
+        + "|\u0b87\u0ba8\u0bcd\u0ba4\u0bbf\u0baf\u0bbe|\u0b87\u0bb2\u0b99\u0bcd\u0b95\u0bc8|\u0b9a\u0bbf\u0b99\u0bcd\u0b95\u0baa\u0bcd\u0baa\u0bc2\u0bb0\u0bcd"
+        + "|\u0c2d\u0c3e\u0c30\u0c24\u0c4d|\u0dbd\u0d82\u0d9a\u0dcf|\u0e04\u0e2d\u0e21|\u0e44\u0e17\u0e22"
+        + "|\u10d2\u10d4|\u307f\u3093\u306a|\u30b0\u30fc\u30b0\u30eb|\u30b3\u30e0|\u4e16\u754c"
+        + "|\u4e2d\u4fe1|\u4e2d\u56fd|\u4e2d\u570b|\u4e2d\u6587\u7f51|\u4f01\u4e1a|\u4f5b\u5c71"
+        + "|\u4fe1\u606f|\u5065\u5eb7|\u516b\u5366|\u516c\u53f8|\u516c\u76ca|\u53f0\u6e7e|\u53f0\u7063"
+        + "|\u5546\u57ce|\u5546\u5e97|\u5546\u6807|\u5728\u7ebf|\u5927\u62ff|\u5a31\u4e50|\u5de5\u884c"
+        + "|\u5e7f\u4e1c|\u6148\u5584|\u6211\u7231\u4f60|\u624b\u673a|\u653f\u52a1|\u653f\u5e9c"
+        + "|\u65b0\u52a0\u5761|\u65b0\u95fb|\u65f6\u5c1a|\u673a\u6784|\u6de1\u9a6c\u9521|\u6e38\u620f"
+        + "|\u70b9\u770b|\u79fb\u52a8|\u7ec4\u7ec7\u673a\u6784|\u7f51\u5740|\u7f51\u5e97|\u7f51\u7edc"
+        + "|\u8c37\u6b4c|\u96c6\u56e2|\u98de\u5229\u6d66|\u9910\u5385|\u9999\u6e2f|\ub2f7\ub137"
+        + "|\ub2f7\ucef4|\uc0bc\uc131|\ud55c\uad6d|xbox"
+        + "|xerox|xin|xn\\-\\-11b4c3d|xn\\-\\-1qqw23a|xn\\-\\-30rr7y|xn\\-\\-3bst00m|xn\\-\\-3ds443g"
+        + "|xn\\-\\-3e0b707e|xn\\-\\-3pxu8k|xn\\-\\-42c2d9a|xn\\-\\-45brj9c|xn\\-\\-45q11c|xn\\-\\-4gbrim"
+        + "|xn\\-\\-55qw42g|xn\\-\\-55qx5d|xn\\-\\-6frz82g|xn\\-\\-6qq986b3xl|xn\\-\\-80adxhks"
+        + "|xn\\-\\-80ao21a|xn\\-\\-80asehdb|xn\\-\\-80aswg|xn\\-\\-90a3ac|xn\\-\\-90ais|xn\\-\\-9dbq2a"
+        + "|xn\\-\\-9et52u|xn\\-\\-b4w605ferd|xn\\-\\-c1avg|xn\\-\\-c2br7g|xn\\-\\-cg4bki|xn\\-\\-clchc0ea0b2g2a9gcd"
+        + "|xn\\-\\-czr694b|xn\\-\\-czrs0t|xn\\-\\-czru2d|xn\\-\\-d1acj3b|xn\\-\\-d1alf|xn\\-\\-efvy88h"
+        + "|xn\\-\\-estv75g|xn\\-\\-fhbei|xn\\-\\-fiq228c5hs|xn\\-\\-fiq64b|xn\\-\\-fiqs8s|xn\\-\\-fiqz9s"
+        + "|xn\\-\\-fjq720a|xn\\-\\-flw351e|xn\\-\\-fpcrj9c3d|xn\\-\\-fzc2c9e2c|xn\\-\\-gecrj9c"
+        + "|xn\\-\\-h2brj9c|xn\\-\\-hxt814e|xn\\-\\-i1b6b1a6a2e|xn\\-\\-imr513n|xn\\-\\-io0a7i"
+        + "|xn\\-\\-j1aef|xn\\-\\-j1amh|xn\\-\\-j6w193g|xn\\-\\-kcrx77d1x4a|xn\\-\\-kprw13d|xn\\-\\-kpry57d"
+        + "|xn\\-\\-kput3i|xn\\-\\-l1acc|xn\\-\\-lgbbat1ad8j|xn\\-\\-mgb9awbf|xn\\-\\-mgba3a3ejt"
+        + "|xn\\-\\-mgba3a4f16a|xn\\-\\-mgbaam7a8h|xn\\-\\-mgbab2bd|xn\\-\\-mgbayh7gpa|xn\\-\\-mgbbh1a71e"
+        + "|xn\\-\\-mgbc0a9azcg|xn\\-\\-mgberp4a5d4ar|xn\\-\\-mgbpl2fh|xn\\-\\-mgbtx2b|xn\\-\\-mgbx4cd0ab"
+        + "|xn\\-\\-mk1bu44c|xn\\-\\-mxtq1m|xn\\-\\-ngbc5azd|xn\\-\\-node|xn\\-\\-nqv7f|xn\\-\\-nqv7fs00ema"
+        + "|xn\\-\\-nyqy26a|xn\\-\\-o3cw4h|xn\\-\\-ogbpf8fl|xn\\-\\-p1acf|xn\\-\\-p1ai|xn\\-\\-pgbs0dh"
+        + "|xn\\-\\-pssy2u|xn\\-\\-q9jyb4c|xn\\-\\-qcka1pmc|xn\\-\\-qxam|xn\\-\\-rhqv96g|xn\\-\\-s9brj9c"
+        + "|xn\\-\\-ses554g|xn\\-\\-t60b56a|xn\\-\\-tckwe|xn\\-\\-unup4y|xn\\-\\-vermgensberater\\-ctb"
+        + "|xn\\-\\-vermgensberatung\\-pwb|xn\\-\\-vhquv|xn\\-\\-vuq861b|xn\\-\\-wgbh1c|xn\\-\\-wgbl6a"
+        + "|xn\\-\\-xhq521b|xn\\-\\-xkc2al3hye2a|xn\\-\\-xkc2dl3a5ee0h|xn\\-\\-y9a3aq|xn\\-\\-yfro4i67o"
+        + "|xn\\-\\-ygbi2ammx|xn\\-\\-zfr164b|xperia|xxx|xyz)"
+        + "|(?:yachts|yamaxun|yandex|yodobashi|yoga|yokohama|youtube|y[et])"
+        + "|(?:zara|zip|zone|zuerich|z[amw]))";
+
+    /**
+     * Kept for backward compatibility reasons.
+     *
+     * @deprecated Deprecated since it does not include all IRI characters defined in RFC 3987
+     */
+    @Deprecated
     public static final String GOOD_IRI_CHAR =
         "a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF";
 
@@ -125,35 +251,148 @@
             + "|[1-9][0-9]|[0-9]))");
 
     /**
+     * Valid UCS characters defined in RFC 3987.
+     */
+    private static final String UCS_CHAR =
+            "\u00A0-\uD7FF" +
+            "\uF900-\uFDCF" +
+            "\uFDF0-\uFFEF" +
+            "\uD800\uDC00-\uD83F\uDFFD" +
+            "\uD840\uDC00-\uD87F\uDFFD" +
+            "\uD880\uDC00-\uD8BF\uDFFD" +
+            "\uD8C0\uDC00-\uD8FF\uDFFD" +
+            "\uD900\uDC00-\uD93F\uDFFD" +
+            "\uD940\uDC00-\uD97F\uDFFD" +
+            "\uD980\uDC00-\uD9BF\uDFFD" +
+            "\uD9C0\uDC00-\uD9FF\uDFFD" +
+            "\uDA00\uDC00-\uDA3F\uDFFD" +
+            "\uDA40\uDC00-\uDA7F\uDFFD" +
+            "\uDA80\uDC00-\uDABF\uDFFD" +
+            "\uDAC0\uDC00-\uDAFF\uDFFD" +
+            "\uDB00\uDC00-\uDB3F\uDFFD" +
+            "\uDB44\uDC00-\uDB7F\uDFFD";
+
+    /**
+     * Valid characters for IRI label defined in RFC 3987.
+     */
+    private static final String LABEL_CHAR = "a-zA-Z0-9" + UCS_CHAR;
+
+    /**
+     * Valid characters for IRI TLD defined in RFC 3987.
+     */
+    private static final String TLD_CHAR = "a-zA-Z" + UCS_CHAR;
+
+    /**
      * RFC 1035 Section 2.3.4 limits the labels to a maximum 63 octets.
      */
-    private static final String IRI
-        = "[" + GOOD_IRI_CHAR + "]([" + GOOD_IRI_CHAR + "\\-]{0,61}[" + GOOD_IRI_CHAR + "]){0,1}";
+    private static final String IRI_LABEL =
+            "[" + LABEL_CHAR + "](?:[" + LABEL_CHAR + "\\-]{0,61}[" + LABEL_CHAR + "]){0,1}";
 
-    private static final String GOOD_GTLD_CHAR =
-        "a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF";
-    private static final String GTLD = "[" + GOOD_GTLD_CHAR + "]{2,63}";
-    private static final String HOST_NAME = "(" + IRI + "\\.)+" + GTLD;
+    /**
+     * RFC 3492 references RFC 1034 and limits Punycode algorithm output to 63 characters.
+     */
+    private static final String PUNYCODE_TLD = "xn\\-\\-[\\w\\-]{0,58}\\w";
+
+    private static final String TLD = "(" + PUNYCODE_TLD + "|" + "[" + TLD_CHAR + "]{2,63}" +")";
+
+    private static final String HOST_NAME = "(" + IRI_LABEL + "\\.)+" + TLD;
 
     public static final Pattern DOMAIN_NAME
         = Pattern.compile("(" + HOST_NAME + "|" + IP_ADDRESS + ")");
 
+    private static final String PROTOCOL = "(?i:http|https|rtsp):\\/\\/";
+
+    /* A word boundary or end of input.  This is to stop foo.sure from matching as foo.su */
+    private static final String WORD_BOUNDARY = "(?:\\b|$|^)";
+
+    private static final String USER_INFO = "(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)"
+            + "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_"
+            + "\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@";
+
+    private static final String PORT_NUMBER = "\\:\\d{1,5}";
+
+    private static final String PATH_AND_QUERY = "\\/(?:(?:[" + LABEL_CHAR
+            + "\\;\\/\\?\\:\\@\\&\\=\\#\\~"  // plus optional query params
+            + "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*";
+
     /**
      *  Regular expression pattern to match most part of RFC 3987
-     *  Internationalized URLs, aka IRIs.  Commonly used Unicode characters are
-     *  added.
+     *  Internationalized URLs, aka IRIs.
      */
-    public static final Pattern WEB_URL = Pattern.compile(
-        "((?:(http|https|Http|Https|rtsp|Rtsp):\\/\\/(?:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)"
-        + "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_"
-        + "\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?"
-        + "(?:" + DOMAIN_NAME + ")"
-        + "(?:\\:\\d{1,5})?)" // plus option port number
-        + "(\\/(?:(?:[" + GOOD_IRI_CHAR + "\\;\\/\\?\\:\\@\\&\\=\\#\\~"  // plus option query params
-        + "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?"
-        + "(?:\\b|$)"); // and finally, a word boundary or end of
-                        // input.  This is to stop foo.sure from
-                        // matching as foo.su
+    public static final Pattern WEB_URL = Pattern.compile("("
+            + "("
+            + "(?:" + PROTOCOL + "(?:" + USER_INFO + ")?" + ")?"
+            + "(?:" + DOMAIN_NAME + ")"
+            + "(?:" + PORT_NUMBER + ")?"
+            + ")"
+            + "(" + PATH_AND_QUERY + ")?"
+            + WORD_BOUNDARY
+            + ")");
+
+    /**
+     * Regular expression that matches known TLDs and punycode TLDs
+     */
+    private static final String STRICT_TLD = "(?:" +
+            IANA_TOP_LEVEL_DOMAINS + "|" + PUNYCODE_TLD + ")";
+
+    /**
+     * Regular expression that matches host names using {@link #STRICT_TLD}
+     */
+    private static final String STRICT_HOST_NAME = "(?:(?:" + IRI_LABEL + "\\.)+"
+            + STRICT_TLD + ")";
+
+    /**
+     * Regular expression that matches domain names using either {@link #STRICT_HOST_NAME} or
+     * {@link #IP_ADDRESS}
+     */
+    private static final Pattern STRICT_DOMAIN_NAME
+            = Pattern.compile("(?:" + STRICT_HOST_NAME + "|" + IP_ADDRESS + ")");
+
+    /**
+     * Regular expression that matches domain names without a TLD
+     */
+    private static final String RELAXED_DOMAIN_NAME =
+            "(?:" + "(?:" + IRI_LABEL + "(?:\\.(?=\\S))" +"?)+" + "|" + IP_ADDRESS + ")";
+
+    /**
+     * Regular expression to match strings that do not start with a supported protocol. The TLDs
+     * are expected to be one of the known TLDs.
+     */
+    private static final String WEB_URL_WITHOUT_PROTOCOL = "("
+            + WORD_BOUNDARY
+            + "(?<!:\\/\\/)"
+            + "("
+            + "(?:" + STRICT_DOMAIN_NAME + ")"
+            + "(?:" + PORT_NUMBER + ")?"
+            + ")"
+            + "(?:" + PATH_AND_QUERY + ")?"
+            + WORD_BOUNDARY
+            + ")";
+
+    /**
+     * Regular expression to match strings that start with a supported protocol. Rules for domain
+     * names and TLDs are more relaxed. TLDs are optional.
+     */
+    private static final String WEB_URL_WITH_PROTOCOL = "("
+            + WORD_BOUNDARY
+            + "(?:"
+            + "(?:" + PROTOCOL + "(?:" + USER_INFO + ")?" + ")"
+            + "(?:" + RELAXED_DOMAIN_NAME + ")?"
+            + "(?:" + PORT_NUMBER + ")?"
+            + ")"
+            + "(?:" + PATH_AND_QUERY + ")?"
+            + WORD_BOUNDARY
+            + ")";
+
+    /**
+     * Regular expression pattern to match IRIs. If a string starts with http(s):// the expression
+     * tries to match the URL structure with a relaxed rule for TLDs. If the string does not start
+     * with http(s):// the TLDs are expected to be one of the known TLDs.
+     *
+     * @hide
+     */
+    public static final Pattern AUTOLINK_WEB_URL = Pattern.compile(
+            "(" + WEB_URL_WITH_PROTOCOL + "|" + WEB_URL_WITHOUT_PROTOCOL + ")");
 
     public static final Pattern EMAIL_ADDRESS
         = Pattern.compile(
diff --git a/core/java/android/view/IDockDividerVisibilityListener.aidl b/core/java/android/view/IDockedStackListener.aidl
similarity index 70%
rename from core/java/android/view/IDockDividerVisibilityListener.aidl
rename to core/java/android/view/IDockedStackListener.aidl
index a7d5cda..77fa7e2 100644
--- a/core/java/android/view/IDockDividerVisibilityListener.aidl
+++ b/core/java/android/view/IDockedStackListener.aidl
@@ -22,6 +22,15 @@
   *
   * @hide
   */
-oneway interface IDockDividerVisibilityListener {
-    void onDockDividerVisibilityChanged(boolean visible);
+oneway interface IDockedStackListener {
+
+    /**
+     * Will fire when an app is shown in side by side mode and a divider should be shown.
+     */
+    void onDividerVisibilityChanged(boolean visible);
+
+    /**
+     * Called when the docked stack gets created or removed.
+     */
+    void onDockedStackExistsChanged(boolean exists);
 }
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl
index 7a379d50..84d312d 100644
--- a/core/java/android/view/IWindowManager.aidl
+++ b/core/java/android/view/IWindowManager.aidl
@@ -29,7 +29,7 @@
 import android.os.IRemoteCallback;
 import android.view.IApplicationToken;
 import android.view.IAppTransitionAnimationSpecsFuture;
-import android.view.IDockDividerVisibilityListener;
+import android.view.IDockedStackListener;
 import android.view.IOnKeyguardExitResult;
 import android.view.IRotationWatcher;
 import android.view.IWindowSession;
@@ -101,11 +101,14 @@
      *                   the task doesn't exist yet.
      * @param configuration Configuration that is being used with this task.
      * @param cropWindowsToStack True if the app windows should be cropped to the stack bounds.
+     * @param alwaysFocusable True if the app windows are always focusable regardless of the stack
+     *                        they are in.
      */
     void addAppToken(int addPos, IApplicationToken token, int taskId, int stackId,
             int requestedOrientation, boolean fullscreen, boolean showWhenLocked, int userId,
             int configChanges, boolean voiceInteraction, boolean launchTaskBehind,
-            in Rect taskBounds, in Configuration configuration, boolean cropWindowsToStack);
+            in Rect taskBounds, in Configuration configuration, boolean cropWindowsToStack,
+            boolean alwaysFocusable);
     /**
      *
      * @param token The token we are adding to the input task Id.
@@ -354,7 +357,17 @@
     void setDockedStackResizing(boolean resizing);
 
     /**
-     * Registers a listener that will be called when the dock divider changes its visibility.
+     * Registers a listener that will be called when the dock divider changes its visibility or when
+     * the docked stack gets added/removed.
      */
-    void registerDockDividerVisibilityListener(IDockDividerVisibilityListener listener);
+    void registerDockedStackListener(IDockedStackListener listener);
+
+    /**
+     * Updates the dim layer used while resizing.
+     *
+     * @param visible Whether the dim layer should be visible.
+     * @param targetStackId The id of the task stack the dim layer should be placed on.
+     * @param alpha The translucency of the dim layer, between 0 and 1.
+     */
+    void setResizeDimLayer(boolean visible, int targetStackId, float alpha);
 }
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java
index 7a544b8..a0f5142 100644
--- a/core/java/android/view/MotionEvent.java
+++ b/core/java/android/view/MotionEvent.java
@@ -973,6 +973,7 @@
      * </p>
      *
      * @see #getAxisValue(int, int)
+     * {@hide}
      */
     public static final int AXIS_SCROLL = 26;
 
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java
index 6b60be9..1be4810 100644
--- a/core/java/android/view/TextureView.java
+++ b/core/java/android/view/TextureView.java
@@ -297,7 +297,7 @@
 
     @Override
     public void setForeground(Drawable foreground) {
-        if (foreground != null) {
+        if (foreground != null && !sTextureViewIgnoresDrawableSetters) {
             throw new UnsupportedOperationException(
                     "TextureView doesn't support displaying a foreground drawable");
         }
@@ -305,7 +305,7 @@
 
     @Override
     public void setBackgroundDrawable(Drawable background) {
-        if (background != null) {
+        if (background != null && !sTextureViewIgnoresDrawableSetters) {
             throw new UnsupportedOperationException(
                     "TextureView doesn't support displaying a background drawable");
         }
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 537f887..68f1ac3 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -812,6 +812,12 @@
     private static boolean sLayoutParamsAlwaysChanged = false;
 
     /**
+     * Allow setForeground/setBackground to be called (and ignored) on a textureview,
+     * without throwing
+     */
+    static boolean sTextureViewIgnoresDrawableSetters = false;
+
+    /**
      * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when
      * calling setFlags.
      */
@@ -3586,6 +3592,9 @@
 
     private int[] mDrawableState = null;
 
+    /** Whether draw() is currently being called. */
+    private boolean mInDraw = false;
+
     ViewOutlineProvider mOutlineProvider = ViewOutlineProvider.BACKGROUND;
 
     /**
@@ -3984,6 +3993,10 @@
             // work. Partial layout breaks this assumption.
             sLayoutParamsAlwaysChanged = targetSdkVersion <= M;
 
+            // Prior to N, TextureView would silently ignore calls to setBackground/setForeground.
+            // On N+, we throw, but that breaks compatibility with apps that use these methods.
+            sTextureViewIgnoresDrawableSetters = targetSdkVersion <= M;
+
             sCompatibilityDone = true;
         }
     }
@@ -16460,6 +16473,8 @@
      */
     @CallSuper
     public void draw(Canvas canvas) {
+        mInDraw = true;
+
         final int privateFlags = mPrivateFlags;
         final boolean dirtyOpaque = (privateFlags & PFLAG_DIRTY_MASK) == PFLAG_DIRTY_OPAQUE &&
                 (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState);
@@ -16504,6 +16519,7 @@
             onDrawForeground(canvas);
 
             // we're done...
+            mInDraw = false;
             return;
         }
 
@@ -16651,6 +16667,8 @@
 
         // Step 6, draw decorations (foreground, scrollbars)
         onDrawForeground(canvas);
+
+        mInDraw = false;
     }
 
     /**
@@ -17095,7 +17113,8 @@
      */
     @Override
     public void invalidateDrawable(@NonNull Drawable drawable) {
-        if (verifyDrawable(drawable)) {
+        // Don't invalidate if a drawable changes during drawing.
+        if (verifyDrawable(drawable) && !mInDraw) {
             final Rect dirty = drawable.getDirtyBounds();
             final int scrollX = mScrollX;
             final int scrollY = mScrollY;
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index cd93dab..1c24392 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -1419,8 +1419,9 @@
 
         case DragEvent.ACTION_DRAG_ENDED: {
             // Release the bookkeeping now that the drag lifecycle has ended
-            if (mChildrenInterestedInDrag != null) {
-                for (View child : mChildrenInterestedInDrag) {
+            final HashSet<View> childrenInterestedInDrag = mChildrenInterestedInDrag;
+            if (childrenInterestedInDrag != null) {
+                for (View child : childrenInterestedInDrag) {
                     // If a child was interested in the ongoing drag, it's told that it's over
                     if (child.dispatchDragEvent(event)) {
                         retval = true;
@@ -1428,12 +1429,11 @@
                     child.mPrivateFlags2 &= ~View.DRAG_MASK;
                     child.refreshDrawableState();
                 }
-
-                mChildrenInterestedInDrag.clear();
-                if (mCurrentDragStartEvent != null) {
-                    mCurrentDragStartEvent.recycle();
-                    mCurrentDragStartEvent = null;
-                }
+                childrenInterestedInDrag.clear();
+            }
+            if (mCurrentDragStartEvent != null) {
+                mCurrentDragStartEvent.recycle();
+                mCurrentDragStartEvent = null;
             }
 
             if (mIsInterestedInDrag) {
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index f2b4fb3..0fb3951 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -384,6 +384,8 @@
         int localChanges;
     }
 
+    private String mTag = TAG;
+
     public ViewRootImpl(Context context, Display display) {
         mContext = context;
         mWindowSession = WindowManagerGlobal.getWindowSession();
@@ -510,6 +512,7 @@
                     mWindowAttributes.packageName = mBasePackageName;
                 }
                 attrs = mWindowAttributes;
+                setTag();
                 // Keep track of the actual window flags supplied by the client.
                 mClientWindowLayoutFlags = attrs.flags;
 
@@ -546,7 +549,7 @@
                     attrs.backup();
                     mTranslator.translateWindowLayout(attrs);
                 }
-                if (DEBUG_LAYOUT) Log.d(TAG, "WindowLayout in setView:" + attrs);
+                if (DEBUG_LAYOUT) Log.d(mTag, "WindowLayout in setView:" + attrs);
 
                 if (!compatibilityInfo.supportsScreen()) {
                     attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
@@ -607,7 +610,7 @@
                 mPendingContentInsets.set(mAttachInfo.mContentInsets);
                 mPendingStableInsets.set(mAttachInfo.mStableInsets);
                 mPendingVisibleInsets.set(0, 0, 0, 0);
-                if (DEBUG_LAYOUT) Log.v(TAG, "Added window " + mWindow);
+                if (DEBUG_LAYOUT) Log.v(mTag, "Added window " + mWindow);
                 if (res < WindowManagerGlobal.ADD_OKAY) {
                     mAttachInfo.mRootView = null;
                     mAdded = false;
@@ -701,6 +704,13 @@
         }
     }
 
+    private void setTag() {
+        final String[] split = mWindowAttributes.getTitle().toString().split("\\.");
+        if (split.length > 0) {
+            mTag = TAG + "[" + split[split.length - 1] + "]";
+        }
+    }
+
     /** Whether the window is in local focus mode or not */
     private boolean isInLocalFocusMode() {
         return (mWindowAttributes.flags & WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE) != 0;
@@ -990,7 +1000,7 @@
     @Override
     public ViewParent invalidateChildInParent(int[] location, Rect dirty) {
         checkThread();
-        if (DEBUG_DRAW) Log.v(TAG, "Invalidate child: " + dirty);
+        if (DEBUG_DRAW) Log.v(mTag, "Invalidate child: " + dirty);
 
         if (dirty == null) {
             invalidate();
@@ -1174,7 +1184,7 @@
 
     private boolean collectViewAttributes() {
         if (mAttachInfo.mRecomputeGlobalAttributes) {
-            //Log.i(TAG, "Computing view hierarchy attributes!");
+            //Log.i(mTag, "Computing view hierarchy attributes!");
             mAttachInfo.mRecomputeGlobalAttributes = false;
             boolean oldScreenOn = mAttachInfo.mKeepScreenOn;
             mAttachInfo.mKeepScreenOn = false;
@@ -1215,7 +1225,7 @@
         int childHeightMeasureSpec;
         boolean windowSizeMayChange = false;
 
-        if (DEBUG_ORIENTATION || DEBUG_LAYOUT) Log.v(TAG,
+        if (DEBUG_ORIENTATION || DEBUG_LAYOUT) Log.v(mTag,
                 "Measuring " + host + " in display " + desiredWindowWidth
                 + "x" + desiredWindowHeight + "...");
 
@@ -1231,26 +1241,26 @@
             if (mTmpValue.type == TypedValue.TYPE_DIMENSION) {
                 baseSize = (int)mTmpValue.getDimension(packageMetrics);
             }
-            if (DEBUG_DIALOG) Log.v(TAG, "Window " + mView + ": baseSize=" + baseSize);
+            if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": baseSize=" + baseSize);
             if (baseSize != 0 && desiredWindowWidth > baseSize) {
                 childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width);
                 childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height);
                 performMeasure(childWidthMeasureSpec, childHeightMeasureSpec);
-                if (DEBUG_DIALOG) Log.v(TAG, "Window " + mView + ": measured ("
+                if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured ("
                         + host.getMeasuredWidth() + "," + host.getMeasuredHeight() + ")");
                 if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) {
                     goodMeasure = true;
                 } else {
                     // Didn't fit in that size... try expanding a bit.
                     baseSize = (baseSize+desiredWindowWidth)/2;
-                    if (DEBUG_DIALOG) Log.v(TAG, "Window " + mView + ": next baseSize="
+                    if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": next baseSize="
                             + baseSize);
                     childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width);
                     performMeasure(childWidthMeasureSpec, childHeightMeasureSpec);
-                    if (DEBUG_DIALOG) Log.v(TAG, "Window " + mView + ": measured ("
+                    if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured ("
                             + host.getMeasuredWidth() + "," + host.getMeasuredHeight() + ")");
                     if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) {
-                        if (DEBUG_DIALOG) Log.v(TAG, "Good!");
+                        if (DEBUG_DIALOG) Log.v(mTag, "Good!");
                         goodMeasure = true;
                     }
                 }
@@ -1350,8 +1360,8 @@
         int desiredWindowHeight;
 
         final int viewVisibility = getHostVisibility();
-        boolean viewVisibilityChanged = mViewVisibility != viewVisibility
-                || mNewSurfaceNeeded;
+        final boolean viewVisibilityChanged = !mFirst
+                && (mViewVisibility != viewVisibility || mNewSurfaceNeeded);
 
         WindowManager.LayoutParams params = null;
         if (mWindowAttributesChanged) {
@@ -1401,7 +1411,6 @@
             mAttachInfo.mHasWindowFocus = false;
             mAttachInfo.mWindowVisibility = viewVisibility;
             mAttachInfo.mRecomputeGlobalAttributes = false;
-            viewVisibilityChanged = false;
             mLastConfiguration.setTo(host.getResources().getConfiguration());
             mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility;
             // Set the layout direction if it has not been set before (inherit is the default)
@@ -1411,14 +1420,13 @@
             host.dispatchAttachedToWindow(mAttachInfo, 0);
             mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(true);
             dispatchApplyInsets(host);
-            //Log.i(TAG, "Screen on initialized: " + attachInfo.mKeepScreenOn);
+            //Log.i(mTag, "Screen on initialized: " + attachInfo.mKeepScreenOn);
 
         } else {
             desiredWindowWidth = frame.width();
             desiredWindowHeight = frame.height();
             if (desiredWindowWidth != mWidth || desiredWindowHeight != mHeight) {
-                if (DEBUG_ORIENTATION) Log.v(TAG,
-                        "View " + host + " resized to: " + frame);
+                if (DEBUG_ORIENTATION) Log.v(mTag, "View " + host + " resized to: " + frame);
                 mFullRedrawNeeded = true;
                 mLayoutRequested = true;
                 windowSizeMayChange = true;
@@ -1471,28 +1479,22 @@
                 }
                 if (!mPendingVisibleInsets.equals(mAttachInfo.mVisibleInsets)) {
                     mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets);
-                    if (DEBUG_LAYOUT) Log.v(TAG, "Visible insets changing to: "
+                    if (DEBUG_LAYOUT) Log.v(mTag, "Visible insets changing to: "
                             + mAttachInfo.mVisibleInsets);
                 }
                 if (!mPendingOutsets.equals(mAttachInfo.mOutsets)) {
                     insetsChanged = true;
                 }
-                if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT
-                        || lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
+                if ((lp.width == ViewGroup.LayoutParams.WRAP_CONTENT
+                        || lp.height == ViewGroup.LayoutParams.WRAP_CONTENT)
+                        && (lp.type == WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL
+                                || lp.type == WindowManager.LayoutParams.TYPE_INPUT_METHOD)) {
                     windowSizeMayChange = true;
-
-                    if (lp.type == WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL
-                            || lp.type == WindowManager.LayoutParams.TYPE_INPUT_METHOD) {
-                        // NOTE -- system code, won't try to do compat mode.
-                        Point size = new Point();
-                        mDisplay.getRealSize(size);
-                        desiredWindowWidth = size.x;
-                        desiredWindowHeight = size.y;
-                    } else {
-                        DisplayMetrics packageMetrics = res.getDisplayMetrics();
-                        desiredWindowWidth = packageMetrics.widthPixels;
-                        desiredWindowHeight = packageMetrics.heightPixels;
-                    }
+                    // NOTE -- system code, won't try to do compat mode.
+                    Point size = new Point();
+                    mDisplay.getRealSize(size);
+                    desiredWindowWidth = size.x;
+                    desiredWindowHeight = size.y;
                 }
             }
 
@@ -1616,7 +1618,7 @@
 
             try {
                 if (DEBUG_LAYOUT) {
-                    Log.i(TAG, "host=w:" + host.getMeasuredWidth() + ", h:" +
+                    Log.i(mTag, "host=w:" + host.getMeasuredWidth() + ", h:" +
                             host.getMeasuredHeight() + ", params=" + params);
                 }
 
@@ -1634,7 +1636,7 @@
                 final int surfaceGenerationId = mSurface.getGenerationId();
                 relayoutResult = relayoutWindow(params, viewVisibility, insetsPending);
 
-                if (DEBUG_LAYOUT) Log.v(TAG, "relayout: frame=" + frame.toShortString()
+                if (DEBUG_LAYOUT) Log.v(mTag, "relayout: frame=" + frame.toShortString()
                         + " overscan=" + mPendingOverscanInsets.toShortString()
                         + " content=" + mPendingContentInsets.toShortString()
                         + " visible=" + mPendingVisibleInsets.toShortString()
@@ -1643,7 +1645,7 @@
                         + " surface=" + mSurface);
 
                 if (mPendingConfiguration.seq != 0) {
-                    if (DEBUG_CONFIGURATION) Log.v(TAG, "Visible with new config: "
+                    if (DEBUG_CONFIGURATION) Log.v(mTag, "Visible with new config: "
                             + mPendingConfiguration);
                     updateConfiguration(new Configuration(mPendingConfiguration), !mFirst);
                     mPendingConfiguration.seq = 0;
@@ -1662,19 +1664,19 @@
                         & WindowManagerGlobal.RELAYOUT_RES_SURFACE_RESIZED) != 0;
                 if (contentInsetsChanged) {
                     mAttachInfo.mContentInsets.set(mPendingContentInsets);
-                    if (DEBUG_LAYOUT) Log.v(TAG, "Content insets changing to: "
+                    if (DEBUG_LAYOUT) Log.v(mTag, "Content insets changing to: "
                             + mAttachInfo.mContentInsets);
                 }
                 if (overscanInsetsChanged) {
                     mAttachInfo.mOverscanInsets.set(mPendingOverscanInsets);
-                    if (DEBUG_LAYOUT) Log.v(TAG, "Overscan insets changing to: "
+                    if (DEBUG_LAYOUT) Log.v(mTag, "Overscan insets changing to: "
                             + mAttachInfo.mOverscanInsets);
                     // Need to relayout with content insets.
                     contentInsetsChanged = true;
                 }
                 if (stableInsetsChanged) {
                     mAttachInfo.mStableInsets.set(mPendingStableInsets);
-                    if (DEBUG_LAYOUT) Log.v(TAG, "Decor insets changing to: "
+                    if (DEBUG_LAYOUT) Log.v(mTag, "Decor insets changing to: "
                             + mAttachInfo.mStableInsets);
                     // Need to relayout with content insets.
                     contentInsetsChanged = true;
@@ -1691,7 +1693,7 @@
                 }
                 if (visibleInsetsChanged) {
                     mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets);
-                    if (DEBUG_LAYOUT) Log.v(TAG, "Visible insets changing to: "
+                    if (DEBUG_LAYOUT) Log.v(mTag, "Visible insets changing to: "
                             + mAttachInfo.mVisibleInsets);
                 }
 
@@ -1872,7 +1874,7 @@
                     int childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width);
                     int childHeightMeasureSpec = getRootMeasureSpec(mHeight, lp.height);
 
-                    if (DEBUG_LAYOUT) Log.v(TAG, "Ooops, something changed!  mWidth="
+                    if (DEBUG_LAYOUT) Log.v(mTag, "Ooops, something changed!  mWidth="
                             + mWidth + " measuredWidth=" + host.getMeasuredWidth()
                             + " mHeight=" + mHeight
                             + " measuredHeight=" + host.getMeasuredHeight()
@@ -1902,7 +1904,7 @@
                     }
 
                     if (measureAgain) {
-                        if (DEBUG_LAYOUT) Log.v(TAG,
+                        if (DEBUG_LAYOUT) Log.v(mTag,
                                 "And hey let's measure once more: width=" + width
                                 + " height=" + height);
                         performMeasure(childWidthMeasureSpec, childHeightMeasureSpec);
@@ -2024,15 +2026,15 @@
 
         if (mFirst) {
             // handle first focus request
-            if (DEBUG_INPUT_RESIZE) Log.v(TAG, "First: mView.hasFocus()="
+            if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: mView.hasFocus()="
                     + mView.hasFocus());
             if (mView != null) {
                 if (!mView.hasFocus()) {
                     mView.requestFocus(View.FOCUS_FORWARD);
-                    if (DEBUG_INPUT_RESIZE) Log.v(TAG, "First: requested focused view="
+                    if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: requested focused view="
                             + mView.findFocus());
                 } else {
-                    if (DEBUG_INPUT_RESIZE) Log.v(TAG, "First: existing focused view="
+                    if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: existing focused view="
                             + mView.findFocus());
                 }
             }
@@ -2104,11 +2106,11 @@
     }
 
     private void handleOutOfResourcesException(Surface.OutOfResourcesException e) {
-        Log.e(TAG, "OutOfResourcesException initializing HW surface", e);
+        Log.e(mTag, "OutOfResourcesException initializing HW surface", e);
         try {
             if (!mWindowSession.outOfMemory(mWindow) &&
                     Process.myUid() != Process.SYSTEM_UID) {
-                Slog.w(TAG, "No processes killed for memory; killing self");
+                Slog.w(mTag, "No processes killed for memory; killing self");
                 Process.killProcess(Process.myPid());
             }
         } catch (RemoteException ex) {
@@ -2184,7 +2186,7 @@
 
         final View host = mView;
         if (DEBUG_ORIENTATION || DEBUG_LAYOUT) {
-            Log.v(TAG, "Laying out " + host + " to (" +
+            Log.v(mTag, "Laying out " + host + " to (" +
                     host.getMeasuredWidth() + ", " + host.getMeasuredHeight() + ")");
         }
 
@@ -2427,11 +2429,11 @@
             String thisHash = Integer.toHexString(System.identityHashCode(this));
             long frameTime = nowTime - mFpsPrevTime;
             long totalTime = nowTime - mFpsStartTime;
-            Log.v(TAG, "0x" + thisHash + "\tFrame time:\t" + frameTime);
+            Log.v(mTag, "0x" + thisHash + "\tFrame time:\t" + frameTime);
             mFpsPrevTime = nowTime;
             if (totalTime > 1000) {
                 float fps = (float) mFpsNumFrames * 1000 / totalTime;
-                Log.v(TAG, "0x" + thisHash + "\tFPS:\t" + fps);
+                Log.v(mTag, "0x" + thisHash + "\tFPS:\t" + fps);
                 mFpsStartTime = nowTime;
                 mFpsNumFrames = 0;
             }
@@ -2473,7 +2475,7 @@
                 try {
                     mWindowDrawCountDown.await();
                 } catch (InterruptedException e) {
-                    Log.e(TAG, "Window redraw count down interruped!");
+                    Log.e(mTag, "Window redraw count down interruped!");
                 }
                 mWindowDrawCountDown = null;
             }
@@ -2483,7 +2485,7 @@
             }
 
             if (LOCAL_LOGV) {
-                Log.v(TAG, "FINISHED DRAWING: " + mWindowAttributes.getTitle());
+                Log.v(mTag, "FINISHED DRAWING: " + mWindowAttributes.getTitle());
             }
             if (mSurfaceHolder != null && mSurface.isValid()) {
                 mSurfaceHolderCallback.surfaceRedrawNeeded(mSurfaceHolder);
@@ -2566,7 +2568,7 @@
         }
 
         if (DEBUG_ORIENTATION || DEBUG_DRAW) {
-            Log.v(TAG, "Draw " + mView + "/"
+            Log.v(mTag, "Draw " + mView + "/"
                     + mWindowAttributes.getTitle()
                     + ": dirty={" + dirty.left + "," + dirty.top
                     + "," + dirty.right + "," + dirty.bottom + "} surface="
@@ -2700,7 +2702,7 @@
             handleOutOfResourcesException(e);
             return false;
         } catch (IllegalArgumentException e) {
-            Log.e(TAG, "Could not lock surface", e);
+            Log.e(mTag, "Could not lock surface", e);
             // Don't assume this is due to out of memory, it could be
             // something else, and if it is something else then we could
             // kill stuff (or ourself) for no reason.
@@ -2710,7 +2712,7 @@
 
         try {
             if (DEBUG_ORIENTATION || DEBUG_DRAW) {
-                Log.v(TAG, "Surface " + surface + " drawing to bitmap w="
+                Log.v(mTag, "Surface " + surface + " drawing to bitmap w="
                         + canvas.getWidth() + ", h=" + canvas.getHeight());
                 //canvas.drawARGB(255, 255, 0, 0);
             }
@@ -2733,7 +2735,7 @@
 
             if (DEBUG_DRAW) {
                 Context cxt = mView.getContext();
-                Log.i(TAG, "Drawing: package:" + cxt.getPackageName() +
+                Log.i(mTag, "Drawing: package:" + cxt.getPackageName() +
                         ", metrics=" + cxt.getResources().getDisplayMetrics() +
                         ", compatibilityInfo=" + cxt.getResources().getCompatibilityInfo());
             }
@@ -2758,14 +2760,14 @@
             try {
                 surface.unlockCanvasAndPost(canvas);
             } catch (IllegalArgumentException e) {
-                Log.e(TAG, "Could not unlock surface", e);
+                Log.e(mTag, "Could not unlock surface", e);
                 mLayoutRequested = true;    // ask wm for a new surface next time.
                 //noinspection ReturnInsideFinallyBlock
                 return false;
             }
 
             if (LOCAL_LOGV) {
-                Log.v(TAG, "Surface " + surface + " unlockCanvasAndPost");
+                Log.v(mTag, "Surface " + surface + " unlockCanvasAndPost");
             }
         }
         return true;
@@ -2870,14 +2872,14 @@
                 // view is visible.
                 rectangle = null;
             }
-            if (DEBUG_INPUT_RESIZE) Log.v(TAG, "Eval scroll: focus=" + focus
+            if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Eval scroll: focus=" + focus
                     + " rectangle=" + rectangle + " ci=" + ci
                     + " vi=" + vi);
             if (focus == lastScrolledFocus && !mScrollMayChange && rectangle == null) {
                 // Optimization: if the focus hasn't changed since last
                 // time, and no layout has happened, then just leave things
                 // as they are.
-                if (DEBUG_INPUT_RESIZE) Log.v(TAG, "Keeping scroll y="
+                if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Keeping scroll y="
                         + mScrollY + " vi=" + vi.toShortString());
             } else {
                 // We need to determine if the currently focused view is
@@ -2885,51 +2887,51 @@
                 // a pan so it can be seen.
                 mLastScrolledFocus = new WeakReference<View>(focus);
                 mScrollMayChange = false;
-                if (DEBUG_INPUT_RESIZE) Log.v(TAG, "Need to scroll?");
+                if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Need to scroll?");
                 // Try to find the rectangle from the focus view.
                 if (focus.getGlobalVisibleRect(mVisRect, null)) {
-                    if (DEBUG_INPUT_RESIZE) Log.v(TAG, "Root w="
+                    if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Root w="
                             + mView.getWidth() + " h=" + mView.getHeight()
                             + " ci=" + ci.toShortString()
                             + " vi=" + vi.toShortString());
                     if (rectangle == null) {
                         focus.getFocusedRect(mTempRect);
-                        if (DEBUG_INPUT_RESIZE) Log.v(TAG, "Focus " + focus
+                        if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Focus " + focus
                                 + ": focusRect=" + mTempRect.toShortString());
                         if (mView instanceof ViewGroup) {
                             ((ViewGroup) mView).offsetDescendantRectToMyCoords(
                                     focus, mTempRect);
                         }
-                        if (DEBUG_INPUT_RESIZE) Log.v(TAG,
+                        if (DEBUG_INPUT_RESIZE) Log.v(mTag,
                                 "Focus in window: focusRect="
                                 + mTempRect.toShortString()
                                 + " visRect=" + mVisRect.toShortString());
                     } else {
                         mTempRect.set(rectangle);
-                        if (DEBUG_INPUT_RESIZE) Log.v(TAG,
+                        if (DEBUG_INPUT_RESIZE) Log.v(mTag,
                                 "Request scroll to rect: "
                                 + mTempRect.toShortString()
                                 + " visRect=" + mVisRect.toShortString());
                     }
                     if (mTempRect.intersect(mVisRect)) {
-                        if (DEBUG_INPUT_RESIZE) Log.v(TAG,
+                        if (DEBUG_INPUT_RESIZE) Log.v(mTag,
                                 "Focus window visible rect: "
                                 + mTempRect.toShortString());
                         if (mTempRect.height() >
                                 (mView.getHeight()-vi.top-vi.bottom)) {
                             // If the focus simply is not going to fit, then
                             // best is probably just to leave things as-is.
-                            if (DEBUG_INPUT_RESIZE) Log.v(TAG,
+                            if (DEBUG_INPUT_RESIZE) Log.v(mTag,
                                     "Too tall; leaving scrollY=" + scrollY);
                         } else if ((mTempRect.top-scrollY) < vi.top) {
                             scrollY -= vi.top - (mTempRect.top-scrollY);
-                            if (DEBUG_INPUT_RESIZE) Log.v(TAG,
+                            if (DEBUG_INPUT_RESIZE) Log.v(mTag,
                                     "Top covered; scrollY=" + scrollY);
                         } else if ((mTempRect.bottom-scrollY)
                                 > (mView.getHeight()-vi.bottom)) {
                             scrollY += (mTempRect.bottom-scrollY)
                                     - (mView.getHeight()-vi.bottom);
-                            if (DEBUG_INPUT_RESIZE) Log.v(TAG,
+                            if (DEBUG_INPUT_RESIZE) Log.v(mTag,
                                     "Bottom covered; scrollY=" + scrollY);
                         }
                         handled = true;
@@ -2939,7 +2941,7 @@
         }
 
         if (scrollY != mScrollY) {
-            if (DEBUG_INPUT_RESIZE) Log.v(TAG, "Pan scroll changed: old="
+            if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Pan scroll changed: old="
                     + mScrollY + " , new=" + scrollY);
             if (!immediate) {
                 if (mScroller == null) {
@@ -3018,7 +3020,7 @@
 
     void setPointerCapture(View view) {
         if (!mAttachInfo.mHasWindowFocus) {
-            Log.w(TAG, "Can't set capture if it's not focused.");
+            Log.w(mTag, "Can't set capture if it's not focused.");
             return;
         }
         if (mCapturingView == view) {
@@ -3044,7 +3046,7 @@
     @Override
     public void requestChildFocus(View child, View focused) {
         if (DEBUG_INPUT_RESIZE) {
-            Log.v(TAG, "Request child focus: focus now " + focused);
+            Log.v(mTag, "Request child focus: focus now " + focused);
         }
         checkThread();
         scheduleTraversals();
@@ -3053,7 +3055,7 @@
     @Override
     public void clearChildFocus(View child) {
         if (DEBUG_INPUT_RESIZE) {
-            Log.v(TAG, "Clearing child focus");
+            Log.v(mTag, "Clearing child focus");
         }
         checkThread();
         scheduleTraversals();
@@ -3152,7 +3154,7 @@
     }
 
     void updateConfiguration(Configuration config, boolean force) {
-        if (DEBUG_CONFIGURATION) Log.v(TAG,
+        if (DEBUG_CONFIGURATION) Log.v(mTag,
                 "Applying new config to window "
                 + mWindowAttributes.getTitle()
                 + ": " + config);
@@ -3315,6 +3317,7 @@
                         && mPendingStableInsets.equals(args.arg6)
                         && mPendingVisibleInsets.equals(args.arg3)
                         && mPendingOutsets.equals(args.arg7)
+                        && mPendingBackDropFrame.equals(args.arg8)
                         && args.arg4 == null) {
                     break;
                 }
@@ -3387,10 +3390,10 @@
                                 mAttachInfo.mHardwareRenderer.initializeIfNeeded(
                                         mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets);
                             } catch (OutOfResourcesException e) {
-                                Log.e(TAG, "OutOfResourcesException locking surface", e);
+                                Log.e(mTag, "OutOfResourcesException locking surface", e);
                                 try {
                                     if (!mWindowSession.outOfMemory(mWindow)) {
-                                        Slog.w(TAG, "No processes killed for memory; killing self");
+                                        Slog.w(mTag, "No processes killed for memory; killing self");
                                         Process.killProcess(Process.myPid());
                                     }
                                 } catch (RemoteException ex) {
@@ -3713,7 +3716,7 @@
          */
         protected void onDeliverToNext(QueuedInputEvent q) {
             if (DEBUG_INPUT_STAGES) {
-                Log.v(TAG, "Done with " + getClass().getSimpleName() + ". " + q);
+                Log.v(mTag, "Done with " + getClass().getSimpleName() + ". " + q);
             }
             if (mNext != null) {
                 mNext.deliver(q);
@@ -3724,7 +3727,7 @@
 
         protected boolean shouldDropInputEvent(QueuedInputEvent q) {
             if (mView == null || !mAdded) {
-                Slog.w(TAG, "Dropping event due to root view being removed: " + q.mEvent);
+                Slog.w(mTag, "Dropping event due to root view being removed: " + q.mEvent);
                 return true;
             } else if ((!mAttachInfo.mHasWindowFocus
                     && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) || mStopped
@@ -3735,12 +3738,12 @@
                 if (isTerminalInputEvent(q.mEvent)) {
                     // Don't drop terminal input events, however mark them as canceled.
                     q.mEvent.cancel();
-                    Slog.w(TAG, "Cancelling event due to no window focus: " + q.mEvent);
+                    Slog.w(mTag, "Cancelling event due to no window focus: " + q.mEvent);
                     return false;
                 }
 
                 // Drop non-terminal input events.
-                Slog.w(TAG, "Dropping event due to no window focus: " + q.mEvent);
+                Slog.w(mTag, "Dropping event due to no window focus: " + q.mEvent);
                 return true;
             }
             return false;
@@ -3980,7 +3983,7 @@
                 InputMethodManager imm = InputMethodManager.peekInstance();
                 if (imm != null) {
                     final InputEvent event = q.mEvent;
-                    if (DEBUG_IMF) Log.v(TAG, "Sending input event to IME: " + event);
+                    if (DEBUG_IMF) Log.v(mTag, "Sending input event to IME: " + event);
                     int result = imm.dispatchInputEvent(event, q, this, mHandler);
                     if (result == InputMethodManager.DISPATCH_HANDLED) {
                         return FINISH_HANDLED;
@@ -4412,7 +4415,7 @@
                     break;
             }
 
-            if (DEBUG_TRACKBALL) Log.v(TAG, "TB X=" + mX.position + " step="
+            if (DEBUG_TRACKBALL) Log.v(mTag, "TB X=" + mX.position + " step="
                     + mX.step + " dir=" + mX.dir + " acc=" + mX.acceleration
                     + " move=" + event.getX()
                     + " / Y=" + mY.position + " step="
@@ -4451,11 +4454,11 @@
             if (keycode != 0) {
                 if (movement < 0) movement = -movement;
                 int accelMovement = (int)(movement * accel);
-                if (DEBUG_TRACKBALL) Log.v(TAG, "Move: movement=" + movement
+                if (DEBUG_TRACKBALL) Log.v(mTag, "Move: movement=" + movement
                         + " accelMovement=" + accelMovement
                         + " accel=" + accel);
                 if (accelMovement > movement) {
-                    if (DEBUG_TRACKBALL) Log.v(TAG, "Delivering fake DPAD: "
+                    if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: "
                             + keycode);
                     movement--;
                     int repeatCount = accelMovement - movement;
@@ -4465,7 +4468,7 @@
                             InputDevice.SOURCE_KEYBOARD));
                 }
                 while (movement > 0) {
-                    if (DEBUG_TRACKBALL) Log.v(TAG, "Delivering fake DPAD: "
+                    if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: "
                             + keycode);
                     movement--;
                     curTime = SystemClock.uptimeMillis();
@@ -4707,7 +4710,7 @@
                 update(event, true);
                 break;
             default:
-                Log.w(TAG, "Unexpected action: " + event.getActionMasked());
+                Log.w(mTag, "Unexpected action: " + event.getActionMasked());
             }
         }
 
@@ -5346,7 +5349,7 @@
                             mWindowSession.dragRecipientEntered(mWindow);
                         }
                     } catch (RemoteException e) {
-                        Slog.e(TAG, "Unable to note drag target change");
+                        Slog.e(mTag, "Unable to note drag target change");
                     }
                 }
 
@@ -5354,10 +5357,10 @@
                 if (what == DragEvent.ACTION_DROP) {
                     mDragDescription = null;
                     try {
-                        Log.i(TAG, "Reporting drop result: " + result);
+                        Log.i(mTag, "Reporting drop result: " + result);
                         mWindowSession.reportDropResult(mWindow, result);
                     } catch (RemoteException e) {
-                        Log.e(TAG, "Unable to report drop result");
+                        Log.e(mTag, "Unable to report drop result");
                     }
                 }
 
@@ -5443,14 +5446,14 @@
             mTranslator.translateWindowLayout(params);
         }
         if (params != null) {
-            if (DBG) Log.d(TAG, "WindowLayout in layoutWindow:" + params);
+            if (DBG) Log.d(mTag, "WindowLayout in layoutWindow:" + params);
         }
         mPendingConfiguration.seq = 0;
-        //Log.d(TAG, ">>>>>> CALLING relayout");
+        //Log.d(mTag, ">>>>>> CALLING relayout");
         if (params != null && mOrigWindowType != params.type) {
             // For compatibility with old apps, don't crash here.
             if (mTargetSdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
-                Slog.w(TAG, "Window type can not be changed after "
+                Slog.w(mTag, "Window type can not be changed after "
                         + "the window is added; ignoring change of " + mView);
                 params.type = mOrigWindowType;
             }
@@ -5462,7 +5465,7 @@
                 viewVisibility, insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0,
                 mWinFrame, mPendingOverscanInsets, mPendingContentInsets, mPendingVisibleInsets,
                 mPendingStableInsets, mPendingOutsets, mPendingConfiguration, mSurface);
-        //Log.d(TAG, "<<<<<< BACK FROM relayout");
+        //Log.d(mTag, "<<<<<< BACK FROM relayout");
         if (restore) {
             params.restore();
         }
@@ -5509,7 +5512,7 @@
             }
         } catch (IllegalStateException e) {
             // Exception thrown by getAudioManager() when mView is null
-            Log.e(TAG, "FATAL EXCEPTION when attempting to play sound effect: " + e);
+            Log.e(mTag, "FATAL EXCEPTION when attempting to play sound effect: " + e);
             e.printStackTrace();
         }
     }
@@ -5632,7 +5635,7 @@
         if (!mIsDrawing) {
             destroyHardwareRenderer();
         } else {
-            Log.e(TAG, "Attempting to destroy the window while drawing!\n" +
+            Log.e(mTag, "Attempting to destroy the window while drawing!\n" +
                     "  window=" + this + ", title=" + mWindowAttributes.getTitle());
         }
         mHandler.sendEmptyMessage(MSG_DIE);
@@ -5641,7 +5644,7 @@
 
     void doDie() {
         checkThread();
-        if (LOCAL_LOGV) Log.v(TAG, "DIE in " + this + " of " + mSurface);
+        if (LOCAL_LOGV) Log.v(mTag, "DIE in " + this + " of " + mSurface);
         synchronized (this) {
             if (mRemoved) {
                 return;
@@ -5734,7 +5737,7 @@
     public void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
             Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
             Configuration newConfig, Rect backDropFrame) {
-        if (DEBUG_LAYOUT) Log.v(TAG, "Resizing " + this + ": frame=" + frame.toShortString()
+        if (DEBUG_LAYOUT) Log.v(mTag, "Resizing " + this + ": frame=" + frame.toShortString()
                 + " contentInsets=" + contentInsets.toShortString()
                 + " visibleInsets=" + visibleInsets.toShortString()
                 + " reportDraw=" + reportDraw
@@ -5772,7 +5775,7 @@
     }
 
     public void dispatchMoved(int newX, int newY) {
-        if (DEBUG_LAYOUT) Log.v(TAG, "Window moved " + this + ": newX=" + newX + " newY=" + newY);
+        if (DEBUG_LAYOUT) Log.v(mTag, "Window moved " + this + ": newX=" + newX + " newY=" + newY);
         if (mTranslator != null) {
             PointF point = new PointF(newX, newY);
             mTranslator.translatePointInScreenToAppWindow(point);
@@ -6689,7 +6692,7 @@
     }
 
     void changeCanvasOpacity(boolean opaque) {
-        Log.d(TAG, "changeCanvasOpacity: opaque=" + opaque);
+        Log.d(mTag, "changeCanvasOpacity: opaque=" + opaque);
         if (mAttachInfo.mHardwareRenderer != null) {
             mAttachInfo.mHardwareRenderer.setOpaque(opaque);
         }
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index d7a98ab..0b06d15 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -571,14 +571,11 @@
     /** @hide */
     public interface WindowControllerCallback {
         /**
-         * Called to move the window and its activity/task to a different stack container.
-         * For example, a window can move between
-         * {@link android.app.ActivityManager.StackId#FULLSCREEN_WORKSPACE_STACK_ID} stack and
-         * {@link android.app.ActivityManager.StackId#FREEFORM_WORKSPACE_STACK_ID} stack.
-         *
-         * @param stackId stack Id to change to.
+         * Moves the activity from
+         * {@link android.app.ActivityManager.StackId#FREEFORM_WORKSPACE_STACK_ID} to
+         * {@link android.app.ActivityManager.StackId#FULLSCREEN_WORKSPACE_STACK_ID} stack.
          */
-        void changeWindowStack(int stackId) throws RemoteException;
+        void exitFreeformMode() throws RemoteException;
 
         /** Returns the current stack Id for the window. */
         int getWindowStackId() throws RemoteException;
diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java
index 01bfbb5..ecec258 100644
--- a/core/java/android/view/WindowManagerPolicy.java
+++ b/core/java/android/view/WindowManagerPolicy.java
@@ -623,14 +623,16 @@
      * decorations that can never be removed.  That is, system bar or
      * button bar.
      */
-    public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation);
+    public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
+            int uiMode);
 
     /**
      * Return the display height available after excluding any screen
      * decorations that can never be removed.  That is, system bar or
      * button bar.
      */
-    public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation);
+    public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
+            int uiMode);
 
     /**
      * Return the available screen width that we should report for the
@@ -638,7 +640,8 @@
      * {@link #getNonDecorDisplayWidth(int, int, int)}; it may be smaller than
      * that to account for more transient decoration like a status bar.
      */
-    public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation);
+    public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation,
+            int uiMode);
 
     /**
      * Return the available screen height that we should report for the
@@ -646,7 +649,8 @@
      * {@link #getNonDecorDisplayHeight(int, int, int)}; it may be smaller than
      * that to account for more transient decoration like a status bar.
      */
-    public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation);
+    public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation,
+            int uiMode);
 
     /**
      * Return whether the given window is forcibly hiding all windows except windows with
@@ -861,11 +865,11 @@
      * @param isDefaultDisplay true if window is on {@link Display#DEFAULT_DISPLAY}.
      * @param displayWidth The current full width of the screen.
      * @param displayHeight The current full height of the screen.
-     * @param displayRotation The current rotation being applied to the base
-     * window.
+     * @param displayRotation The current rotation being applied to the base window.
+     * @param uiMode The current uiMode in configuration.
      */
     public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
-                              int displayRotation);
+                              int displayRotation, int uiMode);
 
     /**
      * Returns the bottom-most layer of the system decor, above which no policy decor should
diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java
index 9442226..9595db2 100644
--- a/core/java/android/webkit/WebSettings.java
+++ b/core/java/android/webkit/WebSettings.java
@@ -987,9 +987,6 @@
      * @deprecated Database paths are managed by the implementation and calling this method
      *             will have no effect.
      */
-    // This will update WebCore when the Sync runs in the C++ side.
-    // Note that the WebCore Database Tracker only allows the path to be set
-    // once.
     @Deprecated
     public abstract void setDatabasePath(String databasePath);
 
@@ -1000,8 +997,10 @@
      *
      * @param databasePath a path to the directory where databases should be
      *                     saved.
+     * @deprecated Geolocation database are managed by the implementation and calling this method
+     *             will have no effect.
      */
-    // This will update WebCore when the Sync runs in the C++ side.
+    @Deprecated
     public abstract void setGeolocationDatabasePath(String databasePath);
 
     /**
@@ -1102,8 +1101,6 @@
      *   via the JavaScript Geolocation API.
      * </ul>
      * <p>
-     * As an option, it is possible to store previous locations and web origin
-     * permissions in a database. See {@link #setGeolocationDatabasePath}.
      *
      * @param flag whether Geolocation should be enabled
      */
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 7443bce..0f58ba3 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -280,6 +280,23 @@
  * instead.
  * </p>
  *
+ * <h3>Metrics</h3>
+ *
+ * <p>
+ * WebView may upload anonymous diagnostic data to Google when the user has consented. This data
+ * helps Google improve WebView. Data is collected on a per-app basis for each app which has
+ * instantiated a WebView. An individual app can opt out of this feature by putting the following
+ * tag in its manifest:
+ * </p>
+ * <pre>
+ * <meta-data android:name="android.webkit.WebView.MetricsOptOut"
+ *            android:value="true" />
+ * </pre>
+ * <p>
+ * Data will only be uploaded for a given app if the user has consented AND the app has not opted
+ * out.
+ * </p>
+ *
  */
 // Implementation notes.
 // The WebView is a thin API class that delegates its public API to a backend WebViewProvider
diff --git a/core/java/android/widget/ActionMenuPresenter.java b/core/java/android/widget/ActionMenuPresenter.java
index 0032f17..48d1d2b 100644
--- a/core/java/android/widget/ActionMenuPresenter.java
+++ b/core/java/android/widget/ActionMenuPresenter.java
@@ -20,6 +20,8 @@
 import android.animation.AnimatorListenerAdapter;
 import android.animation.ObjectAnimator;
 import android.animation.PropertyValuesHolder;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.content.res.Resources;
@@ -134,7 +136,7 @@
     }
 
     @Override
-    public void initForMenu(Context context, MenuBuilder menu) {
+    public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu) {
         super.initForMenu(context, menu);
 
         final Resources res = context.getResources();
@@ -629,8 +631,16 @@
     }
 
     public boolean flagActionItems() {
-        final ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
-        final int itemsSize = visibleItems.size();
+        final ArrayList<MenuItemImpl> visibleItems;
+        final int itemsSize;
+        if (mMenu != null) {
+            visibleItems = mMenu.getVisibleItems();
+            itemsSize = visibleItems.size();
+        } else {
+            visibleItems = null;
+            itemsSize = 0;
+        }
+
         int maxActions = mMaxItems;
         int widthLimit = mActionItemWidthLimit;
         final int querySpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
@@ -786,7 +796,7 @@
         if (isVisible) {
             // Not a submenu, but treat it like one.
             super.onSubMenuSelected(null);
-        } else {
+        } else if (mMenu != null) {
             mMenu.close(false /* closeAllMenus */);
         }
     }
@@ -938,7 +948,9 @@
 
         @Override
         protected void onDismiss() {
-            mMenu.close();
+            if (mMenu != null) {
+                mMenu.close();
+            }
             mOverflowPopup = null;
 
             super.onDismiss();
@@ -999,7 +1011,9 @@
         }
 
         public void run() {
-            mMenu.changeMenuMode();
+            if (mMenu != null) {
+                mMenu.changeMenuMode();
+            }
             final View menuView = (View) mMenuView;
             if (menuView != null && menuView.getWindowToken() != null && mPopup.tryShow()) {
                 mOverflowPopup = mPopup;
diff --git a/core/java/android/widget/ActionMenuView.java b/core/java/android/widget/ActionMenuView.java
index 1f02c3b..4d0a1c8 100644
--- a/core/java/android/widget/ActionMenuView.java
+++ b/core/java/android/widget/ActionMenuView.java
@@ -622,7 +622,7 @@
     }
 
     /** @hide */
-    public void initialize(MenuBuilder menu) {
+    public void initialize(@Nullable MenuBuilder menu) {
         mMenu = menu;
     }
 
diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java
index 258424a..ef6628a 100644
--- a/core/java/android/widget/GridLayout.java
+++ b/core/java/android/widget/GridLayout.java
@@ -1752,7 +1752,8 @@
             boolean validSolution = true;
             // do a binary search to find the max delta that won't conflict with constraints
             while(deltaMin < deltaMax) {
-                final int delta = (deltaMin + deltaMax) / 2;
+                // cast to long to prevent overflow.
+                final int delta = (int) (((long) deltaMin + deltaMax) / 2);
                 invalidateValues();
                 shareOutDelta(delta, totalWeight);
                 validSolution = solve(getArcs(), a, false);
diff --git a/core/java/android/widget/Toolbar.java b/core/java/android/widget/Toolbar.java
index acbf5eb..8e711b0 100644
--- a/core/java/android/widget/Toolbar.java
+++ b/core/java/android/widget/Toolbar.java
@@ -2070,7 +2070,7 @@
         MenuItemImpl mCurrentExpandedItem;
 
         @Override
-        public void initForMenu(Context context, MenuBuilder menu) {
+        public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu) {
             // Clear the expanded action view when menus change.
             if (mMenu != null && mCurrentExpandedItem != null) {
                 mMenu.collapseItemActionView(mCurrentExpandedItem);
diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java
index ba0912a..aa38de7 100644
--- a/core/java/com/android/internal/app/ResolverActivity.java
+++ b/core/java/com/android/internal/app/ResolverActivity.java
@@ -718,9 +718,9 @@
 
                     if (ri.handleAllWebDataURI) {
                         // Set default Browser if needed
-                        final String packageName = pm.getDefaultBrowserPackageName(userId);
+                        final String packageName = pm.getDefaultBrowserPackageNameAsUser(userId);
                         if (TextUtils.isEmpty(packageName)) {
-                            pm.setDefaultBrowserPackageName(ri.activityInfo.packageName, userId);
+                            pm.setDefaultBrowserPackageNameAsUser(ri.activityInfo.packageName, userId);
                         }
                     } else {
                         // Update Domain Verification status
@@ -737,7 +737,7 @@
                                 categories.contains(Intent.CATEGORY_BROWSABLE);
 
                         if (isHttpOrHttps && isViewAction && hasCategoryBrowsable) {
-                            pm.updateIntentVerificationStatus(packageName,
+                            pm.updateIntentVerificationStatusAsUser(packageName,
                                     PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS,
                                     userId);
                         }
diff --git a/core/java/com/android/internal/app/ToolbarActionBar.java b/core/java/com/android/internal/app/ToolbarActionBar.java
index 4b6e7e4..575ef02 100644
--- a/core/java/com/android/internal/app/ToolbarActionBar.java
+++ b/core/java/com/android/internal/app/ToolbarActionBar.java
@@ -483,6 +483,12 @@
         return true;
     }
 
+    @Override
+    public void onDestroy() {
+        // Remove any invalidation callbacks
+        mDecorToolbar.getViewGroup().removeCallbacks(mMenuInvalidator);
+    }
+
     public void addOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
         mMenuVisibilityListeners.add(listener);
     }
diff --git a/core/java/com/android/internal/logging/MetricsLogger.java b/core/java/com/android/internal/logging/MetricsLogger.java
index bfc56db..4b821ab 100644
--- a/core/java/com/android/internal/logging/MetricsLogger.java
+++ b/core/java/com/android/internal/logging/MetricsLogger.java
@@ -36,6 +36,8 @@
     public static final int NOTIFICATION_TOPIC_NOTIFICATION = 263;
     public static final int ACTION_DEFAULT_SMS_APP_CHANGED = 264;
     public static final int QS_COLOR_MATRIX = 265;
+    public static final int QS_CUSTOM = 266;
+    public static final int ACTION_ZEN_ALLOW_SCREEN_ON = 267;
 
     /**
      * Logged when the user docks a window from recents by longpressing a task and dragging it to
diff --git a/core/java/com/android/internal/policy/DecorView.java b/core/java/com/android/internal/policy/DecorView.java
index 40eaaf7..cc2f714 100644
--- a/core/java/com/android/internal/policy/DecorView.java
+++ b/core/java/com/android/internal/policy/DecorView.java
@@ -23,7 +23,6 @@
 import com.android.internal.view.StandaloneActionMode;
 import com.android.internal.view.menu.ContextMenuBuilder;
 import com.android.internal.view.menu.MenuHelper;
-import com.android.internal.view.menu.MenuPresenter;
 import com.android.internal.widget.ActionBarContextView;
 import com.android.internal.widget.BackgroundFallback;
 import com.android.internal.widget.DecorCaptionView;
@@ -72,6 +71,7 @@
 import static android.app.ActivityManager.StackId;
 import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
 import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
+import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
 import static android.view.View.MeasureSpec.AT_MOST;
 import static android.view.View.MeasureSpec.EXACTLY;
 import static android.view.View.MeasureSpec.getMode;
@@ -194,7 +194,12 @@
     private Drawable mCaptionBackgroundDrawable;
     private Drawable mUserCaptionBackgroundDrawable;
 
-    DecorView(Context context, int featureId, PhoneWindow window) {
+    private float mAvailableWidth;
+
+    String mLogTag = TAG;
+
+    DecorView(Context context, int featureId, PhoneWindow window,
+            WindowManager.LayoutParams params) {
         super(context);
         mFeatureId = featureId;
 
@@ -210,7 +215,11 @@
         mSemiTransparentStatusBarColor = context.getResources().getColor(
                 R.color.system_bar_background_semi_transparent, null /* theme */);
 
+        updateAvailableWidth();
+
         setWindow(window);
+
+        updateLogTag(params);
     }
 
     void setBackgroundFallback(int resId) {
@@ -408,7 +417,7 @@
 
         if (mFeatureId >= 0) {
             if (action == MotionEvent.ACTION_DOWN) {
-                Log.i(TAG, "Watchiing!");
+                Log.i(mLogTag, "Watchiing!");
                 mWatchingForMenu = true;
                 mDownY = (int) event.getY();
                 return false;
@@ -421,7 +430,7 @@
             int y = (int)event.getY();
             if (action == MotionEvent.ACTION_MOVE) {
                 if (y > (mDownY+30)) {
-                    Log.i(TAG, "Closing!");
+                    Log.i(mLogTag, "Closing!");
                     mWindow.closePanel(mFeatureId);
                     mWatchingForMenu = false;
                     return true;
@@ -433,13 +442,13 @@
             return false;
         }
 
-        //Log.i(TAG, "Intercept: action=" + action + " y=" + event.getY()
+        //Log.i(mLogTag, "Intercept: action=" + action + " y=" + event.getY()
         //        + " (in " + getHeight() + ")");
 
         if (action == MotionEvent.ACTION_DOWN) {
             int y = (int)event.getY();
             if (y >= (getHeight()-5) && !mWindow.hasChildren()) {
-                Log.i(TAG, "Watching!");
+                Log.i(mLogTag, "Watching!");
                 mWatchingForMenu = true;
             }
             return false;
@@ -452,7 +461,7 @@
         int y = (int)event.getY();
         if (action == MotionEvent.ACTION_MOVE) {
             if (y < (getHeight()-30)) {
-                Log.i(TAG, "Opening!");
+                Log.i(mLogTag, "Opening!");
                 mWindow.openPanel(Window.FEATURE_OPTIONS_PANEL, new KeyEvent(
                         KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MENU));
                 mWatchingForMenu = false;
@@ -543,15 +552,15 @@
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
-        final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
+        final boolean isPortrait =
+                getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT;
 
         final int widthMode = getMode(widthMeasureSpec);
         final int heightMode = getMode(heightMeasureSpec);
 
         boolean fixedWidth = false;
         if (widthMode == AT_MOST) {
-            final TypedValue tvw = isPortrait ? mWindow.mFixedWidthMinor
-                    : mWindow.mFixedWidthMajor;
+            final TypedValue tvw = isPortrait ? mWindow.mFixedWidthMinor : mWindow.mFixedWidthMajor;
             if (tvw != null && tvw.type != TypedValue.TYPE_NULL) {
                 final int w;
                 if (tvw.type == TypedValue.TYPE_DIMENSION) {
@@ -623,7 +632,7 @@
                 if (tv.type == TypedValue.TYPE_DIMENSION) {
                     min = (int)tv.getDimension(metrics);
                 } else if (tv.type == TypedValue.TYPE_FRACTION) {
-                    min = (int)tv.getFraction(metrics.widthPixels, metrics.widthPixels);
+                    min = (int)tv.getFraction(mAvailableWidth, mAvailableWidth);
                 } else {
                     min = 0;
                 }
@@ -1217,7 +1226,7 @@
                     int fop = fg.getOpacity();
                     int bop = bg.getOpacity();
                     if (false)
-                        Log.v(TAG, "Background opacity: " + bop + ", Frame opacity: " + fop);
+                        Log.v(mLogTag, "Background opacity: " + bop + ", Frame opacity: " + fop);
                     if (fop == PixelFormat.OPAQUE || bop == PixelFormat.OPAQUE) {
                         opacity = PixelFormat.OPAQUE;
                     } else if (fop == PixelFormat.UNKNOWN) {
@@ -1232,16 +1241,16 @@
                     // frame with padding... there is no way to tell if the
                     // frame and background together will draw all pixels.
                     if (false)
-                        Log.v(TAG, "Padding: " + mFramePadding);
+                        Log.v(mLogTag, "Padding: " + mFramePadding);
                     opacity = PixelFormat.TRANSLUCENT;
                 }
             }
             if (false)
-                Log.v(TAG, "Background: " + bg + ", Frame: " + fg);
+                Log.v(mLogTag, "Background: " + bg + ", Frame: " + fg);
         }
 
         if (false)
-            Log.v(TAG, "Selected default opacity: " + opacity);
+            Log.v(mLogTag, "Selected default opacity: " + opacity);
 
         mDefaultOpacity = opacity;
         if (mFeatureId < 0) {
@@ -1600,6 +1609,7 @@
                 enableCaption(StackId.hasWindowDecor(workspaceId));
             }
         }
+        updateAvailableWidth();
         initializeElevation();
     }
 
@@ -1744,7 +1754,7 @@
 
         // We shouldn't really get here as the background fallback should be always available since
         // it is defaulted by the system.
-        Log.w(TAG, "Failed to find background drawable for PhoneWindow=" + mWindow);
+        Log.w(mLogTag, "Failed to find background drawable for PhoneWindow=" + mWindow);
         return null;
     }
 
@@ -1761,7 +1771,7 @@
             try {
                 workspaceId = callback.getWindowStackId();
             } catch (RemoteException ex) {
-                Log.e(TAG, "Failed to get the workspace ID of a PhoneWindow.");
+                Log.e(mLogTag, "Failed to get the workspace ID of a PhoneWindow.");
             }
         }
         if (workspaceId == INVALID_STACK_ID) {
@@ -1927,6 +1937,19 @@
         }
     }
 
+    void updateLogTag(WindowManager.LayoutParams params) {
+        final String[] split = params.getTitle().toString().split("\\.");
+        if (split.length > 0) {
+            mLogTag = TAG + "[" + split[split.length - 1] + "]";
+        }
+    }
+
+    private void updateAvailableWidth() {
+        Resources res = getResources();
+        mAvailableWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
+                res.getConfiguration().screenWidthDp, res.getDisplayMetrics());
+    }
+
     private static class ColorViewState {
         View view = null;
         int targetVisibility = View.INVISIBLE;
@@ -1988,12 +2011,12 @@
                 isPrimary = mode == mPrimaryActionMode;
                 isFloating = mode == mFloatingActionMode;
                 if (!isPrimary && mode.getType() == ActionMode.TYPE_PRIMARY) {
-                    Log.e(TAG, "Destroying unexpected ActionMode instance of TYPE_PRIMARY; "
+                    Log.e(mLogTag, "Destroying unexpected ActionMode instance of TYPE_PRIMARY; "
                             + mode + " was not the current primary action mode! Expected "
                             + mPrimaryActionMode);
                 }
                 if (!isFloating && mode.getType() == ActionMode.TYPE_FLOATING) {
-                    Log.e(TAG, "Destroying unexpected ActionMode instance of TYPE_FLOATING; "
+                    Log.e(mLogTag, "Destroying unexpected ActionMode instance of TYPE_FLOATING; "
                             + mode + " was not the current floating action mode! Expected "
                             + mFloatingActionMode);
                 }
diff --git a/core/java/com/android/internal/policy/PhoneWindow.java b/core/java/com/android/internal/policy/PhoneWindow.java
index fafe3d1..f159a4d 100644
--- a/core/java/com/android/internal/policy/PhoneWindow.java
+++ b/core/java/com/android/internal/policy/PhoneWindow.java
@@ -113,6 +113,8 @@
 
     private final static String TAG = "PhoneWindow";
 
+    private static final boolean DEBUG = false;
+
     private final static int DEFAULT_BACKGROUND_FADE_DURATION_MS = 300;
 
     private static final int CUSTOM_TITLE_COMPATIBLE_FEATURES = DEFAULT_FEATURES |
@@ -146,6 +148,9 @@
     // This is the view in which the window contents are placed. It is either
     // mDecor itself, or a child of mDecor where the contents go.
     ViewGroup mContentParent;
+    // Whether the client has explicitly set the content view. If false and mContentParent is not
+    // null, then the content parent was set due to window preservation.
+    private boolean mContentParentExplicitlySet = false;
 
     Callback2 mTakeSurfaceCallback;
 
@@ -315,7 +320,7 @@
 
     @Override
     public boolean requestFeature(int featureId) {
-        if (mContentParent != null) {
+        if (mContentParentExplicitlySet) {
             throw new AndroidRuntimeException("requestFeature() must be called before adding content");
         }
         final int features = getFeatures();
@@ -399,6 +404,7 @@
         if (cb != null && !isDestroyed()) {
             cb.onContentChanged();
         }
+        mContentParentExplicitlySet = true;
     }
 
     @Override
@@ -429,6 +435,7 @@
         if (cb != null && !isDestroyed()) {
             cb.onContentChanged();
         }
+        mContentParentExplicitlySet = true;
     }
 
     @Override
@@ -2281,7 +2288,7 @@
         } else {
             context = getContext();
         }
-        return new DecorView(context, featureId, this);
+        return new DecorView(context, featureId, this, getAttributes());
     }
 
     protected ViewGroup generateLayout(DecorView decor) {
@@ -2360,6 +2367,8 @@
 
         a.getValue(R.styleable.Window_windowMinWidthMajor, mMinWidthMajor);
         a.getValue(R.styleable.Window_windowMinWidthMinor, mMinWidthMinor);
+        if (DEBUG) Log.d(TAG, "Min width minor: " + mMinWidthMinor.coerceToString()
+                + ", major: " + mMinWidthMajor.coerceToString());
         if (a.hasValue(R.styleable.Window_windowFixedWidthMajor)) {
             if (mFixedWidthMajor == null) mFixedWidthMajor = new TypedValue();
             a.getValue(R.styleable.Window_windowFixedWidthMajor,
@@ -3776,4 +3785,12 @@
     int getDecorCaptionShade() {
         return mDecorCaptionShade;
     }
+
+    @Override
+    public void setAttributes(WindowManager.LayoutParams params) {
+        super.setAttributes(params);
+        if (mDecor != null) {
+            mDecor.updateLogTag(params);
+        }
+    }
 }
diff --git a/core/java/com/android/internal/statusbar/IStatusBar.aidl b/core/java/com/android/internal/statusbar/IStatusBar.aidl
index 849d314..4dd71e7 100644
--- a/core/java/com/android/internal/statusbar/IStatusBar.aidl
+++ b/core/java/com/android/internal/statusbar/IStatusBar.aidl
@@ -46,7 +46,7 @@
     void cancelPreloadRecentApps();
     void showScreenPinningRequest();
 
-    void showKeyboardShortcutsMenu();
+    void toggleKeyboardShortcutsMenu();
 
     /**
      * Notifies the status bar that an app transition is pending to delay applying some flags with
diff --git a/core/java/com/android/internal/statusbar/IStatusBarService.aidl b/core/java/com/android/internal/statusbar/IStatusBarService.aidl
index 0a4ad06..0125d37 100644
--- a/core/java/com/android/internal/statusbar/IStatusBarService.aidl
+++ b/core/java/com/android/internal/statusbar/IStatusBarService.aidl
@@ -68,7 +68,7 @@
     void preloadRecentApps();
     void cancelPreloadRecentApps();
 
-    void showKeyboardShortcutsMenu();
+    void toggleKeyboardShortcutsMenu();
 
     /**
      * Notifies the status bar that an app transition is pending to delay applying some flags with
diff --git a/core/java/com/android/internal/util/StateMachine.java b/core/java/com/android/internal/util/StateMachine.java
index 406b487..dc66818 100644
--- a/core/java/com/android/internal/util/StateMachine.java
+++ b/core/java/com/android/internal/util/StateMachine.java
@@ -779,7 +779,7 @@
         @Override
         public final void handleMessage(Message msg) {
             if (!mHasQuit) {
-                if (mSm != null) {
+                if (mSm != null && msg.what != SM_INIT_CMD && msg.what != SM_QUIT_CMD) {
                     mSm.onPreHandleMessage(msg);
                 }
 
@@ -807,7 +807,7 @@
                 // We need to check if mSm == null here as we could be quitting.
                 if (mDbg && mSm != null) mSm.log("handleMessage: X");
 
-                if (mSm != null) {
+                if (mSm != null && msg.what != SM_INIT_CMD && msg.what != SM_QUIT_CMD) {
                     mSm.onPostHandleMessage(msg);
                 }
             }
diff --git a/core/java/com/android/internal/view/menu/BaseMenuPresenter.java b/core/java/com/android/internal/view/menu/BaseMenuPresenter.java
index 92e9ea6..7ac0ac3 100644
--- a/core/java/com/android/internal/view/menu/BaseMenuPresenter.java
+++ b/core/java/com/android/internal/view/menu/BaseMenuPresenter.java
@@ -16,6 +16,8 @@
 
 package com.android.internal.view.menu;
 
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.content.Context;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -58,7 +60,7 @@
     }
 
     @Override
-    public void initForMenu(Context context, MenuBuilder menu) {
+    public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu) {
         mContext = context;
         mInflater = LayoutInflater.from(mContext);
         mMenu = menu;
diff --git a/core/java/com/android/internal/view/menu/IconMenuPresenter.java b/core/java/com/android/internal/view/menu/IconMenuPresenter.java
index 2439b5d..5223a7b 100644
--- a/core/java/com/android/internal/view/menu/IconMenuPresenter.java
+++ b/core/java/com/android/internal/view/menu/IconMenuPresenter.java
@@ -17,6 +17,8 @@
 
 import com.android.internal.view.menu.MenuView.ItemView;
 
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.content.Context;
 import android.os.Bundle;
 import android.os.Parcelable;
@@ -49,7 +51,7 @@
     }
 
     @Override
-    public void initForMenu(Context context, MenuBuilder menu) {
+    public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu) {
         super.initForMenu(context, menu);
         mMaxItems = -1;
     }
diff --git a/core/java/com/android/internal/view/menu/ListMenuPresenter.java b/core/java/com/android/internal/view/menu/ListMenuPresenter.java
index c476354..2fff3ba 100644
--- a/core/java/com/android/internal/view/menu/ListMenuPresenter.java
+++ b/core/java/com/android/internal/view/menu/ListMenuPresenter.java
@@ -16,6 +16,8 @@
 
 package com.android.internal.view.menu;
 
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.content.Context;
 import android.os.Bundle;
 import android.os.Parcelable;
@@ -76,7 +78,7 @@
     }
 
     @Override
-    public void initForMenu(Context context, MenuBuilder menu) {
+    public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu) {
         if (mThemeRes != 0) {
             mContext = new ContextThemeWrapper(context, mThemeRes);
             mInflater = LayoutInflater.from(mContext);
diff --git a/core/java/com/android/internal/view/menu/MenuBuilder.java b/core/java/com/android/internal/view/menu/MenuBuilder.java
index 465d775..31b2f96 100644
--- a/core/java/com/android/internal/view/menu/MenuBuilder.java
+++ b/core/java/com/android/internal/view/menu/MenuBuilder.java
@@ -17,6 +17,7 @@
 package com.android.internal.view.menu;
 
 
+import android.annotation.NonNull;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -1027,23 +1028,24 @@
         mIsActionItemsStale = true;
         onItemsChanged(true);
     }
-    
+
+    @NonNull
     public ArrayList<MenuItemImpl> getVisibleItems() {
         if (!mIsVisibleItemsStale) return mVisibleItems;
-        
+
         // Refresh the visible items
         mVisibleItems.clear();
-        
+
         final int itemsSize = mItems.size(); 
         MenuItemImpl item;
         for (int i = 0; i < itemsSize; i++) {
             item = mItems.get(i);
             if (item.isVisible()) mVisibleItems.add(item);
         }
-        
+
         mIsVisibleItemsStale = false;
         mIsActionItemsStale = true;
-        
+
         return mVisibleItems;
     }
 
diff --git a/core/java/com/android/internal/view/menu/MenuPopup.java b/core/java/com/android/internal/view/menu/MenuPopup.java
index 98f5d90..b151f34 100644
--- a/core/java/com/android/internal/view/menu/MenuPopup.java
+++ b/core/java/com/android/internal/view/menu/MenuPopup.java
@@ -16,6 +16,8 @@
 
 package com.android.internal.view.menu;
 
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.content.Context;
 import android.view.MenuItem;
 import android.view.View;
@@ -73,7 +75,7 @@
     public abstract void setOnDismissListener(PopupWindow.OnDismissListener listener);
 
     @Override
-    public void initForMenu(Context context, MenuBuilder menu) {
+    public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu) {
         // Don't need to do anything; we added as a presenter in the constructor.
     }
 
diff --git a/core/java/com/android/internal/view/menu/MenuPresenter.java b/core/java/com/android/internal/view/menu/MenuPresenter.java
index c847c15..65bdc09 100644
--- a/core/java/com/android/internal/view/menu/MenuPresenter.java
+++ b/core/java/com/android/internal/view/menu/MenuPresenter.java
@@ -16,6 +16,8 @@
 
 package com.android.internal.view.menu;
 
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.content.Context;
 import android.os.Parcelable;
 import android.view.ViewGroup;
@@ -49,14 +51,16 @@
     }
 
     /**
-     * Initialize this presenter for the given context and menu.
-     * This method is called by MenuBuilder when a presenter is
-     * added. See {@link MenuBuilder#addMenuPresenter(MenuPresenter)}
+     * Initializes this presenter for the given context and menu.
+     * <p>
+     * This method is called by MenuBuilder when a presenter is added. See
+     * {@link MenuBuilder#addMenuPresenter(MenuPresenter)}.
      *
-     * @param context Context for this presenter; used for view creation and resource management
-     * @param menu Menu to host
+     * @param context the context for this presenter; used for view creation
+     *                and resource management, must be non-{@code null}
+     * @param menu the menu to host, or {@code null} to clear the hosted menu
      */
-    public void initForMenu(Context context, MenuBuilder menu);
+    public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu);
 
     /**
      * Retrieve a MenuView to display the menu specified in
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index 825e336..f90b59d 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -17,6 +17,8 @@
 package com.android.internal.widget;
 
 import android.animation.LayoutTransition;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.app.ActionBar;
 import android.content.Context;
 import android.content.res.Configuration;
@@ -1593,7 +1595,7 @@
         MenuItemImpl mCurrentExpandedItem;
 
         @Override
-        public void initForMenu(Context context, MenuBuilder menu) {
+        public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu) {
             // Clear the expanded action view when menus change.
             if (mMenu != null && mCurrentExpandedItem != null) {
                 mMenu.collapseItemActionView(mCurrentExpandedItem);
diff --git a/core/java/com/android/internal/widget/DecorCaptionView.java b/core/java/com/android/internal/widget/DecorCaptionView.java
index c3fe9e7..409a17f 100644
--- a/core/java/com/android/internal/widget/DecorCaptionView.java
+++ b/core/java/com/android/internal/widget/DecorCaptionView.java
@@ -16,8 +16,6 @@
 
 package com.android.internal.widget;
 
-import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
-
 import android.content.Context;
 import android.graphics.Color;
 import android.graphics.Rect;
@@ -351,7 +349,7 @@
         Window.WindowControllerCallback callback = mOwner.getWindowControllerCallback();
         if (callback != null) {
             try {
-                callback.changeWindowStack(FULLSCREEN_WORKSPACE_STACK_ID);
+                callback.exitFreeformMode();
             } catch (RemoteException ex) {
                 Log.e(TAG, "Cannot change task workspace.");
             }
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp
index 4a0f3fc..92f7812 100644
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -260,6 +260,15 @@
         return nullObjectReturn("SkAndroidCodec::NewFromStream returned null");
     }
 
+    // Do not allow ninepatch decodes to 565.  In the past, decodes to 565
+    // would dither, and we do not want to pre-dither ninepatches, since we
+    // know that they will be stretched.  We no longer dither 565 decodes,
+    // but we continue to prevent ninepatches from decoding to 565, in order
+    // to maintain the old behavior.
+    if (peeker.mPatch && kRGB_565_SkColorType == prefColorType) {
+        prefColorType = kN32_SkColorType;
+    }
+
     // Determine the output size and return if the client only wants the size.
     SkISize size = codec->getSampledDimensions(sampleSize);
     if (options != NULL) {
@@ -369,15 +378,7 @@
         case SkCodec::kIncompleteInput:
             break;
         default:
-            return nullObjectReturn("codec->getAndoridPixels() failed.");
-    }
-
-    // Some images may initially report that they have alpha due to the format
-    // of the encoded data, but then never use any colors which have alpha
-    // less than 100%.  Here we check if the image really had alpha, and
-    // mark it as opaque if it is actually opaque.
-    if (kOpaque_SkAlphaType != alphaType && !codec->reallyHasAlpha()) {
-        decodingBitmap.setAlphaType(kOpaque_SkAlphaType);
+            return nullObjectReturn("codec->getAndroidPixels() failed.");
     }
 
     int scaledWidth = size.width();
@@ -587,10 +588,6 @@
     return doDecode(env, stream.release(), NULL, options);
 }
 
-static void nativeRequestCancel(JNIEnv*, jobject joptions) {
-    // Deprecated
-}
-
 static jboolean nativeIsSeekable(JNIEnv* env, jobject, jobject fileDescriptor) {
     jint descriptor = jniGetFDFromFileDescriptor(env, fileDescriptor);
     return ::lseek64(descriptor, 0, SEEK_CUR) != -1 ? JNI_TRUE : JNI_FALSE;
@@ -630,10 +627,6 @@
     },
 };
 
-static const JNINativeMethod gOptionsMethods[] = {
-    {   "requestCancel", "()V", (void*)nativeRequestCancel }
-};
-
 int register_android_graphics_BitmapFactory(JNIEnv* env) {
     jclass options_class = FindClassOrDie(env, "android/graphics/BitmapFactory$Options");
     gOptions_bitmapFieldID = GetFieldIDOrDie(env, options_class, "inBitmap",
@@ -665,8 +658,6 @@
     gInsetStruct_constructorMethodID = GetMethodIDOrDie(env, gInsetStruct_class, "<init>",
                                                         "(IIIIIIIIFIF)V");
 
-    android::RegisterMethodsOrDie(env, "android/graphics/BitmapFactory$Options",
-                                  gOptionsMethods, NELEM(gOptionsMethods));
     return android::RegisterMethodsOrDie(env, "android/graphics/BitmapFactory",
                                          gMethods, NELEM(gMethods));
 }
diff --git a/core/jni/android/graphics/FontFamily.cpp b/core/jni/android/graphics/FontFamily.cpp
index ab0df55..7c8dbe8 100644
--- a/core/jni/android/graphics/FontFamily.cpp
+++ b/core/jni/android/graphics/FontFamily.cpp
@@ -36,12 +36,12 @@
 namespace android {
 
 static jlong FontFamily_create(JNIEnv* env, jobject clazz, jstring lang, jint variant) {
-    FontLanguage fontLanguage;
-    if (lang != NULL) {
-        ScopedUtfChars str(env, lang);
-        fontLanguage = FontLanguage(str.c_str(), str.size());
+    if (lang == NULL) {
+        return (jlong)new FontFamily(variant);
     }
-    return (jlong)new FontFamily(fontLanguage, variant);
+    ScopedUtfChars str(env, lang);
+    uint32_t langId = FontStyle::registerLanguageList(str.c_str());
+    return (jlong)new FontFamily(langId, variant);
 }
 
 static void FontFamily_unref(JNIEnv* env, jobject clazz, jlong familyPtr) {
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index 654d148..0a25a0a 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -313,94 +313,10 @@
         obj->setTextAlign(align);
     }
 
-    // generate bcp47 identifier for the supplied locale
-    static void toLanguageTag(char* output, size_t outSize,
-            const char* locale) {
-        if (output == NULL || outSize <= 0) {
-            return;
-        }
-        if (locale == NULL) {
-            output[0] = '\0';
-            return;
-        }
-        char canonicalChars[ULOC_FULLNAME_CAPACITY];
-        UErrorCode uErr = U_ZERO_ERROR;
-        uloc_canonicalize(locale, canonicalChars, ULOC_FULLNAME_CAPACITY,
-                &uErr);
-        if (U_SUCCESS(uErr)) {
-            char likelyChars[ULOC_FULLNAME_CAPACITY];
-            uErr = U_ZERO_ERROR;
-            uloc_addLikelySubtags(canonicalChars, likelyChars,
-                    ULOC_FULLNAME_CAPACITY, &uErr);
-            if (U_SUCCESS(uErr)) {
-                uErr = U_ZERO_ERROR;
-                uloc_toLanguageTag(likelyChars, output, outSize, FALSE, &uErr);
-                if (U_SUCCESS(uErr)) {
-                    return;
-                } else {
-                    ALOGD("uloc_toLanguageTag(\"%s\") failed: %s", likelyChars,
-                            u_errorName(uErr));
-                }
-            } else {
-                ALOGD("uloc_addLikelySubtags(\"%s\") failed: %s",
-                        canonicalChars, u_errorName(uErr));
-            }
-        } else {
-            ALOGD("uloc_canonicalize(\"%s\") failed: %s", locale,
-                    u_errorName(uErr));
-        }
-        // unable to build a proper language identifier
-        output[0] = '\0';
-    }
-
-    static void toLanguageTags(std::string* output, const char* locales) {
-        if (output == NULL) {
-            return;
-        }
-        if (locales == NULL) {
-            output->clear();
-            return;
-        }
-
-        char langTag[ULOC_FULLNAME_CAPACITY];
-        const char* commaLoc = strchr(locales, ',');
-        if (commaLoc == NULL) {
-            assert(locales[0] != '\0');  // the string should not be empty
-            toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, locales);
-            *output = langTag;
-            return;
-        }
-
-        size_t len = strlen(locales);
-        char locale[len];
-        output->clear();
-        output->reserve(len);
-        const char* lastStart = locales;
-        do {
-            assert(lastStart > commaLoc);  // the substring should not be empty
-            strncpy(locale, lastStart, commaLoc - lastStart);
-            locale[commaLoc - lastStart] = '\0';
-            toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, locale);
-            if (langTag[0] != '\0') {
-                output->append(langTag);
-                output->push_back(',');
-            }
-            lastStart = commaLoc + 1;
-            commaLoc = strchr(lastStart, ',');
-        } while (commaLoc != NULL);
-        assert(lastStart[0] != '\0');  // the final substring should not be empty
-        toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, lastStart);
-        if (langTag[0] != '\0') {
-            output->append(langTag);
-        }
-    }
-
     static jint setTextLocales(JNIEnv* env, jobject clazz, jlong objHandle, jstring locales) {
         Paint* obj = reinterpret_cast<Paint*>(objHandle);
         ScopedUtfChars localesChars(env, locales);
-        std::string buf;
-        toLanguageTags(&buf, localesChars.c_str());
-        jint minikinLangListId = FontStyle::registerLanguageList(buf);
+        jint minikinLangListId = FontStyle::registerLanguageList(localesChars.c_str());
         obj->setMinikinLangListId(minikinLangListId);
         return minikinLangListId;
     }
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index 7860b74..42f3fb0 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -1049,6 +1049,10 @@
     pJniStorage->mDeviceCallback.clear();
 }
 
+static jint android_media_AudioTrack_get_FCC_8(JNIEnv *env, jobject thiz) {
+    return FCC_8;
+}
+
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
@@ -1106,6 +1110,7 @@
     {"native_getRoutedDeviceId", "()I", (void *)android_media_AudioTrack_getRoutedDeviceId},
     {"native_enableDeviceCallback", "()V", (void *)android_media_AudioTrack_enableDeviceCallback},
     {"native_disableDeviceCallback", "()V", (void *)android_media_AudioTrack_disableDeviceCallback},
+    {"native_get_FCC_8",     "()I",      (void *)android_media_AudioTrack_get_FCC_8},
 };
 
 
@@ -1135,6 +1140,9 @@
 // ----------------------------------------------------------------------------
 int register_android_media_AudioTrack(JNIEnv *env)
 {
+    // must be first
+    int res = RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
+
     javaAudioTrackFields.nativeTrackInJavaObj = NULL;
     javaAudioTrackFields.postNativeEventInJava = NULL;
 
@@ -1173,7 +1181,7 @@
     // initialize PlaybackParams field info
     gPlaybackParamsFields.init(env);
 
-    return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
+    return res;
 }
 
 
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index 90606a35..3473d9d 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -578,7 +578,7 @@
     return am->isUpToDate() ? JNI_TRUE : JNI_FALSE;
 }
 
-static jobjectArray android_content_AssetManager_getLocales(JNIEnv* env, jobject clazz)
+static jobjectArray getLocales(JNIEnv* env, jobject clazz, bool includeSystemLocales)
 {
     Vector<String8> locales;
 
@@ -587,7 +587,7 @@
         return NULL;
     }
 
-    am->getLocales(&locales);
+    am->getLocales(&locales, includeSystemLocales);
 
     const int N = locales.size();
 
@@ -608,6 +608,16 @@
     return result;
 }
 
+static jobjectArray android_content_AssetManager_getLocales(JNIEnv* env, jobject clazz)
+{
+    return getLocales(env, clazz, true /* include system locales */);
+}
+
+static jobjectArray android_content_AssetManager_getNonSystemLocales(JNIEnv* env, jobject clazz)
+{
+    return getLocales(env, clazz, false /* don't include system locales */);
+}
+
 static jobject constructConfigurationObject(JNIEnv* env, const ResTable_config& config) {
     jobject result = env->NewObject(gConfigurationOffsets.classObject,
             gConfigurationOffsets.constructor);
@@ -2154,6 +2164,8 @@
     // Resources.
     { "getLocales",      "()[Ljava/lang/String;",
         (void*) android_content_AssetManager_getLocales },
+    { "getNonSystemLocales", "()[Ljava/lang/String;",
+        (void*) android_content_AssetManager_getNonSystemLocales },
     { "getSizeConfigurations", "()[Landroid/content/res/Configuration;",
         (void*) android_content_AssetManager_getSizeConfigurations },
     { "setConfiguration", "!(IILjava/lang/String;IIIIIIIIIIIIII)V",
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 1090f90..7d9fd93 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -107,6 +107,7 @@
     <protected-broadcast android:name="android.backup.intent.CLEAR" />
     <protected-broadcast android:name="android.backup.intent.INIT" />
 
+    <protected-broadcast android:name="android.bluetooth.intent.DISCOVERABLE_TIMEOUT" />
     <protected-broadcast android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
     <protected-broadcast android:name="android.bluetooth.adapter.action.SCAN_MODE_CHANGED" />
     <protected-broadcast android:name="android.bluetooth.adapter.action.DISCOVERY_STARTED" />
@@ -276,8 +277,10 @@
     <protected-broadcast android:name="android.intent.action.AIRPLANE_MODE" />
     <protected-broadcast android:name="android.intent.action.ADVANCED_SETTINGS" />
     <protected-broadcast android:name="android.intent.action.APPLICATION_RESTRICTIONS_CHANGED" />
-    <protected-broadcast android:name="android.intent.action.BUGREPORT_FINISHED" />
     <protected-broadcast android:name="android.intent.action.BUGREPORT_STARTED" />
+    <protected-broadcast android:name="android.intent.action.BUGREPORT_FINISHED" />
+    <protected-broadcast android:name="android.intent.action.REMOTE_BUGREPORT_FINISHED" />
+    <protected-broadcast android:name="android.intent.action.REMOTE_BUGREPORT_DISPATCH" />
 
     <protected-broadcast android:name="android.intent.action.ACTION_IDLE_MAINTENANCE_START" />
     <protected-broadcast android:name="android.intent.action.ACTION_IDLE_MAINTENANCE_END" />
@@ -382,6 +385,12 @@
     <protected-broadcast android:name="com.android.server.Wifi.action.TOGGLE_PNO" />
     <protected-broadcast android:name="intent.action.ACTION_RF_BAND_INFO" />
 
+    <protected-broadcast android:name="android.app.action.INTERRUPTION_FILTER_CHANGED" />
+    <protected-broadcast android:name="android.app.action.INTERRUPTION_FILTER_CHANGED_INTERNAL" />
+    <protected-broadcast android:name="android.app.action.NOTIFICATION_POLICY_CHANGED" />
+    <protected-broadcast android:name="android.app.action.NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED" />
+    <protected-broadcast android:name="android.os.action.ACTION_EFFECTS_SUPPRESSOR_CHANGED" />
+
     <!-- ====================================================================== -->
     <!--                          RUNTIME PERMISSIONS                           -->
     <!-- ====================================================================== -->
@@ -888,6 +897,11 @@
         android:protectionLevel="normal"
         android:permissionFlags="hidden"/>
 
+    <!-- @hide We need to keep this around for backwards compatibility -->
+    <permission android:name="android.permission.FLASHLIGHT"
+        android:protectionLevel="normal"
+        android:permissionFlags="hidden"/>
+
     <!-- ====================================================================== -->
     <!-- INSTALL PERMISSIONS                                                    -->
     <!-- ====================================================================== -->
@@ -1193,14 +1207,6 @@
         android:description="@string/permdesc_vibrate"
         android:protectionLevel="normal" />
 
-    <!-- Allows access to the flashlight.
-         <p>Protection level: normal
-    -->
-    <permission android:name="android.permission.FLASHLIGHT"
-        android:label="@string/permlab_flashlight"
-        android:description="@string/permdesc_flashlight"
-        android:protectionLevel="normal" />
-
     <!-- Allows using PowerManager WakeLocks to keep processor from sleeping or screen
          from dimming.
          <p>Protection level: normal
@@ -1901,7 +1907,7 @@
 
     <!-- Allows an application to bind to third party quick settings tiles.
          <p>Should only be requested by the System, should be required by
-         QSTileService declarations.-->
+         TileService declarations.-->
     <permission android:name="android.permission.BIND_QUICK_SETTINGS_TILE"
         android:protectionLevel="signature" />
 
diff --git a/core/res/res/values-af/strings.xml b/core/res/res/values-af/strings.xml
index 04466e5..36c167e 100644
--- a/core/res/res/values-af/strings.xml
+++ b/core/res/res/values-af/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Laat die program toe om foto\'s en video\'s met die kamera te neem. Hierdie toestemming laat die program toe om die kamera te eniger tyd sonder jou bevestiging te gebruik."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"beheer vibrasie"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Laat die program toe om die vibrator te beheer."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"beheer flitslig"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Laat die program toe om die flitslig te beheer."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"skakel foonnommers direk"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Laat die program toe om telefoonnommers sonder jou tussentrede te bel. Dit kan tot onverwagte heffings of oproepe lei. Let daarop dat dit nie die program toelaat om noodnommers te bel nie. Kwaadwillige programme kan jou geld kos deur oproepe sonder jou bevestiging te maak."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"toegang tot kitsboodskapoproepdiens"</string>
diff --git a/core/res/res/values-am/strings.xml b/core/res/res/values-am/strings.xml
index b262325..ec16add 100644
--- a/core/res/res/values-am/strings.xml
+++ b/core/res/res/values-am/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"መተግበሪያው በካሜራው ፎቶዎችንና ቪዲዮዎችን እንዲያነሳ ይፈቅድለታል። ይህ ፈቃድ መተግበሪያው ካሜራውን በማንኛውም ጊዜ ያላንተ ማረጋገጫ እንዲጠቀም ይፈቅድለታል።"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"ነዛሪ ተቆጣጠር"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"ነዛሪውን ለመቆጣጠር ለመተግበሪያው ይፈቅዳሉ።"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"የብርሃንብልጭታ ተቆጣጠር"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"የብልጭታ ብርሃኑን ለመቆጣጠር ለመተግበሪያው ይፈቅዳሉ።"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"በቀጥታ ስልክ ቁጥሮች ደውል"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"መተግበሪያው ያላንተ ጣልቃ ገብነት የስልክ ቁጥሮች ላይ እንዲደውል ይፈቅድለታል። ይህ ያልተጠበቁ ክፍያዎችን ወይም ጥሪዎችን ሊያስከትል ይችላል። ይህ መተግበሪያው የድንገተኛ ስልክ ቁጥሮችን እንዲደውል እንደማይፈቅድለት ልብ በል። ተንኮል አዘል መተግበሪያዎች ያላንተ ማረጋገጫ ጥሪዎችን በማድረግ ገንዘብ ሊያስወጡህ ይችላሉ።"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"የአይኤምኤስ ጥሪ አገልግሎትን ይደርሳል"</string>
diff --git a/core/res/res/values-ar/strings.xml b/core/res/res/values-ar/strings.xml
index 6eb005c..12ef759 100644
--- a/core/res/res/values-ar/strings.xml
+++ b/core/res/res/values-ar/strings.xml
@@ -358,8 +358,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"للسماح للتطبيق بالتقاط صور ومقاطع فيديو من خلال الكاميرا. ويتيح هذا الإذن للتطبيق استخدام الكاميرا في أي وقت وبدون موافقة منك."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"التحكم في الاهتزاز"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"للسماح للتطبيق بالتحكم في الهزّاز."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"التحكم في الضوء الوامض"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"للسماح للتطبيق بالتحكم في الضوء الوامض."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"اتصال مباشر بأرقام الهواتف"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"للسماح للتطبيق بطلب أرقام هاتفية بدون تدخل منك. وقد يؤدي ذلك إلى تحمل رسوم غير متوقعة أو إجراء مكالمات غير متوقعة. ومن الجدير بالذكر أن ذلك لا يتيح للتطبيق الاتصال بأرقام الطوارئ. وقد تؤدي التطبيقات الضارة إلى تحملك تكاليف مالية من خلال إجراء مكالمات بدون موافقة منك."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"الوصول إلى خدمة الاتصال عبر الرسائل الفورية"</string>
diff --git a/core/res/res/values-az-rAZ/strings.xml b/core/res/res/values-az-rAZ/strings.xml
index 30b6e77..7f0e6d7 100644
--- a/core/res/res/values-az-rAZ/strings.xml
+++ b/core/res/res/values-az-rAZ/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Tətbiqə kamera ilə şəkil və video çəkməyə imkan yaradır. Bu icazə tətbiqə sizin təsdiqiniz olmadan kameradan istifadə icazəsi verir."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"vibrasiyaya nəzarət edir"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Tətbiqə vibratoru idarə etmə icazəsi verir."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"Flash işığını idarə edir"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Tətbiqə siqnal işığı na nəzarət etməyə imkan verir."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"telefon nömrələrinə birbaşa zəng edir"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Tətbiqə Sizin müdaxiləniz olmadan telefon zəngləri etməyə imkan verir. Zərərli tətbiqlər Sizdən xəbərsiz şəkildə müxtəlif zənglər edərək, Sizə maddi ziyan vura bilər. Qeyd: Bu, tətbiqlərə təcili nömrələrə zəng etməyə icazə vermir."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS zəng xidmətinə giriş"</string>
diff --git a/core/res/res/values-b+sr+Latn/strings.xml b/core/res/res/values-b+sr+Latn/strings.xml
index 0f51f0d..ac5ce66 100644
--- a/core/res/res/values-b+sr+Latn/strings.xml
+++ b/core/res/res/values-b+sr+Latn/strings.xml
@@ -355,8 +355,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Dozvoljava aplikaciji da snima slike i video snimke kamerom. Ova dozvola omogućava aplikaciji da u bilo kom trenutku koristi kameru bez vaše potvrde."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"kontrola vibracije"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Dozvoljava aplikaciji da kontroliše vibraciju."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"kontrola osvetljenja"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Dozvoljava aplikaciji da kontroliše blic."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"direktno pozivanje brojeva telefona"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Dozvoljava aplikaciji da poziva brojeve telefona bez vaše dozvole. Ovo može da dovede do neočekivanih troškova ili poziva. Imajte na umu da ovo ne dozvoljava aplikaciji da poziva brojeve za hitne slučajeve. Zlonamerne aplikacije mogu da pozivaju bez vaše potvrde, što može da dovede do troškova."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"pristup usluzi poziva pomoću razmene trenutnih poruka"</string>
diff --git a/core/res/res/values-bg/strings.xml b/core/res/res/values-bg/strings.xml
index d70f95f..301e1e3 100644
--- a/core/res/res/values-bg/strings.xml
+++ b/core/res/res/values-bg/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Разрешава на приложението да прави снимки и видеоклипове с камерата. Това разрешение му позволява да я използва по всяко време без потвърждение от ваша страна."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"контролиране на вибрирането"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Разрешава на приложението да контролира устройството за вибрация."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"контролиране на фенерчето"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Разрешава на приложението да контролира фенерчето."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"директно обаждане до телефонни номера"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Разрешава на приложението да се обажда без ваша намеса до телефонни номера, което може да доведе до неочаквано таксуване или обаждания. Обърнете внимание, че това не му позволява да извършва обаждания до спешните служби. Злонамерените приложения могат да ви въвлекат в разходи, като извършват обаждания без потвърждение от ваша страна."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"достъп до услугата за незабавни съобщения за обаждания"</string>
diff --git a/core/res/res/values-bn-rBD/strings.xml b/core/res/res/values-bn-rBD/strings.xml
index 683e2ec..9c88d44 100644
--- a/core/res/res/values-bn-rBD/strings.xml
+++ b/core/res/res/values-bn-rBD/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"ক্যামেরার সাহায্যে ছবি তুলতে ও ভিডিও তৈরি করতে অ্যাপ্লিকেশানটিকে মঞ্জুর করে৷ এই অনুমতিটি অ্যাপ্লিকেশানটিকে আপনার নিশ্চয়তা ছাড়াই যেকোনো সময় ক্যামেরা ব্যবহার করতে মঞ্জুর করে৷"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"কম্পন নিয়ন্ত্রণ করুন"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"অ্যাপ্লিকেশানকে কম্পক নিয়ন্ত্রণ করতে দেয়৷"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ফ্ল্যাশলাইট নিয়ন্ত্রণ করে"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"অ্যাপ্লিকেশানকে টর্চলাইট নিয়ন্ত্রণ করতে দেয়৷"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"সরাসরি ফোন নম্বরগুলিতে কল করে"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"অ্যাপ্লিকেশানটিকে আপনার হস্তক্ষেপ ছাড়াই ফোন নম্বরগুলিতে কল করতে মঞ্জুর করে৷ এটি অপ্রত্যাশিত পরিমাণ খরচা বা কলের কারণ হতে পারে৷ মনে রাখবেন, এটি অ্যাপ্লিকেশানটির দ্বারা জরুরি নম্বরগুলিতে কল করাকে অনুমতি দেয় না৷ ক্ষতিকারক অ্যাপ্লিকেশানগুলি আপনার সম্মতি ছাড়াই কল করার ফলে আপনাকে অহেতুক অর্থ প্রদান করতে হতে পারে৷"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS পরিষেবাতে অ্যাক্সেস"</string>
diff --git a/core/res/res/values-ca/strings.xml b/core/res/res/values-ca/strings.xml
index 786fea1..8554b843 100644
--- a/core/res/res/values-ca/strings.xml
+++ b/core/res/res/values-ca/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Permet que l\'aplicació faci fotos i vídeos amb la càmera. Aquest permís permet que l\'aplicació utilitzi la càmera en qualsevol moment sense la teva confirmació."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"controlar la vibració"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Permet que l\'aplicació controli el vibrador."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"controla la llanterna"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Permet que l\'aplicació controli la llanterna."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"trucar directament a números de telèfon"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Permet que l\'aplicació truqui a números de telèfon sense la teva intervenció. Aquesta acció pot produir càrrecs o trucades inesperades. Tingues en compte que això no permet que l\'aplicació truqui a números d\'emergència. Les aplicacions malicioses poden fer trucades sense la teva confirmació, cosa que et pot fer gastar diners."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"accés al servei de trucades IMS"</string>
diff --git a/core/res/res/values-cs/strings.xml b/core/res/res/values-cs/strings.xml
index a2e12a3..2eca49a 100644
--- a/core/res/res/values-cs/strings.xml
+++ b/core/res/res/values-cs/strings.xml
@@ -356,8 +356,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Umožňuje aplikaci pořizovat fotografie a videa pomocí fotoaparátu. Toto oprávnění umožňuje aplikaci používat fotoaparát kdykoliv i bez vašeho svolení."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"ovládání vibrací"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Umožňuje aplikaci ovládat vibrace."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ovládání kontrolky"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Umožňuje aplikaci ovládat svítilnu."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"přímé volání na telefonní čísla"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Umožňuje aplikaci volat na telefonní čísla bez vašeho přičinění. Může mít za následek neočekávané poplatky nebo hovory. Toto oprávnění neumožňuje aplikaci volat na tísňová čísla. Škodlivé aplikace vás mohou připravit o peníze uskutečňováním hovorů bez vašeho svolení."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"přístup ke službě zasílání rychlých zpráv pro účely hovorů"</string>
diff --git a/core/res/res/values-da/strings.xml b/core/res/res/values-da/strings.xml
index 67b8ee9..2a719b0 100644
--- a/core/res/res/values-da/strings.xml
+++ b/core/res/res/values-da/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Tillader, at appen kan tage billeder og videoer med kameraet. Med denne tilladelse kan appen til enhver tid bruge kameraet uden din bekræftelse."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"kontrollere vibration"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Tillader, at appen kan kontrollere vibratoren."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"kontroller lommelygte"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Tillader, at appen kan kontrollere lommelygten."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ringe direkte op til telefonnumre"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Tillader, at appen kan ringe til telefonnumre uden din indgriben. Dette kan resultere i uventede opkrævninger eller opkald. Bemærk, at appen med denne tilladelse ikke kan ringe til nødopkaldsnumre. Skadelige apps kan koste dig penge ved at foretage opkald uden din bekræftelse."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"få adgang til chat-opkaldstjeneste"</string>
diff --git a/core/res/res/values-de/strings.xml b/core/res/res/values-de/strings.xml
index 2d64aee..d116a24 100644
--- a/core/res/res/values-de/strings.xml
+++ b/core/res/res/values-de/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Ermöglicht der App, Bilder und Videos mit der Kamera aufzunehmen. Die Berechtigung erlaubt der App, die Kamera jederzeit und ohne Ihre Bestätigung zu nutzen."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"Vibrationsalarm steuern"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Ermöglicht der App, den Vibrationsalarm zu steuern"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"Lichtanzeige steuern"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Ermöglicht der App, die Lichtanzeige zu steuern"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"Telefonnummern direkt anrufen"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Ermöglicht der App, ohne Ihr Eingreifen Telefonnummern zu wählen. Dies kann zu unerwarteten Kosten und Anrufen führen. Beachten Sie, dass die App keine Notrufnummern wählen kann. Schädliche Apps verursachen möglicherweise Kosten, indem sie Anrufe ohne Ihre Bestätigung tätigen."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"Zugriff auf IMS-Anrufdienst"</string>
diff --git a/core/res/res/values-el/strings.xml b/core/res/res/values-el/strings.xml
index a1a6ced..8116b16 100644
--- a/core/res/res/values-el/strings.xml
+++ b/core/res/res/values-el/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Επιτρέπει στην εφαρμογή τη λήψη φωτογραφιών και βίντεο με τη φωτογραφική μηχανή. Αυτή η άδεια δίνει τη δυνατότητα στην εφαρμογή να χρησιμοποιεί τη φωτογραφική μηχανή ανά πάσα στιγμή χωρίς την έγκρισή σας."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"έλεγχος δόνησης"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Επιτρέπει στην εφαρμογή τον έλεγχο της δόνησης."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"έλεγχος φακού"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Επιτρέπει στην εφαρμογή τον έλεγχο του φακού."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"απευθείας κλήση τηλεφωνικών αριθμών"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Επιτρέπει στην εφαρμογή την κλήση αριθμών τηλεφώνου χωρίς δική σας παρέμβαση. Αυτό μπορεί να προκαλέσει μη αναμενόμενες χρεώσεις ή κλήσεις. Έχετε υπόψη ότι δεν επιτρέπεται στην εφαρμογή η κλήση αριθμών έκτακτης ανάγκης. Οι κακόβουλες εφαρμογές ενδέχεται να σας κοστίσουν χρήματα, πραγματοποιώντας κλήσεις χωρίς την έγκρισή σας."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"πρόσβαση στην υπηρεσία κλήσεων της IMS"</string>
diff --git a/core/res/res/values-en-rAU/strings.xml b/core/res/res/values-en-rAU/strings.xml
index cd2dc23..930c310 100644
--- a/core/res/res/values-en-rAU/strings.xml
+++ b/core/res/res/values-en-rAU/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Allows the app to take pictures and videos with the camera. This permission allows the app to use the camera at any time without your confirmation."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"control vibration"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Allows the app to control the vibrator."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"control flashlight"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Allows the app to control the flashlight."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"directly call phone numbers"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Allows the app to call phone numbers without your intervention. This may result in unexpected charges or calls. Note that this doesn\'t allow the app to call emergency numbers. Malicious apps may cost you money by making calls without your confirmation."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"access IMS call service"</string>
diff --git a/core/res/res/values-en-rGB/strings.xml b/core/res/res/values-en-rGB/strings.xml
index cd2dc23..930c310 100644
--- a/core/res/res/values-en-rGB/strings.xml
+++ b/core/res/res/values-en-rGB/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Allows the app to take pictures and videos with the camera. This permission allows the app to use the camera at any time without your confirmation."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"control vibration"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Allows the app to control the vibrator."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"control flashlight"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Allows the app to control the flashlight."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"directly call phone numbers"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Allows the app to call phone numbers without your intervention. This may result in unexpected charges or calls. Note that this doesn\'t allow the app to call emergency numbers. Malicious apps may cost you money by making calls without your confirmation."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"access IMS call service"</string>
diff --git a/core/res/res/values-en-rIN/strings.xml b/core/res/res/values-en-rIN/strings.xml
index cd2dc23..930c310 100644
--- a/core/res/res/values-en-rIN/strings.xml
+++ b/core/res/res/values-en-rIN/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Allows the app to take pictures and videos with the camera. This permission allows the app to use the camera at any time without your confirmation."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"control vibration"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Allows the app to control the vibrator."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"control flashlight"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Allows the app to control the flashlight."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"directly call phone numbers"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Allows the app to call phone numbers without your intervention. This may result in unexpected charges or calls. Note that this doesn\'t allow the app to call emergency numbers. Malicious apps may cost you money by making calls without your confirmation."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"access IMS call service"</string>
diff --git a/core/res/res/values-es-rUS/strings.xml b/core/res/res/values-es-rUS/strings.xml
index a6f76ac..258ef33 100644
--- a/core/res/res/values-es-rUS/strings.xml
+++ b/core/res/res/values-es-rUS/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Permite que la aplicación saque fotos o grabe videos con la cámara. Este permiso autoriza a la aplicación a utilizar la cámara en cualquier momento sin tu confirmación."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"controlar la vibración"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Permite que la aplicación controle la vibración."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"controlar linterna"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Permite que la aplicación controle la función de linterna."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"llamar directamente a números de teléfono"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Permite que la aplicación haga llamadas a números de teléfono sin intervención del usuario, lo que puede dar lugar a llamadas o cargos inesperados. Ten en cuenta que las aplicaciones no pueden usar este servicio para realizar llamadas a números de emergencia, pero las aplicaciones malintencionadas pueden causarte gastos imprevistos al realizar llamadas sin tu confirmación."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"acceder al servicio IMS para realizar llamadas"</string>
diff --git a/core/res/res/values-es/strings.xml b/core/res/res/values-es/strings.xml
index 594fa50..9848bb6 100644
--- a/core/res/res/values-es/strings.xml
+++ b/core/res/res/values-es/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Permite que la aplicación haga fotos o grabe vídeos con la cámara. Este permiso autoriza a la aplicación a utilizar la cámara en cualquier momento sin tu confirmación."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"controlar la vibración"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Permite que la aplicación controle la función de vibración."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"controlar linterna"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Permite que la aplicación controle la función de linterna."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"llamar directamente a números de teléfono"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Permite que la aplicación haga llamadas sin intervención del usuario, lo que puede dar lugar a llamadas o cargos inesperados. Ten en cuenta que las aplicaciones no pueden usar este servicio para realizar llamadas a números de emergencia, pero las aplicaciones malintencionadas pueden causarte gastos imprevistos al realizar llamadas sin tu confirmación."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"acceder al servicio de llamadas IMS"</string>
diff --git a/core/res/res/values-et-rEE/strings.xml b/core/res/res/values-et-rEE/strings.xml
index 8ee8904..466bd5d 100644
--- a/core/res/res/values-et-rEE/strings.xml
+++ b/core/res/res/values-et-rEE/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Võimaldab rakendusel teha kaameraga pilte ja videoid. See luba võimaldab rakendusel kasutada kaamerat mis tahes ajal teie kinnituseta."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"juhtige vibreerimist"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Võimaldab rakendusel juhtida vibreerimist."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"juhi taskulampi"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Võimaldab rakendusel juhtida taskulampi."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"helista otse telefoninumbritele"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Võimaldab rakendusel teie sekkumiseta telefoninumbritele helistada. See võib põhjustada ootamatuid tasusid või telefonikõnesid. Pange tähele, et see ei luba rakendusel helistada hädaabinumbritele. Pahatahtlikud rakendused võivad teile kulusid tekitada, tehes telefonikõnesid teie kinnituseta."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"juurdepääs IMS-kõneteenusele"</string>
diff --git a/core/res/res/values-eu-rES/strings.xml b/core/res/res/values-eu-rES/strings.xml
index e257fe9..cdb8622 100644
--- a/core/res/res/values-eu-rES/strings.xml
+++ b/core/res/res/values-eu-rES/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Kamerarekin argazkiak ateratzeko eta bideoak grabatzeko baimena ematen die aplikazioei. Baimen horrekin, aplikazioak kamera edonoiz erabil dezake zure baimenik gabe."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"bibrazioa kontrolatzea"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Bibragailua kontrolatzea baimentzen die aplikazioei."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"kontrolatu linterna"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Linterna kontrolatzea baimentzen die aplikazioei."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"deitu zuzenean telefono-zenbakietara"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Telefono-zenbakietara zuk esku hartu gabe deitzeko baimena ematen die aplikazioei. Horrela, ustekabeko gastuak edo deiak eragin daitezke. Aplikazio gaiztoek erabil dezakete zuk berretsi gabeko deiak eginda gastuak eragiteko."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"Atzitu IMS dei-zerbitzua"</string>
diff --git a/core/res/res/values-fa/strings.xml b/core/res/res/values-fa/strings.xml
index b6b669e..b0da5fe 100644
--- a/core/res/res/values-fa/strings.xml
+++ b/core/res/res/values-fa/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"به برنامه اجازه می‌دهد با دوربین به عکسبرداری و فیلمبرداری بپردازد. این مجوز به برنامه اجازه می‌‌دهد از دوربین در هر زمانی بدون تأیید شما استفاده کند."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"کنترل لرزش"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"‏به برنامه اجازه می‎دهد تا لرزاننده را کنترل کند."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"کنترل چراغ قوه"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"‏به برنامه اجازه می‎دهد تا چراغ قوه را کنترل کند."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"تماس مستقیم با شماره تلفن‌ها"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"به برنامه اجازه می‌دهد بدون دخالت شما با شماره‌های تلفن تماس بگیرد. این ممکن است باعث ایجاد هزینه یا تماس‌های پیش‌بینی نشده شود. توجه داشته باشید که این به برنامه اجازه نمی‌دهد به برقراری تماس‌های اضطراری بپردازد. برنامه‌های مخرب ممکن است با برقراری تماس بدون تأیید شما هزینه‌هایی را برای شما ایجاد کنند."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"‏دسترسی به سرویس تماس IMS"</string>
diff --git a/core/res/res/values-fi/strings.xml b/core/res/res/values-fi/strings.xml
index b0efd96..f7db678 100644
--- a/core/res/res/values-fi/strings.xml
+++ b/core/res/res/values-fi/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Antaa sovelluksen ottaa kuvia ja kuvata videoita kameralla. Sovellus voi käyttää kameraa milloin tahansa ilman lupaasi."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"hallitse värinää"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Antaa sovelluksen hallita värinää."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"hallitse taskulamppua"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Antaa sovelluksen hallita taskulamppua."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"soittaa puhelinnumeroihin suoraan"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Antaa sovelluksen soittaa puhelinnumeroihin kysymättä sinulta. Tämä voi aiheuttaa odottamattomia kuluja tai puheluita. Huomaa, että tämä ei anna sovellukselle lupaa soittaa hätänumeroihin. Haitalliset sovellukset voivat aiheuttaa sinulle kuluja soittamalla puheluita ilman lupaa."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"pikaviestipalvelun puhelukäyttöoikeus"</string>
diff --git a/core/res/res/values-fr-rCA/strings.xml b/core/res/res/values-fr-rCA/strings.xml
index 52a47587..50aed95 100644
--- a/core/res/res/values-fr-rCA/strings.xml
+++ b/core/res/res/values-fr-rCA/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Permet à l\'application de prendre des photos et de filmer des vidéos avec l\'appareil photo. Cette autorisation lui permet d\'utiliser l\'appareil photo à tout moment sans votre consentement."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"gérer le vibreur"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Permet à l\'application de gérer le vibreur de l\'appareil."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"gérer la lampe de poche"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Permet à l\'application de gérer la lampe de poche."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"appeler directement des numéros de téléphone"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Permet à l\'application d\'appeler des numéros de téléphone sans votre intervention. Cette autorisation peut entraîner des frais ou des appels imprévus et ne permet pas à l\'application d\'appeler des numéros d\'urgence. Des applications malveillantes peuvent générer des frais en passant des appels sans votre consentement."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"accéder au service d\'appel IMS"</string>
diff --git a/core/res/res/values-fr/strings.xml b/core/res/res/values-fr/strings.xml
index 2740f3d..33d2016 100644
--- a/core/res/res/values-fr/strings.xml
+++ b/core/res/res/values-fr/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Permet à l\'application de prendre des photos et de filmer des vidéos avec l\'appareil photo. Cette autorisation lui permet d\'utiliser l\'appareil photo à tout moment sans votre consentement."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"contrôler le vibreur"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Permet à l\'application de contrôler le vibreur."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"contrôler la lampe de poche"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Permet à l\'application de contrôler la lampe de poche."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"appeler directement les numéros de téléphone"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Permet à l\'application d\'appeler des numéros de téléphone sans votre intervention. Cette autorisation peut entraîner des frais ou des appels imprévus et ne permet pas à l\'application d\'appeler des numéros d\'urgence. Les applications malveillantes peuvent générer des frais en passant des appels sans votre consentement."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"accéder au service d\'appel IMS"</string>
diff --git a/core/res/res/values-gl-rES/strings.xml b/core/res/res/values-gl-rES/strings.xml
index 71ce6e9b..7947825 100644
--- a/core/res/res/values-gl-rES/strings.xml
+++ b/core/res/res/values-gl-rES/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Permite á aplicación tomar imaxes e vídeos coa cámara. Con este permiso a aplicación pode utilizar a cámara en calquera momento sen a túa confirmación."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"controlar a vibración"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Permite á aplicación controlar o vibrador."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"controlar a lanterna"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Permite á aplicación controlar a luz do flash."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"chamar directamente aos números de teléfono"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Permite á aplicación chamar a números de teléfono sen a túa intervención. Esta acción pode implicar chamadas ou custos inesperados. Ten en conta que isto non permite á aplicación chamar a números de emerxencia. É posible que aplicacións maliciosas che custen diñeiro debido á realización de chamadas sen a túa confirmación."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"acceso ao servizo de chamadas de IMS"</string>
diff --git a/core/res/res/values-gu-rIN/strings.xml b/core/res/res/values-gu-rIN/strings.xml
index 8258dc2..aa9478b 100644
--- a/core/res/res/values-gu-rIN/strings.xml
+++ b/core/res/res/values-gu-rIN/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"એપ્લિકેશનને કૅમેરા વડે ચિત્રો અને વિડિઓઝ લેવાની મંજૂરી આપે છે. આ પરવાનગી એપ્લિકેશનને તમારી પુષ્ટિ વિના કોઈપણ સમયે કૅમેરાના ઉપયોગની મંજૂરી આપે છે."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"વાઇબ્રેશન નિયંત્રિત કરો"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"એપ્લિકેશનને વાઇબ્રેટરને નિયંત્રિત કરવાની મંજૂરી આપે છે."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ફ્લેશલાઇટ નિયંત્રિત કરો"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"એપ્લિકેશનને ફ્લેશલાઇટને નિયંત્રિત કરવાની મંજૂરી આપે છે."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"સીધા જ ફોન નંબર્સ પર કૉલ કરો"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"એપ્લિકેશનને તમારા હસ્તક્ષેપ વિના ફોન નંબર્સ પર કૉલ કરવાની મંજૂરી આપે છે. આ અનપેક્ષિત શુલ્ક અથવા કૉલ્સમાં પરિણમી શકે છે. નોંધો કે આ એપ્લિકેશનને કટોકટીના નંબર્સ પર કૉલ કરવાની મંજૂરી આપતું નથી. દુર્ભાવનાપૂર્ણ એપ્લિકેશનો તમારી પુષ્ટિ વિના કૉલ્સ કરીને તમારા પૈસા ખર્ચ કરી શકે છે."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS કૉલ સેવા ઍક્સેસ કરો"</string>
diff --git a/core/res/res/values-hi/strings.xml b/core/res/res/values-hi/strings.xml
index 3f374ac6..d3d1e2c 100644
--- a/core/res/res/values-hi/strings.xml
+++ b/core/res/res/values-hi/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"ऐप्स  को कैमरे से चित्र और वीडियो लेने देता है. यह अनुमति ऐप्स  को किसी भी समय आपकी पुष्टि के बिना कैमरे का उपयोग करने देती है."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"कंपन नियंत्रित करें"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"ऐप्स को कंपनकर्ता नियंत्रित करने देता है."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"फ़्लैशलाइट नियंत्रित करें"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"ऐप्स को फ़्लैशलाइट नियंत्रित करने देता है."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"फ़ोन नंबर पर सीधे कॉल करें"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"ऐप्स  को आपके हस्‍तक्षेप के बिना फ़ोन नंबर पर कॉल करने देता है. इसके परिणाम अप्रत्‍याशित शुल्‍क या कॉल हो सकते हैं. ध्यान दें कि यह ऐप्स  को आपातकालीन नंबर पर कॉल नहीं करने देता. दुर्भावनापूर्ण ऐप्स  आपकी पुष्टि के बिना कॉल करके आपका धन व्‍यय कर सकते हैं."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS कॉल सेवा ऐक्‍सेस करें"</string>
diff --git a/core/res/res/values-hr/strings.xml b/core/res/res/values-hr/strings.xml
index bf89366..dc55c57 100644
--- a/core/res/res/values-hr/strings.xml
+++ b/core/res/res/values-hr/strings.xml
@@ -355,8 +355,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Aplikaciji omogućuje snimanje slika i videozapisa fotoaparatom. Ta dozvola aplikaciji omogućuje upotrebu fotoaparata u bilo kojem trenutku bez vašeg odobrenja."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"upravljanje vibracijom"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Aplikaciji omogućuje nadzor nad vibratorom."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"upravljanje svjetiljkom"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Aplikaciji omogućuje upravljanje svjetiljkom."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"izravno pozivanje telefonskog broja"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Aplikaciji omogućuje pozivanje telefonskih brojeva bez vašeg sudjelovanja. To može dovesti do neočekivanih troškova ili poziva. Uzmite u obzir da se aplikaciji time ne omogućuje pozivanje brojeva u nuždi. Zlonamjerne aplikacije mogu vam uzrokovati dodatne troškove postavljanjem poziva bez vašeg odobrenja."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"pristupiti usluzi poziva izravnih poruka"</string>
diff --git a/core/res/res/values-hu/strings.xml b/core/res/res/values-hu/strings.xml
index 64e2229..3176c65 100644
--- a/core/res/res/values-hu/strings.xml
+++ b/core/res/res/values-hu/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Lehetővé teszi az alkalmazás számára, hogy a fényképezőgéppel fotókat és videókat készítsen. Az engedéllyel rendelkező alkalmazás bármikor, az Ön jóváhagyása nélkül használhatja a fényképezőgépet."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"rezgés szabályozása"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Lehetővé teszi az alkalmazás számára a rezgés vezérlését."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"vaku vezérlése"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Lehetővé teszi az alkalmazás számára a vaku vezérlését."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"telefonszámok közvetlen hívása"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Lehetővé teszi az alkalmazás számára, hogy az Ön jóváhagyása nélkül hívjon fel telefonszámokat. Ennek eredményeként váratlan terhelésekkel vagy telefonhívásokkal találkozhat. Vegye figyelembe, hogy ez nem teszi lehetővé segélyhívó számok hívását az alkalmazás számára. A rosszindulatú alkalmazások az Ön jóváhagyása nélkül kezdeményezhetnek hívásokat, így költségek merülhetnek fel."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"hozzáférés az IMS-hívásszolgáltatáshoz"</string>
diff --git a/core/res/res/values-hy-rAM/strings.xml b/core/res/res/values-hy-rAM/strings.xml
index 6fdccd3..d72ee8d 100644
--- a/core/res/res/values-hy-rAM/strings.xml
+++ b/core/res/res/values-hy-rAM/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Թույլ է տալիս հավելվածին ֆոտոխցիկով լուսանկարել և տեսանկարել: Այս թույլտվությունը հնարավորություն է տալիս հավելվածին օգտագործել ֆոտոխցիկը ցանկացած ժամանակ` առանց ձեր հաստատման:"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"կառավարել թրթռումը"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Թույլ է տալիս հավելվածին կառավարել թրթռոցը:"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"կառավարել լապտերը"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Թույլ է տալիս հավելվածին կառավարել լապտերը:"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ուղղակիորեն զանգել հեռախոսահամարներին"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Թույլ է տալիս հավելվածին զանգել հեռախոսահամարներին առանց ձեր միջամտության: Սա կարող է հանգեցնել անկանխատեսելի գանձումների կամ զանգերի: Նկատի ունեցեք, որ սա թույլ չի տալիս հավելվածին զանգել արտակարգ իրավիճակների համարներին: Վնասարար հավելվածները կարող են ձեր հաշվից զանգեր կատարել` առանց ձեր հաստատման:"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"օգտվել IMS զանգերի ծառայությունից"</string>
diff --git a/core/res/res/values-in/strings.xml b/core/res/res/values-in/strings.xml
index 4960267..024eea4 100644
--- a/core/res/res/values-in/strings.xml
+++ b/core/res/res/values-in/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Memungkinkan aplikasi mengambil gambar dan video dengan kamera. Izin ini memungkinkan aplikasi menggunakan kamera kapan saja tanpa konfirmasi Anda."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"kontrol getaran"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Mengizinkan aplikasi untuk mengendalikan vibrator."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"mengontrol lampu senter"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Mengizinkan apl mengontrol lampu kilat."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"panggil nomor telepon secara langsung"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Memungkinkan aplikasi menghubungi nomor telepon tanpa campur tangan Anda. Izin ini dapat mengakibatkan biaya atau panggilan tak terduga. Perhatikan bahwa izin ini tidak memungkinkan aplikasi menghubungi nomor darurat. Aplikasi berbahaya dapat menyebabkan Anda dikenakan biaya dengan melakukan panggilan tanpa konfirmasi Anda."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"akses layanan panggilan IMS"</string>
diff --git a/core/res/res/values-is-rIS/strings.xml b/core/res/res/values-is-rIS/strings.xml
index 35ae53d..240c715 100644
--- a/core/res/res/values-is-rIS/strings.xml
+++ b/core/res/res/values-is-rIS/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Leyfir forriti að taka myndir og myndskeið með myndavélinni. Þessi heimild leyfir forritinu að nota myndavélina hvenær sem er án þinnar heimildar."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"stjórna titringi"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Leyfir forriti að stjórna titraranum."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"stjórna vasaljósi"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Leyfir forriti að stjórna vasaljósinu."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"hringja beint í símanúmer"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Leyfir forriti að hringja í símanúmer án íhlutunar notanda. Þetta getur haft í för með sér óumbeðin gjöld og símtöl. Athugaðu að þetta leyfir forritinu ekki að hringja í neyðarnúmer. Spilliforrit geta stofnað til kostnaðar fyrir þig með því að hringja símtöl án þinnar heimildar."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"fá aðgang að IMS-símtalsþjónustu"</string>
diff --git a/core/res/res/values-it/strings.xml b/core/res/res/values-it/strings.xml
index ee1b67d..ece503d 100644
--- a/core/res/res/values-it/strings.xml
+++ b/core/res/res/values-it/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Consente all\'applicazione di scattare foto e riprendere video con la fotocamera. Questa autorizzazione consente all\'applicazione di utilizzare la fotocamera in qualsiasi momento senza la tua conferma."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"controllo vibrazione"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Consente all\'applicazione di controllare la vibrazione."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"controllo flash"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Consente all\'applicazione di controllare il flash."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"chiamata diretta n. telefono"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Consente all\'applicazione di chiamare numeri di telefono senza il tuo intervento. Ciò può comportare chiamate o addebiti imprevisti. Tieni presente che ciò non consente all\'applicazione di chiamare numeri di emergenza. Applicazioni dannose potrebbero generare dei costi effettuando chiamate senza la tua conferma."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"Accesso al servizio di chiamata IMS"</string>
diff --git a/core/res/res/values-iw/strings.xml b/core/res/res/values-iw/strings.xml
index df0471e..144afc0 100644
--- a/core/res/res/values-iw/strings.xml
+++ b/core/res/res/values-iw/strings.xml
@@ -356,8 +356,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"מאפשר לאפליקציה לצלם תמונות וסרטונים באמצעות המצלמה. אישור זה מאפשר לאפליקציה להשתמש במצלמה בכל עת ללא אישורך."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"שליטה ברטט"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"מאפשר לאפליקציה לשלוט ברטט."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"שליטה בפנס"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"מאפשר לאפליקציה לשלוט בפנס."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"התקשר ישירות למספרי טלפון"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"מאפשר לאפליקציה להתקשר למספרי טלפון ללא התערבותך. פעולה זו עשויה לגרום לשיחות או לחיובים לא צפויים. שים לב שהדבר לא מאפשר לאפליקציה להתקשר למספרי חירום. אפליקציות זדוניות עשויות לגרום לעלויות על ידי ביצוע שיחות ללא התערבותך."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"‏גישה אל שירות שיחות IMS"</string>
diff --git a/core/res/res/values-ja/strings.xml b/core/res/res/values-ja/strings.xml
index 764e0cf..edfab22 100644
--- a/core/res/res/values-ja/strings.xml
+++ b/core/res/res/values-ja/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"カメラでの写真と動画の撮影をアプリに許可します。これにより、アプリが確認なしでいつでもカメラを使用できるようになります。"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"バイブレーションの制御"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"バイブレーションの制御をアプリに許可します。"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ライトのコントロール"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"ライトの制御をアプリに許可します。"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"電話番号発信"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"電話番号への自動発信をアプリに許可します。これにより、予期せぬ発信や料金が発生する可能性があります。なお、緊急通報番号への発信は許可されません。悪意のあるアプリが確認なしで発信し、料金が発生する恐れがあります。"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS通話サービスへのアクセス"</string>
diff --git a/core/res/res/values-ka-rGE/strings.xml b/core/res/res/values-ka-rGE/strings.xml
index 0fa786c..ffdd31c 100644
--- a/core/res/res/values-ka-rGE/strings.xml
+++ b/core/res/res/values-ka-rGE/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"აპს შეეძლება კამერით სურათისა და ვიდეოს გადაღება. ეს ნებართვა აპს უფლებას აძლევს, ნებისმიერ დროს გამოიყენოს კამერა თქვენი დადასტურების გარეშე."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"ვიბრაციის კონტროლი"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"აპს შეეძლება, მართოს ვიბრირება."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ფანრის მართვა"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"აპს შეეძლება, მართოს განათება."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"პირდაპირი დარეკვა ტელეფონის ნომრებზე"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"აპს შეეძლება დარეკოს ტელეფონის ნომრებზე თქვენი ჩარევის გარეშე. ამან შესაძლოა გამოიწვიოს თქვენს სატელეფონი ქვითარზე მოულოდნელი ხარჯებისა და ზარების გაჩენა. გაითვალისწინეთ, რომ აპს გადაუდებელი დახმარების ნომრებზე დარეკვა არ შეუძლია. მავნე აპებს შეეძლება თქვენი დადასტურების გარეშე ზარების განხორციელება და შესაბამისი საფასურის გადახდაც მოგიწევთ."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS ზარების სერვისზე წვდომა"</string>
diff --git a/core/res/res/values-kk-rKZ/strings.xml b/core/res/res/values-kk-rKZ/strings.xml
index 275e5bc..ff58eaa 100644
--- a/core/res/res/values-kk-rKZ/strings.xml
+++ b/core/res/res/values-kk-rKZ/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Қолданбаға камераны қолданып, фотосурет немесе бейне жазу мүмкіндігін береді. Бұл рұқсат камераны кез келген уақытта сіздің құптауыңызды қажет етпей қолдану мүмкіндігін береді."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"тербелісті басқару"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Қолданбаға вибраторды басқаруға рұқсат береді."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"сигналдық шамды басқару"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Қолданбаға қалта шамын басқаруға рұқсат береді."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"нөмірлерге тікелей телефон шалу"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Қолданбаға сіздің қатысуыңызсыз қоңырау шалу мүмкіндігін береді. Нәтижесінде қосымша төлем немесе күтпеген қоңырау алуыңыз мүмкін. Есіңізде болсын, қолданба төтенше байланыстарға қоңырау шала алмайды. Залалды қолданбалар сіздің рұқсатыңызсыз қоңыраулар шалып, күтпеген төлемдерге себеп болуы мүмкін."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS қоңырау қызметін пайдалану"</string>
diff --git a/core/res/res/values-km-rKH/strings.xml b/core/res/res/values-km-rKH/strings.xml
index 96abf45..261212f 100644
--- a/core/res/res/values-km-rKH/strings.xml
+++ b/core/res/res/values-km-rKH/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"ឲ្យ​កម្មវិធី​ថត​រូប និង​វីដេអូ​ដោយ​ប្រើ​ម៉ាស៊ីន​ថត។ វា​ឲ្យ​កម្មវិធី​​ប្រើ​ម៉ាស៊ីន​ថត​នៅ​ពេល​​ណាមួយ​ដោយ​គ្មាន​ការ​បញ្ជាក់​របស់​អ្នក។"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"ពិនិត្យ​ការ​ញ័រ"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"ឲ្យ​កម្មវិធី​គ្រប់គ្រង​កម្មវិធី​ញ័រ។"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ត្រួតពិនិត្យ​ពិល"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"ឲ្យ​កម្មវិធី​ពិនិត្យ​ពិល។"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ហៅ​លេខ​ទូរស័ព្ទ​ដោយ​ផ្ទាល់"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"ឲ្យ​កម្មវិធី​ហៅ​លេខ​ទូរស័ព្ទ​ដោយ​គ្មាន​សកម្មភាព​របស់​អ្នក។​ វា​អាច​កាត់​លុយ​ ឬ​ហៅ​ដោយ​មិន​រំពឹង​ទុក។ ចំណាំ​ថា​ វា​មិន​អនុញ្ញាត​ឲ្យ​កម្មវិធី​ហៅ​លេខ​ពេល​អាសន្ន​ទេ។ កម្មវិធី​ព្យាបាទ​អាច​កាត់​លុយ​របស់​អ្នក​ ដោយ​ធ្វើការ​ហៅ​ដោយ​គ្មាន​ការ​បញ្ជាក់​របស់​អ្នក។"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"ចូលដំណើរការសេវាកម្មការហៅតាម IMS"</string>
diff --git a/core/res/res/values-kn-rIN/strings.xml b/core/res/res/values-kn-rIN/strings.xml
index d0dac23..f083702 100644
--- a/core/res/res/values-kn-rIN/strings.xml
+++ b/core/res/res/values-kn-rIN/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"ಕ್ಯಾಮರಾ ಮೂಲಕ ಚಿತ್ರಗಳು ಮತ್ತು ವೀಡಿಯೊಗಳನ್ನು ಸೆರೆಹಿಡಿಯಲು ಅಪ್ಲಿಕೇಶನ್‍‍ಗೆ ಅವಕಾಶ ಮಾಡಿಕೊಡುತ್ತದೆ. ಈ ಅನುಮತಿಯು ನಿಮ್ಮ ಖಾತರಿ ಇಲ್ಲದೆಯೇ ಯಾವುದೇ ಸಮಯದಲ್ಲಿ ಕ್ಯಾಮರಾವನ್ನು ಬಳಸಲು ಅಪ್ಲಿಕೇಶನ್‍‍ಗೆ ಅನುಮತಿಸುತ್ತದೆ."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"ವೈಬ್ರೇಷನ್‌‌ ನಿಯಂತ್ರಿಸಿ"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"ವೈಬ್ರೇಟರ್‌ ನಿಯಂತ್ರಿಸಲು ಅಪ್ಲಿಕೇಶನ್‌ಗೆ ಅನುಮತಿಸುತ್ತದೆ."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ಫ್ಲ್ಯಾಶ್‌ಲೈಟ್ ನಿಯಂತ್ರಿಸಿ"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"ಫ್ಲ್ಯಾಶ್‌ಲೈಟ್ ನಿಯಂತ್ರಿಸಲು ಅಪ್ಲಿಕೇಶನ್‌‌ಗೆ ಅನುಮತಿಸುತ್ತದೆ."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ಫೋನ್ ಸಂಖ್ಯೆಗಳಿಗೆ ನೇರವಾಗಿ ಕರೆ ಮಾಡಿ"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"ನಿಮ್ಮ ಹಸ್ತಕ್ಷೇಪ ಇಲ್ಲದೆಯೇ ಫೋನ್‍ ಸಂಖ್ಯೆಗಳಿಗೆ ಕರೆ ಮಾಡಲು ಅಪ್ಲಿಕೇಶನ್‍‍ಗೆ ಅನುಮತಿಸುತ್ತದೆ. ಇದು ಅನಿರೀಕ್ಷಿತ ಶುಲ್ಕಗಳು ಅಥವಾ ಕರೆಗಳಿಗೆ ಕಾರಣವಾಗಬಹುದು. ತುರ್ತು ಸಂಖ್ಯೆಗಳಿಗೆ ಕರೆಮಾಡಲು ಈ ಅಪ್ಲಿಕೇಶನ್‍ ಅನುಮತಿಸುವುದಿಲ್ಲ ಎಂಬುದು ಗಮನದಲ್ಲಿರಲಿ. ದುರುದ್ದೇಶಪೂರಿತ ಅಪ್ಲಿಕೇಶನ್‍‍ಗಳು ನಿಮ್ಮ ಖಾತರಿ ಇಲ್ಲದೆಯೇ ಕರೆಗಳನ್ನು ಮಾಡುವುದರ ಮೂಲಕ ನಿಮ್ಮ ಹಣ ಖರ್ಚಾಗಬಹುದು."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS ಕರೆ ಸೇವೆಯನ್ನು ಪ್ರವೇಶಿಸಿ"</string>
diff --git a/core/res/res/values-ko/strings.xml b/core/res/res/values-ko/strings.xml
index b1b4588..c8f08c7 100644
--- a/core/res/res/values-ko/strings.xml
+++ b/core/res/res/values-ko/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"앱이 카메라로 사진과 동영상을 찍을 수 있도록 허용합니다. 이 권한을 사용하면 앱이 언제든지 사용자의 확인 없이 카메라를 사용할 수 있습니다."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"진동 제어"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"앱이 진동을 제어할 수 있도록 허용합니다."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"카메라 플래시 제어"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"앱이 카메라 플래시를 제어할 수 있도록 허용합니다."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"전화번호 자동 연결"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"앱이 사용자의 조작 없이 전화번호로 전화를 걸 수 있도록 허용합니다. 이 경우 예상치 못한 통화 요금이 부과될 수 있습니다. 앱이 비상 전화를 걸도록 하는 권한은 주어지지 않습니다. 악성 앱이 사용자의 확인 없이 전화를 걸어 요금이 부과될 수 있습니다."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS 통화 서비스에 액세스"</string>
diff --git a/core/res/res/values-ky-rKG/strings.xml b/core/res/res/values-ky-rKG/strings.xml
index 7644a9b..4d84933 100644
--- a/core/res/res/values-ky-rKG/strings.xml
+++ b/core/res/res/values-ky-rKG/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Колдонмого камера аркылуу видео жана сүрөт тартуу уруксатын берет. Бул уруксат, камераны каалаган убакта, сиздин ырастооңузсуз колдонуу уруксатын берет."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"титирөөнү башкаруу"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Колдонмого дирилдегичти көзөмөлдөө мүмкүнчүлүгүн берет."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"кол чыракты көзөмөлдөө"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Колдонмого колчыракты көзөмөлдөө мүмкүнчүлүгүн берет."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"телефон номерлерине түз чалуу"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Колдонмого сиздин катышууңузсуз телефон номурларга чалуу уруксатын берет. Бул сиз күтпөгөн чыгымдарга же чалууларга алып келиши мүмкүн. Бул куткаруучулардын номурларына чалууга уруксат бербей тургандыгын эске алыңыз. Зыяндуу колдонмолор, сиздин ырастооңузсуз чалууларды аткарып, көп чыгымдарга себепкер болушу мүмкүн."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS чалуу кызматына мүмкүнчүлүк алуу"</string>
diff --git a/core/res/res/values-land/config.xml b/core/res/res/values-land/config.xml
new file mode 100644
index 0000000..7308dc5
--- /dev/null
+++ b/core/res/res/values-land/config.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License
+  -->
+<resources>
+    <integer name="config_dockedStackDividerSnapMode">2</integer>
+</resources>
\ No newline at end of file
diff --git a/core/res/res/values-lo-rLA/strings.xml b/core/res/res/values-lo-rLA/strings.xml
index a5ff8d1..12d67bb 100644
--- a/core/res/res/values-lo-rLA/strings.xml
+++ b/core/res/res/values-lo-rLA/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"ອະນຸຍາດໃຫ້ແອັບຯຖ່າຍຮູບ ແລະວິດີໂອດ້ວຍກ້ອງຖ່າຍຮູບ. ການອະນຸຍາດນີ້ຈະອານຸຍາດໃຫ້ແອັບຯ ສາມາດໃຊ້ກ້ອງຖ່າຍຮູບໄດ້ຕະຫລອດເວລາ ໂດຍບໍ່ຕ້ອງຖ້າການຢືນຢັນຈາກທ່ານ."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"ຄວບຄຸມການສັ່ນ"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"ອະນຸຍາດໃຫ້ແອັບຯຄວບຄຸມໂຕສັ່ນ."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ຄວບຄຸມໄຟແຟລດ"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"ອະນຸຍາດໃຫ້ແອັບຯ ຄວບຄຸມໄຟແຟລດ."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ໂທຫາເບີໂທລະສັບໂດຍກົງ"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"ອະນຸຍາດໃຫ້ແອັບຯໂທຫາເບີໂທລະສັບໄດ້ ໂດຍບໍ່ຕ້ອງຖ້າການດຳເນີນການໃດໆຈາກທ່ານ. ຄຸນສົມບັດນີ້ອາດກໍ່ໃຫ້ເກີດຄ່າໃຊ້ຈ່າຍໃນການໂທທີ່ບໍ່ຄາດຄິດໄດ້. ໝາຍເຫດ: ຄຸນສົມບັດນີ້ບໍ່ໄດ້ເປັນການອະນຸຍາດໃຫ້ແອັບຯ ສາມາດໂທຫາເບີສຸກເສີນ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດເຮັດໃຫ້ທ່ານ ຕ້ອງເສຍຄ່າໂທໂດຍທີ່ບໍ່ໄດ້ຄາດຄິດ."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"ເຂົ້າ​ຫາ​ການ​ບໍ​ລິ​ການ​ໂທ IMS"</string>
diff --git a/core/res/res/values-lt/strings.xml b/core/res/res/values-lt/strings.xml
index f59e754..e35edd6 100644
--- a/core/res/res/values-lt/strings.xml
+++ b/core/res/res/values-lt/strings.xml
@@ -356,8 +356,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Leidžiama programai fotografuoti ir filmuoti kamera. Šis leidimas suteikia teisę programai naudoti kamerą bet kada be jūsų patvirtinimo."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"valdyti vibraciją"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Leidžiama programai valdyti vibravimą."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"valdyti šviesos signalą"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Leidžiama programai valdyti šviesos signalą."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"skambinti tiesiogiai telefono numeriais"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Leidžiama programai skambinti telefonų numeriais be jūsų įsikišimo. Dėl to gali atsirasti nenumatytų apmokestinimų ar skambučių. Atminkite, kad programai neleidžiama skambinti pagalbos telefonų numeriais. Kenkėjiškos programos gali skambinti be jūsų patvirtinimo, o dėl to jums gali būti taikomi mokesčiai."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"pasiekti IMS skambučių paslaugą"</string>
diff --git a/core/res/res/values-lv/strings.xml b/core/res/res/values-lv/strings.xml
index d1993ed..de02a4f 100644
--- a/core/res/res/values-lv/strings.xml
+++ b/core/res/res/values-lv/strings.xml
@@ -355,8 +355,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Ļauj lietotnei uzņemt attēlus un videoklipus ar kameru. Ar šo atļauju lietotne var jebkurā brīdī izmantot kameru bez jūsu apstiprinājuma."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"kontrolēt vibrosignālu"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Ļauj lietotnei kontrolēt vibrosignālu."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"kontrolēt uzliesmojumu"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Ļauj lietotnei kontrolēt zibspuldzi."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"tieši zvanīt uz tālruņa numuriem"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Ļauj lietotnei zvanīt uz tālruņa numuriem bez jūsu iejaukšanās. Tas var radīt neparedzētas izmaksas vai zvanus. Ņemiet vērā, ka lietotnei nav atļauts zvanīt uz tālruņa numuriem ārkārtas situācijām. Ļaunprātīgas lietotnes var radīt jums izmaksas, veicot zvanus bez jūsu apstiprinājuma."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"piekļūt tūlītējās ziņojumapmaiņas pakalpojumam, lai veiktu zvanus"</string>
diff --git a/core/res/res/values-mk-rMK/strings.xml b/core/res/res/values-mk-rMK/strings.xml
index 672c2b5..96a29a5 100644
--- a/core/res/res/values-mk-rMK/strings.xml
+++ b/core/res/res/values-mk-rMK/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Овозможува апликацијата да прави фотографии и да снима видеа со камерата. Оваа дозвола овозможува апликацијата да ја користи камерата во кое било време без ваша потврда."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"контролирај вибрации"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Дозволува апликацијата да ги контролира вибрациите."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"контролирај сијаличка"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Дозволува апликацијата да ја контролира батериската ламба."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"директно избирај телефонски броеви"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Овозможува апликацијата да повикува телефонски броеви без ваша интервенција. Ова може да предизвика неочекувани трошоци или повици. Имајте на ум дека ова не дозволува апликацијата да повикува броеви на служби за итна помош. Злонамерните апликации може да ве чинат пари поради повици без ваша потврда."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"пристапи до услугата за повици IMS"</string>
diff --git a/core/res/res/values-ml-rIN/strings.xml b/core/res/res/values-ml-rIN/strings.xml
index c6f6698..f6869e3 100644
--- a/core/res/res/values-ml-rIN/strings.xml
+++ b/core/res/res/values-ml-rIN/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"ക്യാമറ ഉപയോഗിച്ച് ചിത്രങ്ങളും വീഡിയോകളും എടുക്കാൻ അപ്ലിക്കേഷനെ അനുവദിക്കുന്നു. നിങ്ങളുടെ സ്ഥിരീകരണമില്ലാതെ ഏതുസമയത്തും ക്യാമറ ഉപയോഗിക്കാൻ ഈ അനുമതി അപ്ലിക്കേഷനെ അനുവദിക്കുന്നു."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"വൈബ്രേറ്റുചെയ്യൽ നിയന്ത്രിക്കുക"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"വൈബ്രേറ്റർ നിയന്ത്രിക്കുന്നതിന് അപ്ലിക്കേഷനെ അനുവദിക്കുന്നു."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ടോർച്ച് നിയന്ത്രിക്കുക"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"ഫ്ലാഷ്ലൈറ്റിനെ നിയന്ത്രിക്കുന്നതിന് അപ്ലിക്കേഷനെ അനുവദിക്കുന്നു."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ഫോൺ നമ്പറുകളിലേക്ക് നേരിട്ട് വിളിക്കുക"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"നിങ്ങളുടെ ഇടപെടൽ ഇല്ലാതെ ഫോൺ നമ്പറുകളിലേക്ക് കോൾ ചെയ്യാൻ അപ്ലിക്കേഷനെ അനുവദിക്കുന്നു. ഇത് അപ്രതീക്ഷിത നിരക്കുകൾക്കോ കോളുകൾക്കോ ഇടയാക്കാം. ഇത് അടിയന്തര നമ്പറുകളിലേക്ക് വിളിക്കാൻ അപ്ലിക്കേഷനെ അനുവദിക്കില്ലെന്ന കാര്യം ശ്രദ്ധിക്കുക. ക്ഷുദ്രകരമായ അപ്ലിക്കേഷനുകൾ നിങ്ങളുടെ സ്ഥിരീകരണമില്ലാതെ കോളുകൾ ചെയ്യുന്നത് പണച്ചെലവിനിടയാക്കാം."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS കോൾ സേവനം ആക്സസ് ചെയ്യുക"</string>
diff --git a/core/res/res/values-mn-rMN/strings.xml b/core/res/res/values-mn-rMN/strings.xml
index c42beca..d982ece 100644
--- a/core/res/res/values-mn-rMN/strings.xml
+++ b/core/res/res/values-mn-rMN/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Апп нь камераар зураг авах болон видео бичих боломжтой. Энэ зөвшөөрөл нь апп-д ямар ч үед таны зөвшөөрөлгүйгээр камер ашиглах боломжийг олгоно."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"чичиргээг удирдах"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Апп нь чичиргээг удирдах боломжтой."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"гар чийдэн удирдах"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Апп нь гар чийдэнг удирдах боломжтой."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"утасны дугаарт шууд дуудлага хийх"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Апп нь таны оролцоогүйгээр дуудлага хийх боломжтой. Энэ нь төлөвлөгдөөгүй төлбөрт оруулах эсвэл дуудлага хийнэ. Энэ нь апп-г яаралтай дугаарт дуудлага хийхйг зөвшөөрөхгүй. Хортой апп нь таны зөвшөөрөлгүйгээр дуудлага хийж таныг төлбөрт оруулж болзошгүй"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS дуудлагын үйлчилгээнд хандах"</string>
diff --git a/core/res/res/values-mr-rIN/strings.xml b/core/res/res/values-mr-rIN/strings.xml
index 8bc86e6..4087199 100644
--- a/core/res/res/values-mr-rIN/strings.xml
+++ b/core/res/res/values-mr-rIN/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"कॅमेर्‍यासह चित्रे आणि व्हिडिओ घेण्यासाठी अॅप ला अनुमती देते. ही परवानगी आपल्या पुष्टीकरणाशिवाय कोणत्याही वेळी कॅमेरा वापरण्यासाठी अॅप ला परवानगी देते."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"कंपन नियंत्रित करा"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"अॅप ला व्हायब्रेटर नियंत्रित करण्यासाठी अनुमती देते."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"फ्लॅशलाइट नियंत्रित करा"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"फ्लॅशलाइट नियंत्रित करण्यासाठी अॅप ला अनुमती देते."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"फोन नंबरवर प्रत्यक्ष कॉल करा"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"आपल्या हस्तक्षेपाशिवाय फोन नंबरवर कॉल करण्यासाठी अॅप ला अनुमती देते. यामुळे अनपेक्षित शुल्क किंवा कॉल लागू शकतात. लक्षात ठेवा की हे आणीबाणीच्या नंबरवर कॉल करण्यासाठी अॅप ला अनुमती देत नाही. दुर्भावनापूर्ण अॅप्स नी आपल्या पुष्टिकरणाशिवाय कॉल केल्यामुळे आपले पैसे खर्च होऊ शकतात."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS कॉल सेवेमध्‍ये प्रवेश करा"</string>
diff --git a/core/res/res/values-ms-rMY/strings.xml b/core/res/res/values-ms-rMY/strings.xml
index f1249d6..0923e91 100644
--- a/core/res/res/values-ms-rMY/strings.xml
+++ b/core/res/res/values-ms-rMY/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Membenarkan apl mengambil gambar dan video menggunakan kamera. Kebenaran ini membenarkan apl untuk menggunakan kamera pada bila-bila masa tanpa pengesahan anda."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"kawal getaran"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Membenarkan apl mengawal penggetar."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"mengawal lampu suluh"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Membenarkan apl mengawal lampu suluh."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"panggil terus nombor telefon"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Membenarkan apl memanggil nombor telefon tanpa campur tangan anda. Ini mungkin menyebabkan caj atau panggilan yang di luar jangkaan. Apl hasad boleh menyebabkan anda kerugian wang dengan membuat panggilan tanpa pengesahan anda."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"akses perkhidmatan panggilan IMS"</string>
diff --git a/core/res/res/values-my-rMM/strings.xml b/core/res/res/values-my-rMM/strings.xml
index 3393e12..3ef7e6c 100644
--- a/core/res/res/values-my-rMM/strings.xml
+++ b/core/res/res/values-my-rMM/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"အပလီကေးရှင်းအား အလိုအလျောက် ဓာတ်ပုံရိုက်ခွင့်၊ ဗီဒီယို ရိုက်ကူးခွင့် ပြုပါ။ ဒီခွင့်ပြုချက်က အပလီကေးရှင်းကို အချိန်မရွေး ကင်မရာအား ခွင့်ပြုချက် မလိုအပ်ပဲ သုံးခွင့်ပြုပါသည်။"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"တုန်ခုန်မှုအား ထိန်းချုပ်ခြင်း"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"appအား တုန်ခါစက်ကို ထိန်းချုပ်ခွင့် ပြုသည်။"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ဓါတ်မီးအား ထိန်းသိမ်းရန်"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"appအား ကား ဖလက်ရှမီးကို ထိန်းချုပ်ခွင့် ပြုသည်။"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ဖုန်းနံပါတ်များကိုတိုက်ရိုက်ခေါ်ဆိုခြင်း"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"အပလီကေးရှင်းအား အလိုအလျောက် ဖုန်းခေါ်ခွင့် ပြုပါ။ မလိုအပ်သော ဖုန်းခ များ ဖြစ်ပေါ်နိုင်ပါသည်။ ဒီခွင့်ပြုခြင်းမှာ အရေးပေါ်ဖုန်းခေါ်ခြင်း မပါဝင်ပါ။ သံသယဖြစ်စရာ အပလီကေးရှင်းများက သင့်မသိပဲ ဖုန်းခေါ်ခြင်းဖြင့် ဖုန်းခ ပိုမိုကျနိုင်ပါသည်။"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS ဖုန်းခေါ်ဆိုမှု ဝန်ဆောင်ဌာန ဝင်ကြည့်ပါ"</string>
diff --git a/core/res/res/values-nb/strings.xml b/core/res/res/values-nb/strings.xml
index e1ad565..cd65d85 100644
--- a/core/res/res/values-nb/strings.xml
+++ b/core/res/res/values-nb/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Appen tillates å ta bilder og filme med kameraet. Det betyr at appen kan bruke kameraet når som helst uten bekreftelse fra deg."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"kontrollere vibreringen"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Lar appen kontrollere vibreringsfunksjonen."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"kontrollere lommelykten"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Lar appen kontrollere lommelykten."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ringe telefonnummer direkte"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Lar appen ringe telefonnumre uten at du gjør noe. Dette kan resultere i uventede oppringninger og kostnader. Appen kan imidlertid ikke ringe nødnumre. Merk at skadelige apper kan påføre deg kostnader ved å ringe uten bekreftelse fra deg."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"få tilgang til nettprattjenesten for ringing"</string>
diff --git a/core/res/res/values-ne-rNP/strings.xml b/core/res/res/values-ne-rNP/strings.xml
index f94222b..301094b 100644
--- a/core/res/res/values-ne-rNP/strings.xml
+++ b/core/res/res/values-ne-rNP/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"अनुप्रयोगलाई क्यामेरासँग तस्बिर र भिडियोहरू लिन अनुमति दिन्छ। यस अनुमतिले अनुप्रयोगलाई तपाईंको पुष्टिकरण बिना कुनै पनि समयमा क्यामेरा प्रयोग गर्न स्वीकृति दिन्छ।"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"कम्पन नियन्त्रण गर्नुहोस्"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"अनुप्रयोगलाई भाइब्रेटर नियन्त्रण गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"फ्ल्यासलाईट नियन्त्रण गर्नुहोस्"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"फ्ल्यास प्रकाशलाई नियन्त्रण गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"फोन नम्बरहरूमा सिधै कल गर्नुहोस्"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"तपाईँको हस्तक्षेप बेगरै फोन नम्बर कल गर्न अनुप्रयोगलाई अनुमति दिन्छ। यसले अनपेक्षित शुल्क वा कलहरू गराउन सक्छ। यसले अनुप्रयोगलाई आपतकालीन नम्बरहरू कल गर्न अनुमति दिँदैन विचार गर्नुहोस्। खराब अनुप्रयोगहरूले तपाईँको स्वीकार बिना कलहरू गरेर तपाईँलाई बढी पैसा तिराउन सक्छ।"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS कल सेवा पहुँच गर्नुहोस्"</string>
diff --git a/core/res/res/values-nl/strings.xml b/core/res/res/values-nl/strings.xml
index 1bef95d..1407991 100644
--- a/core/res/res/values-nl/strings.xml
+++ b/core/res/res/values-nl/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Hiermee kan de app foto\'s en video\'s maken met de camera. Met deze toestemming kan de app de camera altijd gebruiken, zonder je bevestiging."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"trilling beheren"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Hiermee kan de app de trilstand beheren."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"zaklamp bedienen"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Hiermee kan de app de zaklamp bedienen."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"telefoonnummers rechtstreeks bellen"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Hiermee kan de app zonder je tussenkomst telefoonnummers bellen. Dit kan tot onverwachte kosten of oproepen leiden. De app kan hiermee geen noodnummers bellen. Schadelijke apps kunnen u geld kosten door nummers te bellen zonder om je bevestiging te vragen."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"toegang tot IMS-service voor bellen"</string>
diff --git a/core/res/res/values-pa-rIN/strings.xml b/core/res/res/values-pa-rIN/strings.xml
index 168c66f..39f20f5 100644
--- a/core/res/res/values-pa-rIN/strings.xml
+++ b/core/res/res/values-pa-rIN/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"ਐਪ ਨੂੰ ਕੈਮਰੇ ਨਾਲ ਤਸਵੀਰਾਂ ਅਤੇ ਵੀਡੀਓ ਲੈਣ ਦੀ ਆਗਿਆ ਦਿੰਦਾ ਹੈ। ਇਹ ਅਨੁਮਤੀ ਐਪ ਨੂੰ ਤੁਹਾਡੀ ਪੁਸ਼ਟੀ ਤੋਂ ਬਿਨਾਂ ਕਿਸੇ ਵੀ ਸਮੇਂ ਕੈਮਰਾ ਵਰਤਣ ਦੀ ਆਗਿਆ ਦਿੰਦੀ ਹੈ।"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"ਵਾਈਬ੍ਰੇਸ਼ਨ ਤੇ ਨਿਯੰਤਰਣ ਪਾਓ"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"ਐਪ ਨੂੰ ਵਾਈਬ੍ਰੇਟਰ ਤੇ ਨਿਯੰਤਰਣ ਪਾਉਣ ਦੀ ਆਗਿਆ ਦਿੰਦਾ ਹੈ।"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ਫਲੈਸ਼ਲਾਈਟ ਤੇ ਨਿਯੰਤਰਣ ਪਾਓ"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"ਐਪ ਨੂੰ ਫਲੈਸ਼ਲਾਈਟ ਤੇ ਨਿਯੰਤਰਣ ਪਾਉਣ ਦੀ ਆਗਿਆ ਦਿੰਦਾ ਹੈ।"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ਫੋਨ ਨੰਬਰਾਂ ਤੇ ਸਿੱਧੇ ਕਾਲ ਕਰੋ"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"ਐਪ ਨੂੰ ਤੁਹਾਡੇ ਦਖ਼ਲ ਤੋਂ ਬਿਨਾਂ ਫੋਨ ਨੰਬਰਾਂ ਤੇ ਕਾਲ ਕਰਨ ਦੀ ਆਗਿਆ ਦਿੰਦਾ ਹੈ। ਇਸਦੇ ਸਿੱਟੇ ਵਜੋਂ ਅਕਲਪਿਤ ਖ਼ਰਚੇ ਜਾਂ ਕਾਲਾਂ ਹੋ ਸਕਦੀਆਂ ਹਨ। ਧਿਆਨ ਦਿਓ ਕਿ ਇਹ ਐਪ ਨੂੰ ਐਮਰਜੈਂਸੀ ਨੰਬਰਾਂ ਤੇ ਕਾਲ ਕਰਨ ਦੀ ਆਗਿਆ ਨਹੀਂ ਦਿੰਦਾ। ਖ਼ਰਾਬ ਐਪਸ ਤੁਹਾਡੀ ਪੁਸ਼ਟੀ ਤੋਂ ਬਿਨਾਂ ਕਾਲਾਂ ਕਰਕੇ ਤੁਹਾਨੂੰ ਖ਼ਰਚੇ ਪਾ ਸਕਦੇ ਹਨ।"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS ਕਾਲ ਸੇਵਾ ਤੱਕ ਪਹੁੰਚ"</string>
diff --git a/core/res/res/values-pl/strings.xml b/core/res/res/values-pl/strings.xml
index 80ef7df..f3e50b5 100644
--- a/core/res/res/values-pl/strings.xml
+++ b/core/res/res/values-pl/strings.xml
@@ -356,8 +356,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Pozwala aplikacji na robienie zdjęć i nagrywanie filmów przy użyciu aparatu. Aplikacja z tym uprawnieniem może użyć aparatu w dowolnym momencie bez Twojego potwierdzenia."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"sterowanie wibracjami"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Pozwala aplikacji na sterowanie wibracjami."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"kontrolowanie latarki"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Pozwala aplikacji na sterowanie latarką."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"bezpośrednie wybieranie numerów telefonów"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Pozwala aplikacji na dzwonienie pod numery telefonów bez Twojej wiedzy. Może to skutkować nieoczekiwanymi opłatami lub połączeniami. Aplikacja nie może dzwonić pod numery alarmowe. Złośliwe aplikacje mogą generować koszty, wykonując połączenia bez Twojego potwierdzenia."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"usługa telefoniczna z dostępem do komunikatora"</string>
diff --git a/core/res/res/values-pt-rBR/strings.xml b/core/res/res/values-pt-rBR/strings.xml
index 11e060a..89bbbe8 100644
--- a/core/res/res/values-pt-rBR/strings.xml
+++ b/core/res/res/values-pt-rBR/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Permite que o app tire fotos e filme vídeos com a câmera. Esta permissão autoriza o app a usar a câmera a qualquer momento sem sua confirmação."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"controlar vibração"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Permite que o app controle a vibração."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"controlar lanterna"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Permite que o app controle a lanterna."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ligar diretamente para números de telefone"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Permite que o app ligue para números de telefone sem sua intervenção. Isso pode resultar em cobranças ou chamadas inesperadas. Esta opção não permite que o app ligue para números de emergência. Apps maliciosos podem gerar custos com chamadas feitas sem sua confirmação."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"acessar serviço de mensagens instantâneas para chamadas"</string>
diff --git a/core/res/res/values-pt-rPT/strings.xml b/core/res/res/values-pt-rPT/strings.xml
index d76133a..f559dbb 100644
--- a/core/res/res/values-pt-rPT/strings.xml
+++ b/core/res/res/values-pt-rPT/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Permite que a aplicação tire fotografias e grave vídeos com a câmara. Esta autorização permite que a aplicação utilize a câmara sem a sua confirmação em qualquer altura."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"controlar vibração"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Permite à aplicação controlar o vibrador."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"controlar lanterna"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Permite à aplicação controlar a lanterna."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"marcar números de telefone diretamente"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Permite que a aplicação ligue para números de telefone sem a intervenção do utilizador. Esta ação pode resultar em cobranças ou chamadas inesperadas. Tenha em atenção que isto não permite que a aplicação ligue para números de emergência. As aplicações maliciosas podem fazer com que incorra em custos, fazendo chamadas sem a sua confirmação."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"aceder ao serviço de chamadas IMS"</string>
@@ -1478,7 +1476,7 @@
       <item quantity="one">Durante 1 h</item>
     </plurals>
     <string name="zen_mode_until" msgid="7336308492289875088">"Até às <xliff:g id="FORMATTEDTIME">%1$s</xliff:g>"</string>
-    <string name="zen_mode_alarm" msgid="9128205721301330797">"Até às <xliff:g id="FORMATTEDTIME">%1$s</xliff:g> (próximo alarme)"</string>
+    <string name="zen_mode_alarm" msgid="9128205721301330797">"Até <xliff:g id="FORMATTEDTIME">%1$s</xliff:g> (próximo alarme)"</string>
     <string name="zen_mode_forever" msgid="7420011936770086993">"Até que o utilizador desative"</string>
     <string name="zen_mode_forever_dnd" msgid="3792132696572189081">"Até desativar Não incomodar"</string>
     <string name="zen_mode_rule_name_combination" msgid="191109939968076477">"<xliff:g id="FIRST">%1$s</xliff:g>/<xliff:g id="REST">%2$s</xliff:g>"</string>
diff --git a/core/res/res/values-pt/strings.xml b/core/res/res/values-pt/strings.xml
index 11e060a..89bbbe8 100644
--- a/core/res/res/values-pt/strings.xml
+++ b/core/res/res/values-pt/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Permite que o app tire fotos e filme vídeos com a câmera. Esta permissão autoriza o app a usar a câmera a qualquer momento sem sua confirmação."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"controlar vibração"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Permite que o app controle a vibração."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"controlar lanterna"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Permite que o app controle a lanterna."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ligar diretamente para números de telefone"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Permite que o app ligue para números de telefone sem sua intervenção. Isso pode resultar em cobranças ou chamadas inesperadas. Esta opção não permite que o app ligue para números de emergência. Apps maliciosos podem gerar custos com chamadas feitas sem sua confirmação."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"acessar serviço de mensagens instantâneas para chamadas"</string>
diff --git a/core/res/res/values-ro/strings.xml b/core/res/res/values-ro/strings.xml
index 8a78f17..4086e69 100644
--- a/core/res/res/values-ro/strings.xml
+++ b/core/res/res/values-ro/strings.xml
@@ -355,8 +355,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Permite aplicației să realizeze fotografii și videoclipuri cu camera foto. Cu această permisiune aplicația utilizează camera foto oricând și fără confirmare."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"controlează vibrarea"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Permite aplicației să controleze mecanismul de vibrare."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"control lanternă"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Permite aplicației să controleze lanterna."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"apelare directă numere de telefon"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Permite aplicației să apeleze numere de telefon fără intervenţia dvs. Acest lucru poate determina apariția unor taxe sau a unor apeluri neaşteptate. Cu această permisiune aplicația nu poate apela numerele de urgenţă. Aplicaţiile rău intenţionate pot acumula costuri prin efectuarea unor apeluri fără confirmare."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"accesează serviciul de apelare IMS"</string>
diff --git a/core/res/res/values-ru/strings.xml b/core/res/res/values-ru/strings.xml
index 0753e93..ee39b83 100644
--- a/core/res/res/values-ru/strings.xml
+++ b/core/res/res/values-ru/strings.xml
@@ -356,8 +356,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Приложение сможет снимать фотографии и видеоролики с помощью камеры в любое время без вашего разрешения."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"Управление функцией вибросигнала"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Приложение сможет контролировать вибросигналы."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"Управление вспышкой"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Приложение сможет контролировать вспышку."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"Осуществление телефонных вызовов"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Приложение сможет без вашего участия звонить на любой номер телефона. Это не относится к номерам экстренных служб. Вредоносные программы смогут совершать вызовы без вашего разрешения, что может привести к непредвиденным расходам."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"совершение звонков с помощью службы IMS"</string>
diff --git a/core/res/res/values-si-rLK/strings.xml b/core/res/res/values-si-rLK/strings.xml
index d66b245..5364c98 100644
--- a/core/res/res/values-si-rLK/strings.xml
+++ b/core/res/res/values-si-rLK/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"කැමරාවෙන් පින්තූර ගැනීමට සහ වීඩියෝ කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරය මඟින් ඔබගේ අනුදැනුමකින් තොරව ඕනෑම වේලාවකදී කැමරාව භාවිතා කිරීමට යෙදුමට අවසර දෙන්න."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"කම්පනය පාලනය කිරීම"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"කම්පකය පාලනයට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"සැණෙළි ආලෝකය පාලනය කරන්න"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"සැණෙළිය පාලනයට යෙදුමට අවසර දෙන්න."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"දුරකථන අංක වෙත ඍජුවම අමතන්න"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"ඔබගේ මැදිහත් වීමක් නොමැතිව දුරකථන අංක ඇමතීමට යෙදුමට අවසර දෙන්න. මෙහි ප්‍රතිඑලය වන්නේ අනපේක්ෂිත අයකිරීම් හෝ ඇමතුම් ඇතිවීමයි. මෙයන් හදිසි අංක වලට ඇමතුම් ගැනීමට යෙදුමට අවසර නොදෙන බවට සටහන් කරගන්න. ඔබගේ අනුදැනුමක් නොමැතිව ඇමතුම් ගැනීමෙන් අනිෂ්ට යෙදුම් ඔබගේ මුදල් නිකරුණේ වැය කරයි."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS ඇමතුම් සේවාවට පිවිසෙන්න"</string>
diff --git a/core/res/res/values-sk/strings.xml b/core/res/res/values-sk/strings.xml
index 05c8467..90ccd54 100644
--- a/core/res/res/values-sk/strings.xml
+++ b/core/res/res/values-sk/strings.xml
@@ -356,8 +356,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Umožňuje aplikácii fotografovať a nahrávať videá pomocou fotoaparátu. Toto povolenie umožňuje aplikácii používať fotoaparát kedykoľvek a bez vášho potvrdenia."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"ovládať vibrovanie"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Umožňuje aplikácii ovládať vibrácie."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ovládať kontrolku"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Umožňuje aplikácii ovládať svetlo."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"priamo volať na telefónne čísla"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Umožňuje aplikácii volať telefónne čísla bez vášho zásahu. V dôsledku toho sa môžu účtovať neočakávané poplatky alebo sa môžu uskutočniť neočakávané hovory. Toto povolenie neumožňuje aplikácii volať na čísla tiesňového volania."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"prístup k službe volania IMS"</string>
diff --git a/core/res/res/values-sl/strings.xml b/core/res/res/values-sl/strings.xml
index ea5f4c4..4e9b1c5 100644
--- a/core/res/res/values-sl/strings.xml
+++ b/core/res/res/values-sl/strings.xml
@@ -356,8 +356,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Aplikaciji omogoča fotografiranje in snemanje videoposnetkov s kamero. S tem dovoljenjem lahko aplikacija kadar koli uporablja kamero brez vaše potrditve."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"nadzor vibriranja"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Aplikaciji omogoča nadzor vibriranja."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"nadzor svetilke"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Aplikaciji omogoča nadzor svetilke."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"neposredno klicanje telefonskih številk"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Aplikaciji omogoča klicanje telefonskih številk brez vašega posredovanja. Zaradi tega lahko pride do nepričakovanih stroškov ali klicev. Aplikaciji to ne dovoljuje opravljanja klicev v sili. Zlonamerne aplikacije lahko kličejo brez vaše potrditve, kar vas lahko drago stane."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"dostop do storitve za klicanje IMS"</string>
diff --git a/core/res/res/values-sq-rAL/strings.xml b/core/res/res/values-sq-rAL/strings.xml
index 77e0e62..be9c709 100644
--- a/core/res/res/values-sq-rAL/strings.xml
+++ b/core/res/res/values-sq-rAL/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Lejon aplikacion të krijojë fotografi dhe video me kamerën. Kjo leje mundëson përdorimin e kamerës në çdo kohë pa konfirmimin tënd."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"kontrollo dridhjen"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Lejon aplikacionin të kontrollojë dridhësin."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"kontrollo elektrikun"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Lejon aplikacionin të kontrollojë elektrikun."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"telefono drejtpërdrejt numrat e telefonit"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Lejon aplikacionin të telefonojë numra pa ndërhyrjen tënde. Kjo mund të rezultojë në tarifa ose telefonata të papritura. Ki parasysh se kjo nuk e lejon aplikacionin të telefonojë numra urgjence. Aplikacione keqdashëse mund të të kushtojnë para duke kryer telefonata pa konfirmimin tënd."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"qasje në shërbimin e telefonatave IMS"</string>
diff --git a/core/res/res/values-sr/strings.xml b/core/res/res/values-sr/strings.xml
index 2423418..a3618ab 100644
--- a/core/res/res/values-sr/strings.xml
+++ b/core/res/res/values-sr/strings.xml
@@ -355,8 +355,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Дозвољава апликацији да снима слике и видео снимке камером. Ова дозвола омогућава апликацији да у било ком тренутку користи камеру без ваше потврде."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"контрола вибрације"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Дозвољава апликацији да контролише вибрацију."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"контрола осветљења"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Дозвољава апликацији да контролише блиц."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"директно позивање бројева телефона"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Дозвољава апликацији да позива бројеве телефона без ваше дозволе. Ово може да доведе до неочекиваних трошкова или позива. Имајте на уму да ово не дозвољава апликацији да позива бројеве за хитне случајеве. Злонамерне апликације могу да позивају без ваше потврде, што може да доведе до трошкова."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"приступ услузи позива помоћу размене тренутних порука"</string>
diff --git a/core/res/res/values-sv/strings.xml b/core/res/res/values-sv/strings.xml
index cdf252e..b07dc28 100644
--- a/core/res/res/values-sv/strings.xml
+++ b/core/res/res/values-sv/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Tillåter att appen tar bilder och spelar in videor med kameran. Med den här behörigheten tillåts appen att använda kameran när som helst utan ditt godkännande."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"styra vibration"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Tillåter att appen styr vibrationen."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"styra lampa"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Tillåter att appen styr lampan."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ringa telefonnummer direkt"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Tillåter att appen ringer telefonnummer utan någon aktiv åtgärd från dig. Detta kan leda till oväntade avgifter och samtal. Observera att appen inte tillåts ringa nödsamtal. Skadliga appar kan ringa utan ditt godkännande och detta kan kosta pengar."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"tillgång till tjänsten för snabbmeddelanden vid samtal"</string>
diff --git a/core/res/res/values-sw/strings.xml b/core/res/res/values-sw/strings.xml
index 5e618bf..cf0063c 100644
--- a/core/res/res/values-sw/strings.xml
+++ b/core/res/res/values-sw/strings.xml
@@ -356,8 +356,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Inaruhusu programu kupiga picha na video kwa kamera. Kibali hiki kinaruhusu programu kutumia kamera kwa wakati wowote bila uthibitisho wako."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"Kudhibiti mtetemo"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Inaruhusu programu kudhibiti kitingishi."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"dhibiti tochi"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Inaruhusu programu kudhibiti tochi."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"piga simu moja kwa moja kwa nambari za simu"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Inaruhusu programu kupiga nambari za simu bila ya wewe kuingilia kati. Hii inaweza kusababisha gharama zisizotarajiwa au simu. Kumbuka kuwa hii hairuhusu programu kupiga nambari za dharura. Programu hasidi zinaweza kukugharimu pesa kwa kupiga simu bila uthibitisho wako."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"fikia huduma ya simu ya IMS"</string>
@@ -795,7 +793,7 @@
     <string name="save_password_remember" msgid="6491879678996749466">"Kumbuka"</string>
     <string name="save_password_never" msgid="8274330296785855105">"Katu"</string>
     <string name="open_permission_deny" msgid="7374036708316629800">"Hauna idhini ya kufungua ukurasa huu."</string>
-    <string name="text_copied" msgid="4985729524670131385">"Maandishi yamenakiliwa kwenye ubao klipu."</string>
+    <string name="text_copied" msgid="4985729524670131385">"Maandishi yamenakiliwa kwenye ubao wa kunakili."</string>
     <string name="more_item_label" msgid="4650918923083320495">"Zaidi"</string>
     <string name="prepend_shortcut_label" msgid="2572214461676015642">"Menyu+"</string>
     <string name="menu_space_shortcut_label" msgid="2410328639272162537">"mwanya"</string>
diff --git a/core/res/res/values-sw600dp/config.xml b/core/res/res/values-sw600dp/config.xml
index 5a007ce..7f57ded 100644
--- a/core/res/res/values-sw600dp/config.xml
+++ b/core/res/res/values-sw600dp/config.xml
@@ -40,5 +40,6 @@
     <!-- Use a larger scaling span for larger screen devices. -->
     <dimen name="config_minScalingSpan">32mm</dimen>
 
+    <integer name="config_dockedStackDividerSnapMode">1</integer>
 </resources>
 
diff --git a/core/res/res/values-ta-rIN/strings.xml b/core/res/res/values-ta-rIN/strings.xml
index 7e0ab5e..ecefb77 100644
--- a/core/res/res/values-ta-rIN/strings.xml
+++ b/core/res/res/values-ta-rIN/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"கேமரா மூலமாகப் படங்களையும், வீடியோக்களையும் எடுக்க பயன்பாட்டை அனுமதிக்கிறது. உங்கள் உறுதிப்படுத்தல் இன்றி கேமராவை எந்நேரத்திலும் பயன்படுத்தப் பயன்பாட்டை இது அனுமதிக்கிறது."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"அதிர்வைக் கட்டுப்படுத்துதல்"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"அதிர்வைக் கட்டுப்படுத்தப் பயன்பாட்டை அனுமதிக்கிறது."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ஃப்லாஷ்லைட்டை இயக்குதல்"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"ஃப்ளாஷ் லைட்டைக் கட்டுப்படுத்த, பயன்பாட்டை அனுமதிக்கிறது."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"தொலைபேசி எண்களை நேரடியாக அழைத்தல்"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"உங்கள் தலையீட்டின்றி மொபைல் எண்களை அழைக்கப் பயன்பாட்டை அனுமதிக்கிறது. இதன் விளைவாக எதிர்பாராத கட்டணங்களோ அழைப்புகளோ ஏற்படலாம். அவசரகால எண்களை அழைக்க இது பயன்பாட்டை அனுமதிக்காது என்பதை நினைவில்கொள்ளவும். தீங்கிழைக்கும் பயன்பாடுகள், உங்கள் உறுதிப்படுத்தல் இன்றி அழைப்புகளைச் செய்வதால் உங்களுக்குச் செலவு ஏற்படக்கூடும்."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS அழைப்புச் சேவையை அணுகுதல்"</string>
diff --git a/core/res/res/values-te-rIN/strings.xml b/core/res/res/values-te-rIN/strings.xml
index 87b782f..b1bccd2 100644
--- a/core/res/res/values-te-rIN/strings.xml
+++ b/core/res/res/values-te-rIN/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"కెమెరాతో చిత్రాలు మరియు వీడియోలను తీయడానికి అనువర్తనాన్ని అనుమతిస్తుంది. ఈ అనుమతి మీ నిర్ధారణ లేకుండానే ఎప్పుడైనా కెమెరాను ఉపయోగించడానికి అనువర్తనాన్ని అనుమతిస్తుంది."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"వైబ్రేషన్‌ను నియంత్రించడం"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"వైబ్రేటర్‌ను నియంత్రించడానికి అనువర్తనాన్ని అనుమతిస్తుంది."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ఫ్లాష్‌కాంతిని నియంత్రించడం"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"ఫ్లాష్‌లైట్‌ను నియంత్రించడానికి అనువర్తనాన్ని అనుమతిస్తుంది."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ఫోన్ నంబర్‌లకు నేరుగా కాల్ చేయడం"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"మీ ప్రమేయం లేకుండా ఫోన్ నంబర్‌లకు కాల్ చేయడానికి అనువర్తనాన్ని అనుమతిస్తుంది. దీని వలన అనుకోని ఛార్జీలు విధించబడవచ్చు లేదా కాల్‌లు రావచ్చు. ఇది అత్యవసర నంబర్‌లకు కాల్ చేయడానికి అనువర్తనాన్ని అనుమతించదని గుర్తుంచుకోండి. హానికరమైన అనువర్తనాలు మీ నిర్ధారణ లేకుండానే కాల్‌లు చేయడం ద్వారా మీకు డబ్బు ఖర్చయ్యేలా చేయవచ్చు."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS కాల్ సేవ ప్రాప్యత అనుమతి"</string>
diff --git a/core/res/res/values-th/strings.xml b/core/res/res/values-th/strings.xml
index 2ec0f4c..0b8e60d 100644
--- a/core/res/res/values-th/strings.xml
+++ b/core/res/res/values-th/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"อนุญาตให้แอปพลิเคชันถ่ายภาพและวิดีโอด้วยกล้องถ่ายรูปนี้ การอนุญาตนี้จะทำให้แอปพลิเคชันสามารถใช้กล้องถ่ายรูปได้ทุกเมื่อโดยไม่ต้องรอการยืนยันจากคุณ"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"ควบคุมการสั่นเตือน"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"อนุญาตให้แอปพลิเคชันควบคุมการสั่นเตือน"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"ควบคุมไฟฉาย"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"อนุญาตให้แอปพลิเคชันควบคุมไฟฉาย"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"โทรติดต่อหมายเลขโทรศัพท์โดยตรง"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"อนุญาตให้แอปพลิเคชันโทรเข้าโทรศัพท์โดยไม่ต้องให้คุณจัดการ ซึ่งอาจทำให้มีการเรียกเก็บเงินหรือการโทรที่ไม่คาดคิด โปรดทราบว่าการทำงานนี้ไม่ได้อนุญาตให้แอปพลิเคชันโทรไปหมายเลขฉุกเฉิน แอปพลิเคชันที่เป็นอันตรายอาจทำให้คุณต้องเสียค่าบริการด้วยการโทรโดยไม่ขอการยืนยันจากคุณ"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"เข้าถึงบริการโทร IMS"</string>
diff --git a/core/res/res/values-tl/strings.xml b/core/res/res/values-tl/strings.xml
index 36aa9d9..02a3587 100644
--- a/core/res/res/values-tl/strings.xml
+++ b/core/res/res/values-tl/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Pinapayagan ang app na kumuha ng mga larawan at video gamit ang camera. Pinapayagan ng pahintulot na ito ang app na gamitin ang camera anumang oras nang wala ng iyong kumpirmasyon."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"kontrolin ang pag-vibrate"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Pinapayagan ang app na kontrolin ang vibrator."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"kontrolin ang flashlight"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Pinapayagan ang app na kontrolin ang flashlight."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"direktang tawagan ang mga numero ng telepono"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Pinapayagan ang app na tumawag sa mga numero ng telepono nang wala ng iyong panghihimasok. Maaari itong magresulta sa mga hindi inaasahang pagsingil o tawag. Tandaan na hindi nito pinapayagan ang app na tumawag sa mga numerong pang-emergency. Maaaring magpagastos sa iyo ng pera ang nakakahamak na apps sa pamamagitan ng pagtawag nang wala ng iyong kumpirmasyon."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"i-access ang serbisyo sa tawag ng IMS"</string>
diff --git a/core/res/res/values-tr/strings.xml b/core/res/res/values-tr/strings.xml
index 7b0bdc6..283bcebb 100644
--- a/core/res/res/values-tr/strings.xml
+++ b/core/res/res/values-tr/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Uygulamaya kamerayla fotoğraf ve video çekme izni verir. Bu izin, uygulamanın sizin onayınız olmadan istediği zaman kamerayı kullanmasına olanak sağlar."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"titreşimi denetleme"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Uygulamaya, titreşimi denetleme izni verir."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"el fenerini denetle"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Uygulamaya, el fenerini denetleme izni verir."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"telefon numaralarına doğrudan çağrı yap"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Uygulamaya sizin müdahaleniz olmadan telefon numaralarına çağrı yapma izni verir. Bu durum beklenmeyen ödemelere veya çağrılara neden olabilir. Ancak bu iznin, uygulamanın acil numaralara çağrı yapmasına olanak sağlamadığını unutmayın. Kötü amaçlı uygulamalar onayınız olmadan çağrılar yaparak sizi zarara sokabilir."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS çağrı hizmetine erişme"</string>
diff --git a/core/res/res/values-uk/strings.xml b/core/res/res/values-uk/strings.xml
index 308e50c..fce4cc3 100644
--- a/core/res/res/values-uk/strings.xml
+++ b/core/res/res/values-uk/strings.xml
@@ -356,8 +356,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Дозволяє програмі фотографувати та знімати відео за допомогою камери. Такий дозвіл дає програмі змогу будь-коли використовувати камеру без вашого підтвердження."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"контролювати вібросигнал"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Дозволяє програмі контролювати вібросигнал."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"контр. блим. світло"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Дозволяє програмі контролювати світловий сигнал."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"прямо набирати номери тел."</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Дозволяє програмі набирати номери телефону без вашого відома. Це може спричинити неочікуване стягнення плати чи здійснення дзвінків. Зауважте, що це не дозволяє програмі набирати екстрені номери. Шкідливі програми можуть здійснювати дзвінки без вашого підтвердження, за що з вас стягуватимуться кошти."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"отримувати доступ до телефонної служби IMS"</string>
diff --git a/core/res/res/values-ur-rPK/strings.xml b/core/res/res/values-ur-rPK/strings.xml
index ca26e9b..519f42b 100644
--- a/core/res/res/values-ur-rPK/strings.xml
+++ b/core/res/res/values-ur-rPK/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"ایپ کو کیمرے سے تصویریں لینے اور ویڈیوز بنانے کی اجازت دیتا ہے۔ یہ اجازت ایپ کو آپ کی تصدیق کے بغیر کسی بھی وقت کیمرا استعمال کرنے کی اجازت دیتی ہے۔"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"ارتعاش کو کنٹرول کریں"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"ایپ کو وائبریٹر کنٹرول کرنے کی اجازت دیتا ہے۔"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"فلیش لائٹ کنٹرول"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"ایپ کو فلیش لائٹ کنٹرول کرنے کی اجازت دیتا ہے۔"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"براہ راست فون نمبرز پر کال کریں"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"ایپ کو آپ کی مداخلت کے بغیر فون نمبروں پر کال کرنے کی اجازت دیتا ہے۔ اس کے نتیجے میں غیر متوقع چارجز یا کالیں ہوسکتی ہیں۔ نوٹ کرلیں کہ یہ ایپ کو ہنگامی نمبروں پر کال کرنے کی اجازت نہیں دیتا ہے۔ نقصان دہ ایپس آپ کی تصدیق کے بغیر کالیں کرکے آپ کی رقم صرف کروا سکتے ہیں۔"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"‏IMS کال سروس تک رسائی حاصل کریں"</string>
diff --git a/core/res/res/values-uz-rUZ/strings.xml b/core/res/res/values-uz-rUZ/strings.xml
index 3f3d151..e90d921 100644
--- a/core/res/res/values-uz-rUZ/strings.xml
+++ b/core/res/res/values-uz-rUZ/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Ilovaga kameradan foydalanib rasm va videoga olishga ruxsat beradi. Bu ruxsat ilovaga sizdan tasdiqlashni so‘ramasdan kameradan foydalanishga imkon beradi."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"tebranishni boshqarish"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Ilova tebranishli signallarni boshqarishi mumkin."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"chiroq chaqnashini boshqarish"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Ilova chaqnoqni boshqarishi mumkin."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"telefon raqamlariga tog‘ridan to‘g‘ri qo‘ng‘iroq qilish"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Ilovaga sizning yordamingizsiz telefonga qo‘ng‘iroq qilish imkonini beradi. Bu kutilmagan qo‘ng‘iroqlarni amalga oshirishi yoki ortiqcha to‘lovlarni yuzaga keltirishi mumkin. Shunga e’tibor qilinki, u favqulodda telefon raqamlariga qo‘ng‘iroqlar qilishga ruxsat bermaydi. Zararli ilovalar sizdan so‘ramasdan qo‘ng‘iroqlarni amalga oshirib, pulingizni sarflashi mumkin."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"IMS qo‘ng‘iroq xizmatiga kirish"</string>
diff --git a/core/res/res/values-vi/strings.xml b/core/res/res/values-vi/strings.xml
index c538684..31e090b 100644
--- a/core/res/res/values-vi/strings.xml
+++ b/core/res/res/values-vi/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Cho phép ứng dụng chụp ảnh và quay video bằng máy ảnh. Quyền này cho phép ứng dụng sử dụng máy ảnh bất kỳ lúc nào mà không cần sự xác nhận của bạn."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"kiểm soát rung"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Cho phép ứng dụng kiểm soát bộ rung."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"kiểm soát đèn nháy"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Cho phép ứng dụng kiểm soát đèn nháy."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"gọi trực tiếp số điện thoại"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Cho phép ứng dụng gọi các số điện thoại mà không cần sự can thiệp của bạn. Việc này có thể dẫn đến các khoản phí hoặc cuộc gọi không mong muốn. Lưu ý rằng quyền này không cho phép ứng dụng gọi các số khẩn cấp. Các ứng dụng độc hại có thể khiến bạn tốn tiền do thực hiện cuộc gọi mà không cần sự xác nhận của bạn."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"truy cập dịch vụ gọi điện qua IMS"</string>
diff --git a/core/res/res/values-zh-rCN/strings.xml b/core/res/res/values-zh-rCN/strings.xml
index 77053f2..c5cd59a 100644
--- a/core/res/res/values-zh-rCN/strings.xml
+++ b/core/res/res/values-zh-rCN/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"允许该应用使用相机拍摄照片和视频。此权限可让该应用随时使用相机,而无需您的确认。"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"控制振动"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"允许应用控制振动器。"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"控制闪光灯"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"允许应用控制闪光灯。"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"直接拨打电话号码"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"允许该应用在您未执行操作的情况下拨打电话号码。此权限可能会导致意外收费或呼叫。请注意,此权限不允许该应用拨打紧急电话号码。恶意应用可通过拨打电话产生相关费用,而无需您的确认。"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"使用即时通讯通话服务"</string>
diff --git a/core/res/res/values-zh-rHK/strings.xml b/core/res/res/values-zh-rHK/strings.xml
index 612efe4..36ba2ad6 100644
--- a/core/res/res/values-zh-rHK/strings.xml
+++ b/core/res/res/values-zh-rHK/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"允許應用程式使用相機拍照和錄影。這項權限允許應用程式隨時使用相機,而不需經您確認。"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"控制震動"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"允許應用程式控制震動。"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"控制閃光燈"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"允許應用程式控制閃光燈。"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"直接撥打電話號碼"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"允許應用程式繞過您自行撥打電話號碼,但可能會產生未預期的費用或撥打未預期的電話。注意:這項權限不允許應用程式撥打緊急電話。惡意應用程式可能未經您確認擅自撥打電話,增加您的支出。"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"使用 IMS 通話服務"</string>
diff --git a/core/res/res/values-zh-rTW/strings.xml b/core/res/res/values-zh-rTW/strings.xml
index 201cc1e..72ea523 100644
--- a/core/res/res/values-zh-rTW/strings.xml
+++ b/core/res/res/values-zh-rTW/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"允許應用程式使用相機拍照和錄影。這項權限可讓應用程式隨時使用相機,而不需請求您進行確認。"</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"控制震動"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"允許應用程式控制震動。"</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"控制閃光燈"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"允許應用程式控制閃光燈。"</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"直接撥打電話號碼"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"允許應用程式自行撥打電話,但可能產生非預期的費用或撥打非預期的電話。注意:這項權限不允許應用程式撥打緊急電話。惡意應用程式可能利用此功能擅自撥打電話,增加您不必要的額外支出。"</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"存取 IMS 撥號服務"</string>
diff --git a/core/res/res/values-zu/strings.xml b/core/res/res/values-zu/strings.xml
index 5e835e3..bee7eea 100644
--- a/core/res/res/values-zu/strings.xml
+++ b/core/res/res/values-zu/strings.xml
@@ -354,8 +354,6 @@
     <string name="permdesc_camera" msgid="8497216524735535009">"Ivumela uhlelo lokusebenza ukuthatha izithombe namavidiyo ngekhamera. Le mvume ivumela uhlelo lokusebenza ukusebenzisa ikhamera nganoma isiphi isikhathi ngaphandle kwemvume yakho."</string>
     <string name="permlab_vibrate" msgid="7696427026057705834">"lawula ukudlidliza"</string>
     <string name="permdesc_vibrate" msgid="6284989245902300945">"Ivumela uhlelo lokusebenza ukulawula isidlidlizi."</string>
-    <string name="permlab_flashlight" msgid="2155920810121984215">"lawula ukukhanya kwefulashi"</string>
-    <string name="permdesc_flashlight" msgid="6522284794568368310">"Ivumela uhlelo lokusebenza ukulawula ukukhanya kwefuleshi."</string>
     <string name="permlab_callPhone" msgid="3925836347681847954">"ngokuqondile shayela izinombolo zocingo"</string>
     <string name="permdesc_callPhone" msgid="3740797576113760827">"Ivumela uhlelo lokusebenza ukushayela izinombolo zefoni ngaphandle kokuhlanganyela kwakho. Lokhu kungaholela emashajini noma amakholi angalindelekile. Qaphela ukuthi lokhu akuvumeli uhlelo lokusebenza ukushayela izinombolo zesimo esiphuthumayo. Izinhlelo zokusebenza ezingalungile zingabiza imali ngokwenze amakholi ngaphandle kokuqinisekisa kwakho."</string>
     <string name="permlab_accessImsCallService" msgid="3574943847181793918">"finyelela kusevisi yekholi ye-IMS"</string>
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index 2a11081..58a77e8 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -1857,6 +1857,11 @@
         <attr name="lockTaskMode" />
         <attr name="showForAllUsers" />
         <attr name="encryptionAware" />
+        <!-- @hide This activity is always focusable regardless of if it is in a task/stack whose
+             activities are normally not focusable.
+             For example, {@link android.R.attr#supportsPictureInPicture} activities are placed
+             in a task/stack that isn't focusable. This flag allows them to be focusable.-->
+        <attr name="alwaysFocusable" format="boolean" />
     </declare-styleable>
 
     <!-- The <code>activity-alias</code> tag declares a new
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index c03d471..58c4046 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -2410,4 +2410,15 @@
 
     <!-- Default bounds [left top right bottom] on screen for picture-in-picture windows. -->
     <string translatable="false" name="config_defaultPictureInPictureBounds">"0 0 100 100"</string>
+
+    <!-- Controls the snap mode for the docked stack divider
+             0 - 3 snap targets: left/top has 16:9 ratio, 1:1, and right/bottom has 16:9 ratio
+             1 - 3 snap targets: fixed ratio, 1:1, (1 - fixed ratio)
+             2 - 1 snap target: 1:1
+    -->
+    <integer name="config_dockedStackDividerSnapMode">0</integer>
+
+    <!-- List of comma separated package names for which we the system will not show crash, ANR,
+         etc. dialogs. -->
+    <string translatable="false" name="config_appsNotReportingCrashes"></string>
 </resources>
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index ef6b467..b2482cd 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -35,6 +35,13 @@
     <dimen name="navigation_bar_height_landscape">48dp</dimen>
     <!-- Width of the navigation bar when it is placed vertically on the screen -->
     <dimen name="navigation_bar_width">48dp</dimen>
+    <!-- Height of the bottom navigation / system bar in car mode. -->
+    <dimen name="navigation_bar_height_car_mode">96dp</dimen>
+    <!-- Height of the bottom navigation bar in portrait; often the same as
+         @dimen/navigation_bar_height_car_mode -->
+    <dimen name="navigation_bar_height_landscape_car_mode">96dp</dimen>
+    <!-- Width of the navigation bar when it is placed vertically on the screen in car mode -->
+    <dimen name="navigation_bar_width_car_mode">96dp</dimen>
     <!-- Height of notification icons in the status bar -->
     <dimen name="status_bar_icon_size">24dip</dimen>
     <!-- Size of the giant number (unread count) in the notifications -->
@@ -429,4 +436,6 @@
 
     <item type="dimen" format="integer" name="time_picker_column_start_material">0</item>
     <item type="dimen" format="integer" name="time_picker_column_end_material">1</item>
+
+    <item type="fraction" name="docked_stack_divider_fixed_ratio">34.15%</item>
 </resources>
diff --git a/core/res/res/values/locale_config.xml b/core/res/res/values/locale_config.xml
index eee5771..3cfd9f4 100644
--- a/core/res/res/values/locale_config.xml
+++ b/core/res/res/values/locale_config.xml
@@ -49,6 +49,7 @@
         <item>ar-SY</item> <!-- Arabic (Syria) -->
         <item>ar-TD</item> <!-- Arabic (Chad) -->
         <item>ar-TN</item> <!-- Arabic (Tunisia) -->
+        <item>ar-XB</item> <!-- Right-to-left pseudolocale -->
         <item>ar-YE</item> <!-- Arabic (Yemen) -->
         <item>as-IN</item> <!-- Assamese (India) -->
         <item>asa-TZ</item> <!-- Asu (Tanzania) -->
@@ -195,6 +196,7 @@
         <item>en-VI</item> <!-- English (U.S. Virgin Islands) -->
         <item>en-VU</item> <!-- English (Vanuatu) -->
         <item>en-WS</item> <!-- English (Samoa) -->
+        <item>en-XA</item> <!-- Left-to-right pseudolocale -->
         <item>en-ZA</item> <!-- English (South Africa) -->
         <item>en-ZM</item> <!-- English (Zambia) -->
         <item>en-ZW</item> <!-- English (Zimbabwe) -->
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 347f2f9..be9ba62 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -1026,11 +1026,6 @@
     <string name="permdesc_vibrate">Allows the app to control the vibrator.</string>
 
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permlab_flashlight">control flashlight</string>
-    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
-    <string name="permdesc_flashlight">Allows the app to control the flashlight.</string>
-
-    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_callPhone">directly call phone numbers</string>
     <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permdesc_callPhone">Allows the app to call phone numbers
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 3c1d944..a4654e8 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -575,6 +575,7 @@
   <java-symbol type="string" name="config_ntpServer" />
   <java-symbol type="string" name="config_useragentprofile_url" />
   <java-symbol type="string" name="config_wifi_p2p_device_type" />
+  <java-symbol type="string" name="config_appsNotReportingCrashes" />
   <java-symbol type="string" name="contentServiceSync" />
   <java-symbol type="string" name="contentServiceSyncNotificationTitle" />
   <java-symbol type="string" name="contentServiceTooManyDeletesNotificationDesc" />
@@ -1492,9 +1493,14 @@
   <java-symbol type="bool" name="target_honeycomb_needs_options_menu" />
   <java-symbol type="dimen" name="docked_stack_divider_thickness" />
   <java-symbol type="dimen" name="docked_stack_divider_insets" />
+  <java-symbol type="integer" name="config_dockedStackDividerSnapMode" />
+  <java-symbol type="fraction" name="docked_stack_divider_fixed_ratio" />
   <java-symbol type="dimen" name="navigation_bar_height" />
   <java-symbol type="dimen" name="navigation_bar_height_landscape" />
   <java-symbol type="dimen" name="navigation_bar_width" />
+  <java-symbol type="dimen" name="navigation_bar_height_car_mode" />
+  <java-symbol type="dimen" name="navigation_bar_height_landscape_car_mode" />
+  <java-symbol type="dimen" name="navigation_bar_width_car_mode" />
   <java-symbol type="dimen" name="status_bar_height" />
   <java-symbol type="drawable" name="ic_jog_dial_sound_off" />
   <java-symbol type="drawable" name="ic_jog_dial_sound_on" />
diff --git a/core/tests/coretests/Android.mk b/core/tests/coretests/Android.mk
index 7cd25af..ee8921e 100644
--- a/core/tests/coretests/Android.mk
+++ b/core/tests/coretests/Android.mk
@@ -22,7 +22,7 @@
 	$(call all-java-files-under, EnabledTestApp/src)
 
 LOCAL_DX_FLAGS := --core-library
-LOCAL_AAPT_FLAGS = -0 dat -0 gld
+LOCAL_AAPT_FLAGS = -0 dat -0 gld -c fa
 LOCAL_STATIC_JAVA_LIBRARIES := \
     core-tests-support \
     android-common \
diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml
index 5177836..c0453f8 100644
--- a/core/tests/coretests/AndroidManifest.xml
+++ b/core/tests/coretests/AndroidManifest.xml
@@ -146,6 +146,16 @@
             </intent-filter>
         </activity>
 
+        <activity android:name="android.widget.DatePickerActivity"
+                android:label="DatePickerActivity"
+                android:screenOrientation="portrait"
+                android:theme="@android:style/Theme.Material.Light">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+            </intent-filter>
+        </activity>
+
         <activity android:name="android.widget.focus.DescendantFocusability" android:label="DescendantFocusability">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
diff --git a/core/tests/coretests/res/layout/datepicker_layout.xml b/core/tests/coretests/res/layout/datepicker_layout.xml
new file mode 100644
index 0000000..a79f87d
--- /dev/null
+++ b/core/tests/coretests/res/layout/datepicker_layout.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<RelativeLayout
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+    <DatePicker
+            android:id="@+id/datePicker"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerInParent="true"/>
+    <EditText
+            android:id="@+id/belowPicker"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:text="Some Text"
+            android:textAlignment="center"
+            android:layout_below="@id/datePicker"/>
+</RelativeLayout>
diff --git a/core/tests/coretests/res/values-fa/strings.xml b/core/tests/coretests/res/values-fa/strings.xml
new file mode 100644
index 0000000..c83f5f1
--- /dev/null
+++ b/core/tests/coretests/res/values-fa/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="dummy_string">رشتهٔ الکی</string>
+</resources>
diff --git a/core/tests/coretests/res/values/strings.xml b/core/tests/coretests/res/values/strings.xml
index 04b0478..ef915bb 100644
--- a/core/tests/coretests/res/values/strings.xml
+++ b/core/tests/coretests/res/values/strings.xml
@@ -139,4 +139,7 @@
     <!-- RestrictionsManagerTest -->
     <string name="restrictionManager_title">Title</string>
     <string name="restrictionManager_desc">Description</string>
+
+    <!-- ResourcesLocaleResolutionTest -->
+    <string name="dummy_string">dummy string</string>
 </resources>
diff --git a/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java b/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java
deleted file mode 100644
index 37495e1..0000000
--- a/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.content.pm;
-
-import android.os.Parcel;
-import android.test.AndroidTestCase;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.MessageDigest;
-
-public class ManifestDigestTest extends AndroidTestCase {
-    private static final byte[] MESSAGE_1 = {
-            (byte) 0x00, (byte) 0xAA, (byte) 0x55, (byte) 0xFF
-    };
-
-    public void testManifestDigest_FromInputStream_Null() {
-        assertNull("Attributes were null, so ManifestDigest.fromAttributes should return null",
-                ManifestDigest.fromInputStream(null));
-    }
-
-    public void testManifestDigest_FromInputStream_ThrowsIoException() {
-        InputStream is = new InputStream() {
-            @Override
-            public int read() throws IOException {
-                throw new IOException();
-            }
-        };
-
-        assertNull("InputStream threw exception, so ManifestDigest should be null",
-                ManifestDigest.fromInputStream(is));
-    }
-
-    public void testManifestDigest_Equals() throws Exception {
-        InputStream is = new ByteArrayInputStream(MESSAGE_1);
-
-        ManifestDigest expected =
-                new ManifestDigest(MessageDigest.getInstance("SHA-256").digest(MESSAGE_1));
-
-        ManifestDigest actual = ManifestDigest.fromInputStream(is);
-        assertEquals(expected, actual);
-
-        ManifestDigest unexpected = new ManifestDigest(new byte[0]);
-        assertFalse(unexpected.equals(actual));
-    }
-
-    public void testManifestDigest_Parcel() throws Exception {
-        InputStream is = new ByteArrayInputStream(MESSAGE_1);
-
-        ManifestDigest digest = ManifestDigest.fromInputStream(is);
-
-        Parcel p = Parcel.obtain();
-        digest.writeToParcel(p, 0);
-        p.setDataPosition(0);
-
-        ManifestDigest fromParcel = ManifestDigest.CREATOR.createFromParcel(p);
-
-        assertEquals("ManifestDigest going through parceling should be the same as before: "
-                + digest.toString() + " and " + fromParcel.toString(), digest,
-                fromParcel);
-    }
-}
diff --git a/core/tests/coretests/src/android/content/pm/VerificationParamsTest.java b/core/tests/coretests/src/android/content/pm/VerificationParamsTest.java
index 9b216cb..d963812 100644
--- a/core/tests/coretests/src/android/content/pm/VerificationParamsTest.java
+++ b/core/tests/coretests/src/android/content/pm/VerificationParamsTest.java
@@ -16,7 +16,6 @@
 
 package android.content.pm;
 
-import android.content.pm.ManifestDigest;
 import android.content.pm.VerificationParams;
 import android.net.Uri;
 import android.os.Parcel;
@@ -33,7 +32,6 @@
     private final static String VERIFICATION_URI_STRING = "http://verification.uri/path";
     private final static String ORIGINATING_URI_STRING = "http://originating.uri/path";
     private final static String REFERRER_STRING = "http://referrer.uri/path";
-    private final static byte[] DIGEST_BYTES = "fake digest".getBytes();
     private final static int INSTALLER_UID = 42;
 
     private final static Uri VERIFICATION_URI = Uri.parse(VERIFICATION_URI_STRING);
@@ -42,11 +40,9 @@
 
     private final static int ORIGINATING_UID = 10042;
 
-    private final static ManifestDigest MANIFEST_DIGEST = new ManifestDigest(DIGEST_BYTES);
-
     public void testParcel() throws Exception {
         VerificationParams expected = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         Parcel parcel = Parcel.obtain();
         expected.writeToParcel(parcel, 0);
@@ -61,85 +57,70 @@
         assertEquals(REFERRER, actual.getReferrer());
 
         assertEquals(ORIGINATING_UID, actual.getOriginatingUid());
-
-        assertEquals(MANIFEST_DIGEST, actual.getManifestDigest());
     }
 
     public void testEquals_Success() throws Exception {
         VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         VerificationParams params2 = new VerificationParams(
                 Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING),
-                Uri.parse(REFERRER_STRING), ORIGINATING_UID, new ManifestDigest(DIGEST_BYTES));
+                Uri.parse(REFERRER_STRING), ORIGINATING_UID);
 
         assertEquals(params1, params2);
     }
 
     public void testEquals_VerificationUri_Failure() throws Exception {
         VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         VerificationParams params2 = new VerificationParams(
                 Uri.parse("http://a.different.uri/"), Uri.parse(ORIGINATING_URI_STRING),
-                Uri.parse(REFERRER_STRING), ORIGINATING_UID, new ManifestDigest(DIGEST_BYTES));
+                Uri.parse(REFERRER_STRING), ORIGINATING_UID);
 
         assertFalse(params1.equals(params2));
     }
 
     public void testEquals_OriginatingUri_Failure() throws Exception {
         VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         VerificationParams params2 = new VerificationParams(
                 Uri.parse(VERIFICATION_URI_STRING), Uri.parse("http://a.different.uri/"),
-                Uri.parse(REFERRER_STRING), ORIGINATING_UID, new ManifestDigest(DIGEST_BYTES));
+                Uri.parse(REFERRER_STRING), ORIGINATING_UID);
 
         assertFalse(params1.equals(params2));
     }
 
     public void testEquals_Referrer_Failure() throws Exception {
         VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         VerificationParams params2 = new VerificationParams(
                 Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING),
-                Uri.parse("http://a.different.uri/"), ORIGINATING_UID,
-                new ManifestDigest(DIGEST_BYTES));
+                Uri.parse("http://a.different.uri/"), ORIGINATING_UID);
 
         assertFalse(params1.equals(params2));
     }
 
     public void testEquals_Originating_Uid_Failure() throws Exception {
         VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         VerificationParams params2 = new VerificationParams(
                 Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING),
-                Uri.parse(REFERRER_STRING), 12345, new ManifestDigest(DIGEST_BYTES));
-
-        assertFalse(params1.equals(params2));
-    }
-
-    public void testEquals_ManifestDigest_Failure() throws Exception {
-        VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
-
-        VerificationParams params2 = new VerificationParams(
-                Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING),
-                Uri.parse(REFERRER_STRING), ORIGINATING_UID,
-                new ManifestDigest("a different digest".getBytes()));
+                Uri.parse(REFERRER_STRING), 12345);
 
         assertFalse(params1.equals(params2));
     }
 
     public void testEquals_InstallerUid_Failure() throws Exception {
         VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         VerificationParams params2 = new VerificationParams(
                 Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING),
-                Uri.parse(REFERRER_STRING), ORIGINATING_UID, new ManifestDigest(DIGEST_BYTES));
+                Uri.parse(REFERRER_STRING), ORIGINATING_UID);
         params2.setInstallerUid(INSTALLER_UID);
 
         assertFalse(params1.equals(params2));
@@ -147,78 +128,65 @@
 
     public void testHashCode_Success() throws Exception {
         VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         VerificationParams params2 = new VerificationParams(
                 Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING),
-                Uri.parse(REFERRER_STRING), ORIGINATING_UID, new ManifestDigest(DIGEST_BYTES));
+                Uri.parse(REFERRER_STRING), ORIGINATING_UID);
 
         assertEquals(params1.hashCode(), params2.hashCode());
     }
 
     public void testHashCode_VerificationUri_Failure() throws Exception {
         VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         VerificationParams params2 = new VerificationParams(null, Uri.parse(ORIGINATING_URI_STRING),
-                Uri.parse(REFERRER_STRING), ORIGINATING_UID, new ManifestDigest(DIGEST_BYTES));
+                Uri.parse(REFERRER_STRING), ORIGINATING_UID);
 
         assertFalse(params1.hashCode() == params2.hashCode());
     }
 
     public void testHashCode_OriginatingUri_Failure() throws Exception {
         VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         VerificationParams params2 = new VerificationParams(
                 Uri.parse(VERIFICATION_URI_STRING), Uri.parse("http://a.different.uri/"),
-                Uri.parse(REFERRER_STRING), ORIGINATING_UID, new ManifestDigest(DIGEST_BYTES));
+                Uri.parse(REFERRER_STRING), ORIGINATING_UID);
 
         assertFalse(params1.hashCode() == params2.hashCode());
     }
 
     public void testHashCode_Referrer_Failure() throws Exception {
         VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         VerificationParams params2 = new VerificationParams(
                 Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING), null,
-                ORIGINATING_UID, new ManifestDigest(DIGEST_BYTES));
+                ORIGINATING_UID);
 
         assertFalse(params1.hashCode() == params2.hashCode());
     }
 
     public void testHashCode_Originating_Uid_Failure() throws Exception {
         VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         VerificationParams params2 = new VerificationParams(
                 Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING),
-                Uri.parse(REFERRER_STRING), 12345, new ManifestDigest(DIGEST_BYTES));
-
-        assertFalse(params1.hashCode() == params2.hashCode());
-    }
-
-    public void testHashCode_ManifestDigest_Failure() throws Exception {
-        VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
-
-        VerificationParams params2 = new VerificationParams(
-                Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING),
-                Uri.parse(REFERRER_STRING), ORIGINATING_UID,
-                new ManifestDigest("a different digest".getBytes()));
+                Uri.parse(REFERRER_STRING), 12345);
 
         assertFalse(params1.hashCode() == params2.hashCode());
     }
 
     public void testHashCode_InstallerUid_Failure() throws Exception {
         VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
-                REFERRER, ORIGINATING_UID, MANIFEST_DIGEST);
+                REFERRER, ORIGINATING_UID);
 
         VerificationParams params2 = new VerificationParams(
                 Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING),
-                Uri.parse(REFERRER_STRING), ORIGINATING_UID,
-                new ManifestDigest("a different digest".getBytes()));
+                Uri.parse(REFERRER_STRING), ORIGINATING_UID);
         params2.setInstallerUid(INSTALLER_UID);
 
         assertFalse(params1.hashCode() == params2.hashCode());
diff --git a/core/tests/coretests/src/android/content/res/ResourcesLocaleResolutionTest.java b/core/tests/coretests/src/android/content/res/ResourcesLocaleResolutionTest.java
new file mode 100644
index 0000000..55c0031
--- /dev/null
+++ b/core/tests/coretests/src/android/content/res/ResourcesLocaleResolutionTest.java
@@ -0,0 +1,53 @@
+/*
+* Copyright (C) 2015 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package android.content.res;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.util.DisplayMetrics;
+import android.util.LocaleList;
+
+import java.util.Arrays;
+import java.util.Locale;
+
+public class ResourcesLocaleResolutionTest extends AndroidTestCase {
+    @SmallTest
+    public void testGetResolvedLocale_englishIsAlwaysConsideredSupported() {
+        // First make sure English has no explicit assets other than the default assets
+        final AssetManager assets = getContext().getAssets();
+        final String supportedLocales[] = assets.getNonSystemLocales();
+        for (String languageTag : supportedLocales) {
+            if ("en-XA".equals(languageTag)) {
+                continue;
+            }
+            assertFalse(
+                    "supported locales: " + Arrays.toString(supportedLocales),
+                    "en".equals(Locale.forLanguageTag(languageTag).getLanguage()));
+        }
+
+        final DisplayMetrics dm = new DisplayMetrics();
+        dm.setToDefaults();
+        final Configuration cfg = new Configuration();
+        cfg.setToDefaults();
+        // Avestan and English have no assets, but Persian does.
+        cfg.setLocales(LocaleList.forLanguageTags("ae,en,fa"));
+        Resources res = new Resources(assets, dm, cfg);
+        // We should get English, because it is always considered supported.
+        assertEquals("en", res.getResolvedLocale().toLanguageTag());
+    }
+}
+
diff --git a/core/tests/coretests/src/android/util/PatternsTest.java b/core/tests/coretests/src/android/util/PatternsTest.java
index 253eb25..d383775 100644
--- a/core/tests/coretests/src/android/util/PatternsTest.java
+++ b/core/tests/coretests/src/android/util/PatternsTest.java
@@ -17,14 +17,16 @@
 
 import android.test.suitebuilder.annotation.SmallTest;
 import android.test.suitebuilder.annotation.Suppress;
-import android.util.Patterns;
 
 import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import junit.framework.TestCase;
 
 public class PatternsTest extends TestCase {
 
+    //Tests for Patterns.TOP_LEVEL_DOMAIN
+
     @SmallTest
     public void testTldPattern() throws Exception {
         boolean t;
@@ -40,7 +42,7 @@
         t = Patterns.TOP_LEVEL_DOMAIN.matcher("xn--0zwm56d").matches();
         assertTrue("Missed valid TLD", t);
 
-        // One of the new top level internationalized domain.
+        // One of the new top level unicode domain.
         t = Patterns.TOP_LEVEL_DOMAIN.matcher("\uD55C\uAD6D").matches();
         assertTrue("Missed valid TLD", t);
 
@@ -54,60 +56,372 @@
         assertFalse("Matched invalid TLD!", t);
     }
 
+    //Tests for Patterns.IANA_TOP_LEVEL_DOMAINS
+
     @SmallTest
-    @Suppress // Failing.
-    public void testUrlPattern() throws Exception {
-        boolean t;
-
-        t = Patterns.WEB_URL.matcher("http://www.google.com").matches();
-        assertTrue("Valid URL", t);
-
-        // Google in one of the new top level domain.
-        t = Patterns.WEB_URL.matcher("http://www.google.me").matches();
-        assertTrue("Valid URL", t);
-        t = Patterns.WEB_URL.matcher("google.me").matches();
-        assertTrue("Valid URL", t);
-
-        // Test url in Chinese: http://xn--fsqu00a.xn--0zwm56d
-        t = Patterns.WEB_URL.matcher("http://xn--fsqu00a.xn--0zwm56d").matches();
-        assertTrue("Valid URL", t);
-        t = Patterns.WEB_URL.matcher("xn--fsqu00a.xn--0zwm56d").matches();
-        assertTrue("Valid URL", t);
-
-        // Url for testing top level Arabic country code domain in Punycode:
-        //   http://xn--4gbrim.xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c/ar/default.aspx
-        t = Patterns.WEB_URL.matcher("http://xn--4gbrim.xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c/ar/default.aspx").matches();
-        assertTrue("Valid URL", t);
-        t = Patterns.WEB_URL.matcher("xn--4gbrim.xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c/ar/default.aspx").matches();
-        assertTrue("Valid URL", t);
-
-        // Internationalized URL.
-        t = Patterns.WEB_URL.matcher("http://\uD604\uAE08\uC601\uC218\uC99D.kr").matches();
-        assertTrue("Valid URL", t);
-        t = Patterns.WEB_URL.matcher("\uD604\uAE08\uC601\uC218\uC99D.kr").matches();
-        assertTrue("Valid URL", t);
-        // URL with international TLD.
-        t = Patterns.WEB_URL.matcher("\uB3C4\uBA54\uC778.\uD55C\uAD6D").matches();
-        assertTrue("Valid URL", t);
-
-        t = Patterns.WEB_URL.matcher("http://brainstormtech.blogs.fortune.cnn.com/2010/03/11/" +
-            "top-five-moments-from-eric-schmidt\u2019s-talk-in-abu-dhabi/").matches();
-        assertTrue("Valid URL", t);
-
-        t = Patterns.WEB_URL.matcher("ftp://www.example.com").matches();
-        assertFalse("Matched invalid protocol", t);
-
-        t = Patterns.WEB_URL.matcher("http://www.example.com:8080").matches();
-        assertTrue("Didn't match valid URL with port", t);
-
-        t = Patterns.WEB_URL.matcher("http://www.example.com:8080/?foo=bar").matches();
-        assertTrue("Didn't match valid URL with port and query args", t);
-
-        t = Patterns.WEB_URL.matcher("http://www.example.com:8080/~user/?foo=bar").matches();
-        assertTrue("Didn't match valid URL with ~", t);
+    public void testIanaTopLevelDomains_matchesValidTld() throws Exception {
+        Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
+        assertTrue("Should match 'com'", pattern.matcher("com").matches());
     }
 
     @SmallTest
+    public void testIanaTopLevelDomains_matchesValidNewTld() throws Exception {
+        Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
+        assertTrue("Should match 'me'", pattern.matcher("me").matches());
+    }
+
+    @SmallTest
+    public void testIanaTopLevelDomains_matchesPunycodeTld() throws Exception {
+        Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
+        assertTrue("Should match Punycode TLD", pattern.matcher("xn--qxam").matches());
+    }
+
+    @SmallTest
+    public void testIanaTopLevelDomains_matchesIriTLD() throws Exception {
+        Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
+        assertTrue("Should match IRI TLD", pattern.matcher("\uD55C\uAD6D").matches());
+    }
+
+    @SmallTest
+    public void testIanaTopLevelDomains_doesNotMatchWrongTld() throws Exception {
+        Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
+        assertFalse("Should not match 'mem'", pattern.matcher("mem").matches());
+    }
+
+    @SmallTest
+    public void testIanaTopLevelDomains_doesNotMatchWrongPunycodeTld() throws Exception {
+        Pattern pattern = Pattern.compile(Patterns.IANA_TOP_LEVEL_DOMAINS);
+        assertFalse("Should not match invalid Punycode TLD", pattern.matcher("xn").matches());
+    }
+
+    //Tests for Patterns.WEB_URL
+
+    @SmallTest
+    public void testWebUrl_matchesValidUrlWithSchemeAndHostname() throws Exception {
+        String url = "http://www.android.com";
+        assertTrue("Should match URL with scheme and hostname",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesValidUrlWithSchemeHostnameAndNewTld() throws Exception {
+        String url = "http://www.android.me";
+        assertTrue("Should match URL with scheme, hostname and new TLD",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesValidUrlWithHostnameAndNewTld() throws Exception {
+        String url = "android.me";
+        assertTrue("Should match URL with hostname and new TLD",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesChinesePunycodeUrlWithProtocol() throws Exception {
+        String url = "http://xn--fsqu00a.xn--0zwm56d";
+        assertTrue("Should match Chinese Punycode URL with protocol",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesChinesePunycodeUrlWithoutProtocol() throws Exception {
+        String url = "xn--fsqu00a.xn--0zwm56d";
+        assertTrue("Should match Chinese Punycode URL without protocol",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+
+    @SmallTest
+    public void testWebUrl_matchesArabicPunycodeUrlWithProtocol() throws Exception {
+        String url = "http://xn--4gbrim.xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c/ar/default.aspx";
+        assertTrue("Should match arabic Punycode URL with protocol",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesArabicPunycodeUrlWithoutProtocol() throws Exception {
+        String url = "xn--4gbrim.xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c/ar/default.aspx";
+        assertTrue("Should match Arabic Punycode URL without protocol",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesUrlWithUnicodeDomainNameWithProtocol() throws Exception {
+        String url = "http://\uD604\uAE08\uC601\uC218\uC99D.kr";
+        assertTrue("Should match URL with Unicode domain name",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesUrlWithUnicodeDomainNameWithoutProtocol() throws Exception {
+        String url = "\uD604\uAE08\uC601\uC218\uC99D.kr";
+        assertTrue("Should match URL without protocol and with Unicode domain name",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesUrlWithUnicodeTld() throws Exception {
+        String url = "\uB3C4\uBA54\uC778.\uD55C\uAD6D";
+        assertTrue("Should match URL with Unicode TLD",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesUrlWithUnicodePath() throws Exception {
+        String url = "http://brainstormtech.blogs.fortune.cnn.com/2010/03/11/" +
+                "top-five-moments-from-eric-schmidt\u2019s-talk-in-abu-dhabi/";
+        assertTrue("Should match URL with Unicode path",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_doesNotMatchValidUrlWithInvalidProtocol() throws Exception {
+        String url = "ftp://www.example.com";
+        assertFalse("Should not match URL with invalid protocol",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesValidUrlWithPort() throws Exception {
+        String url = "http://www.example.com:8080";
+        assertTrue("Should match URL with port", Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesUrlWithPortAndQuery() throws Exception {
+        String url = "http://www.example.com:8080/?foo=bar";
+        assertTrue("Should match URL with port and query",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesUrlWithTilde() throws Exception {
+        String url = "http://www.example.com:8080/~user/?foo=bar";
+        assertTrue("Should match URL with tilde", Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testWebUrl_matchesProtocolCaseInsensitive() throws Exception {
+        String url = "hTtP://android.com";
+        assertTrue("Protocol matching should be case insensitive",
+                Patterns.WEB_URL.matcher(url).matches());
+    }
+
+    //Tests for Patterns.AUTOLINK_WEB_URL
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesValidUrlWithSchemeAndHostname() throws Exception {
+        String url = "http://www.android.com";
+        assertTrue("Should match URL with scheme and hostname",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesValidUrlWithSchemeHostnameAndNewTld() throws Exception {
+        String url = "http://www.android.me";
+        assertTrue("Should match URL with scheme, hostname and new TLD",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesValidUrlWithHostnameAndNewTld() throws Exception {
+        String url = "android.me";
+        assertTrue("Should match URL with hostname and new TLD",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+
+        url = "android.camera";
+        assertTrue("Should match URL with hostname and new TLD",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesChinesePunycodeUrlWithProtocol() throws Exception {
+        String url = "http://xn--fsqu00a.xn--0zwm56d";
+        assertTrue("Should match Chinese Punycode URL with protocol",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesChinesePunycodeUrlWithoutProtocol() throws Exception {
+        String url = "xn--fsqu00a.xn--0zwm56d";
+        assertTrue("Should match Chinese Punycode URL without protocol",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesArabicPunycodeUrlWithProtocol() throws Exception {
+        String url = "http://xn--4gbrim.xn--rmckbbajlc6dj7bxne2c.xn--wgbh1c/ar/default.aspx";
+        assertTrue("Should match Arabic Punycode URL with protocol",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesArabicPunycodeUrlWithoutProtocol() throws Exception {
+        String url = "xn--4gbrim.xn--rmckbbajlc6dj7bxne2c.xn--wgbh1c/ar/default.aspx";
+        assertTrue("Should match Arabic Punycode URL without protocol",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_doesNotMatchPunycodeTldThatStartsWithDash() throws Exception {
+        String url = "http://xn--fsqu00a.-xn--0zwm56d";
+        assertFalse("Should not match Punycode TLD that starts with dash",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_doesNotMatchPunycodeTldThatEndsWithDash() throws Exception {
+        String url = "http://xn--fsqu00a.xn--0zwm56d-";
+        assertFalse("Should not match Punycode TLD that ends with dash",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesUrlWithUnicodeDomainName() throws Exception {
+        String url = "http://\uD604\uAE08\uC601\uC218\uC99D.kr";
+        assertTrue("Should match URL with Unicode domain name",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+
+        url = "\uD604\uAE08\uC601\uC218\uC99D.kr";
+        assertTrue("hould match URL without protocol and with Unicode domain name",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesUrlWithUnicodeTld() throws Exception {
+        String url = "\uB3C4\uBA54\uC778.\uD55C\uAD6D";
+        assertTrue("Should match URL with Unicode TLD",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesUrlWithUnicodePath() throws Exception {
+        String url = "http://brainstormtech.blogs.fortune.cnn.com/2010/03/11/" +
+                "top-five-moments-from-eric-schmidt\u2019s-talk-in-abu-dhabi/";
+        assertTrue("Should match URL with Unicode path",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_doesNotMatchValidUrlWithInvalidProtocol() throws Exception {
+        String url = "ftp://www.example.com";
+        assertFalse("Should not match URL with invalid protocol",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesValidUrlWithPort() throws Exception {
+        String url = "http://www.example.com:8080";
+        assertTrue("Should match URL with port",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesUrlWithPortAndQuery() throws Exception {
+        String url = "http://www.example.com:8080/?foo=bar";
+        assertTrue("Should match URL with port and query",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesUrlWithTilde() throws Exception {
+        String url = "http://www.example.com:8080/~user/?foo=bar";
+        assertTrue("Should match URL with tilde",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesProtocolCaseInsensitive() throws Exception {
+        String url = "hTtP://android.com";
+        assertTrue("Protocol matching should be case insensitive",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesUrlStartingWithHttpAndDoesNotHaveTld() throws Exception {
+        String url = "http://android/#notld///a/n/d/r/o/i/d&p1=1&p2=2";
+        assertTrue("Should match URL without a TLD and starting with http ",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_doesNotMatchUrlsWithoutProtocolAndWithUnknownTld()
+            throws Exception {
+        String url = "thank.you";
+        assertFalse("Should not match URL that does not start with a protocol and " +
+                "does not contain a known TLD",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_doesNotMatchUrlWithInvalidRequestParameter() throws Exception {
+        String url = "http://android.com?p=value";
+        assertFalse("Should not match URL with invalid request parameter",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_doesNotPartiallyMatchUnknownProtocol() throws Exception {
+        String url = "ftp://foo.bar/baz";
+        assertFalse("Should not partially match URL with unknown protocol",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).find());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesValidUrlWithEmoji() throws Exception {
+        String url = "Thank\u263A.com";
+        assertTrue("Should match URL with emoji",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_doesNotMatchUrlsWithEmojiWithoutProtocolAndWithoutKnownTld()
+            throws Exception {
+        String url = "Thank\u263A.you";
+        assertFalse("Should not match URLs containing emoji and with unknown TLD",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_doesNotMatchEmailAddress()
+            throws Exception {
+        String url = "android@android.com";
+        assertFalse("Should not match email address",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesDomainNameWithSurrogatePairs() throws Exception {
+        String url = "android\uD83C\uDF38.com";
+        assertTrue("Should match domain name with Unicode surrogate pairs",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesTldWithSurrogatePairs() throws Exception {
+        String url = "http://android.\uD83C\uDF38com";
+        assertTrue("Should match TLD with Unicode surrogate pairs",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_matchesPathWithSurrogatePairs() throws Exception {
+        String url = "http://android.com/path-with-\uD83C\uDF38?v=\uD83C\uDF38";
+        assertTrue("Should match path and query with Unicode surrogate pairs",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    @SmallTest
+    public void testAutoLinkWebUrl_doesNotMatchUrlWithExcludedSurrogate() throws Exception {
+        String url = "http://android\uD83F\uDFFE.com";
+        assertFalse("Should not match URL with excluded Unicode surrogate pair",
+                Patterns.AUTOLINK_WEB_URL.matcher(url).matches());
+    }
+
+    //Tests for Patterns.IP_ADDRESS
+
+    @SmallTest
     public void testIpPattern() throws Exception {
         boolean t;
 
@@ -118,34 +432,85 @@
         assertFalse("Invalid IP", t);
     }
 
+    //Tests for Patterns.DOMAIN_NAME
+
     @SmallTest
-    @Suppress // Failing.
-    public void testDomainPattern() throws Exception {
-        boolean t;
-
-        t = Patterns.DOMAIN_NAME.matcher("mail.example.com").matches();
-        assertTrue("Valid domain", t);
-
-        t = Patterns.DOMAIN_NAME.matcher("google.me").matches();
-        assertTrue("Valid domain", t);
-
-        // Internationalized domains.
-        t = Patterns.DOMAIN_NAME.matcher("\uD604\uAE08\uC601\uC218\uC99D.kr").matches();
-        assertTrue("Valid domain", t);
-
-        t = Patterns.DOMAIN_NAME.matcher("__+&42.xer").matches();
-        assertFalse("Invalid domain", t);
-
-        // Obsolete domain .yu
-        t = Patterns.DOMAIN_NAME.matcher("test.yu").matches();
-        assertFalse("Obsolete country code top level domain", t);
-
-        // Testing top level Arabic country code domain in Punycode:
-        t = Patterns.DOMAIN_NAME.matcher("xn--4gbrim.xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c").matches();
-        assertTrue("Valid domain", t);
+    public void testDomain_matchesPunycodeTld() throws Exception {
+        String domain = "xn--fsqu00a.xn--0zwm56d";
+        assertTrue("Should match domain name in Punycode",
+                Patterns.DOMAIN_NAME.matcher(domain).matches());
     }
 
     @SmallTest
+    public void testDomain_doesNotMatchPunycodeThatStartsWithDash() throws Exception {
+        String domain = "xn--fsqu00a.-xn--0zwm56d";
+        assertFalse("Should not match Punycode TLD that starts with a dash",
+                Patterns.DOMAIN_NAME.matcher(domain).matches());
+    }
+
+    @SmallTest
+    public void testDomain_doesNotMatchPunycodeThatEndsWithDash() throws Exception {
+        String domain = "xn--fsqu00a.xn--0zwm56d-";
+        assertFalse("Should not match Punycode TLD that ends with a dash",
+                Patterns.DOMAIN_NAME.matcher(domain).matches());
+    }
+
+    @SmallTest
+    public void testDomain_doesNotMatchPunycodeLongerThanAllowed() throws Exception {
+        String tld = "xn--";
+        for(int i=0; i<=6; i++) {
+            tld += "0123456789";
+        }
+        String domain = "xn--fsqu00a." + tld;
+        assertFalse("Should not match Punycode TLD that is longer than 63 chars",
+                Patterns.DOMAIN_NAME.matcher(domain).matches());
+    }
+
+    @SmallTest
+    public void testDomain_matchesObsoleteTld() throws Exception {
+        String domain = "test.yu";
+        assertTrue("Should match domain names with obsolete TLD",
+                Patterns.DOMAIN_NAME.matcher(domain).matches());
+    }
+
+    @SmallTest
+    public void testDomain_matchesWithSubDomain() throws Exception {
+        String domain = "mail.example.com";
+        assertTrue("Should match domain names with subdomains",
+                Patterns.DOMAIN_NAME.matcher(domain).matches());
+    }
+
+    @SmallTest
+    public void testDomain_matchesWithoutSubDomain() throws Exception {
+        String domain = "android.me";
+        assertTrue("Should match domain names without subdomains",
+                Patterns.DOMAIN_NAME.matcher(domain).matches());
+    }
+
+    @SmallTest
+    public void testDomain_matchesUnicodeDomainNames() throws Exception {
+        String domain = "\uD604\uAE08\uC601\uC218\uC99D.kr";
+        assertTrue("Should match unicodedomain names",
+                Patterns.DOMAIN_NAME.matcher(domain).matches());
+    }
+
+    @SmallTest
+    public void testDomain_doesNotMatchInvalidDomain() throws Exception {
+        String domain = "__+&42.xer";
+        assertFalse("Should not match invalid domain name",
+                Patterns.DOMAIN_NAME.matcher(domain).matches());
+    }
+
+    @SmallTest
+    public void testDomain_matchesPunycodeArabicDomainName() throws Exception {
+        String domain = "xn--4gbrim.xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c";
+        assertTrue("Should match Punycode Arabic domain name",
+                Patterns.DOMAIN_NAME.matcher(domain).matches());
+    }
+
+    //Tests for Patterns.PHONE
+
+    @SmallTest
     public void testPhonePattern() throws Exception {
         boolean t;
 
diff --git a/core/tests/coretests/src/android/widget/DatePickerActivity.java b/core/tests/coretests/src/android/widget/DatePickerActivity.java
new file mode 100644
index 0000000..c3b25a1
--- /dev/null
+++ b/core/tests/coretests/src/android/widget/DatePickerActivity.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.widget;
+
+import android.app.Activity;
+import android.os.Bundle;
+import com.android.frameworks.coretests.R;
+
+/**
+ * A minimal application for DatePickerFocusTest.
+ */
+public class DatePickerActivity extends Activity {
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.datepicker_layout);
+    }
+}
diff --git a/core/tests/coretests/src/android/widget/DatePickerFocusTest.java b/core/tests/coretests/src/android/widget/DatePickerFocusTest.java
new file mode 100644
index 0000000..513e40f
--- /dev/null
+++ b/core/tests/coretests/src/android/widget/DatePickerFocusTest.java
@@ -0,0 +1,250 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.widget;
+
+import android.app.Activity;
+import android.app.Instrumentation;
+import android.os.SystemClock;
+import android.test.ActivityInstrumentationTestCase2;
+import android.view.KeyEvent;
+import android.view.View;
+
+import com.android.frameworks.coretests.R;
+
+/**
+ * Test {@link DatePicker} focus changes.
+ */
+public class DatePickerFocusTest extends ActivityInstrumentationTestCase2<DatePickerActivity> {
+
+    private Activity mActivity;
+    private Instrumentation mInstrumentation;
+    private DatePicker mDatePicker;
+
+    public DatePickerFocusTest() {
+        super(DatePickerActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        mActivity = getActivity();
+        mInstrumentation = getInstrumentation();
+
+        mDatePicker = (DatePicker) mActivity.findViewById(R.id.datePicker);
+    }
+
+    /**
+     * Tabs (forward and backward) through the DatePicker to ensure the correct
+     * Views gain focus.
+     */
+    public void testFocusTravel() throws Throwable {
+        runTestOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                assertTrue(mDatePicker.requestFocus());
+            }
+        });
+        assertViewHasFocus(com.android.internal.R.id.date_picker_header_year);
+        sendKey(KeyEvent.KEYCODE_TAB);
+        assertViewHasFocus(com.android.internal.R.id.prev);
+        sendKey(KeyEvent.KEYCODE_TAB);
+        assertViewHasFocus(com.android.internal.R.id.next);
+        sendKey(KeyEvent.KEYCODE_TAB);
+        assertViewHasFocus(com.android.internal.R.id.day_picker_view_pager);
+        sendKey(KeyEvent.KEYCODE_TAB);
+        assertViewHasFocus(R.id.belowPicker);
+        sendShiftKey(KeyEvent.KEYCODE_TAB);
+        assertViewHasFocus(com.android.internal.R.id.day_picker_view_pager);
+        sendShiftKey(KeyEvent.KEYCODE_TAB);
+        assertViewHasFocus(com.android.internal.R.id.next);
+        sendShiftKey(KeyEvent.KEYCODE_TAB);
+        assertViewHasFocus(com.android.internal.R.id.prev);
+        sendShiftKey(KeyEvent.KEYCODE_TAB);
+        assertViewHasFocus(com.android.internal.R.id.date_picker_header_year);
+    }
+
+    private void sendKey(int keycode) {
+        mInstrumentation.sendKeyDownUpSync(keycode);
+        mInstrumentation.waitForIdleSync();
+    }
+
+    private void assertViewHasFocus(final int id) throws Throwable {
+        runTestOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                View view = mActivity.findViewById(id);
+                assertTrue(view.hasFocus());
+            }
+        });
+    }
+
+    private void sendShiftKey(int keycode) {
+        final KeyEvent shiftDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT);
+        mInstrumentation.sendKeySync(shiftDown);
+
+        final KeyEvent keyDown = new KeyEvent(SystemClock.uptimeMillis(),
+                SystemClock.uptimeMillis(), KeyEvent.ACTION_DOWN, keycode, 0,
+                KeyEvent.META_SHIFT_ON);
+        mInstrumentation.sendKeySync(keyDown);
+
+        final KeyEvent keyUp = new KeyEvent(SystemClock.uptimeMillis(),
+                SystemClock.uptimeMillis(), KeyEvent.ACTION_UP, keycode, 0,
+                KeyEvent.META_SHIFT_ON);
+        mInstrumentation.sendKeySync(keyUp);
+
+        final KeyEvent shiftUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT);
+        mInstrumentation.sendKeySync(shiftUp);
+
+        mInstrumentation.waitForIdleSync();
+    }
+
+    /**
+     * Tests to ensure the keyboard can select the current year.
+     */
+    public void testYearChoice() throws Throwable {
+        setKnownDate();
+        runTestOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                View year = mDatePicker.
+                        findViewById(com.android.internal.R.id.date_picker_header_year);
+                assertTrue(year.requestFocus());
+            }
+        });
+        sendKey(KeyEvent.KEYCODE_ENTER);
+        runTestOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                View yearSelect = mDatePicker.
+                        findViewById(com.android.internal.R.id.date_picker_year_picker);
+                assertEquals(yearSelect, mDatePicker.findFocus());
+            }
+        });
+        sendKey(KeyEvent.KEYCODE_DPAD_UP);
+        sendKey(KeyEvent.KEYCODE_ENTER);
+        runTestOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                View yearSelect = mDatePicker.
+                        findViewById(com.android.internal.R.id.date_picker_year_picker);
+                assertNotSame(View.VISIBLE, yearSelect.getVisibility());
+                View year = mDatePicker.
+                        findViewById(com.android.internal.R.id.date_picker_header_year);
+                assertTrue(year.hasFocus());
+                assertEquals(2014, mDatePicker.getYear());
+            }
+        });
+    }
+
+    public void testArrowThroughDays() throws Throwable {
+        setKnownDate();
+        runTestOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                View prev = mDatePicker.findViewById(com.android.internal.R.id.next);
+                prev.requestFocus();
+            }
+        });
+        sendKey(KeyEvent.KEYCODE_TAB);
+        // Should select the current date and the date shouldn't change
+        sendKey(KeyEvent.KEYCODE_ENTER);
+        assertDateIs(12, 31, 2015);
+        // Move right to January 24, 2016
+        sendKey(KeyEvent.KEYCODE_DPAD_RIGHT);
+        sendKey(KeyEvent.KEYCODE_ENTER);
+        assertDateIs(1, 24, 2016);
+        // Move down to January 31, 2016
+        sendKey(KeyEvent.KEYCODE_DPAD_DOWN);
+        sendKey(KeyEvent.KEYCODE_ENTER);
+        assertDateIs(1, 31, 2016);
+        // Move up to January 5, 2016
+        sendKey(KeyEvent.KEYCODE_DPAD_UP);
+        sendKey(KeyEvent.KEYCODE_DPAD_UP);
+        sendKey(KeyEvent.KEYCODE_DPAD_UP);
+        sendKey(KeyEvent.KEYCODE_DPAD_UP);
+        sendKey(KeyEvent.KEYCODE_DPAD_RIGHT);
+        sendKey(KeyEvent.KEYCODE_DPAD_RIGHT);
+        sendKey(KeyEvent.KEYCODE_ENTER);
+        assertDateIs(1, 5, 2016);
+        // Move up to prev arrow key
+        sendKey(KeyEvent.KEYCODE_DPAD_UP);
+        assertViewHasFocus(com.android.internal.R.id.prev);
+        // tab back into the day-selection pager
+        sendKey(KeyEvent.KEYCODE_TAB);
+        sendKey(KeyEvent.KEYCODE_TAB);
+        sendKey(KeyEvent.KEYCODE_ENTER);
+        assertViewHasFocus(com.android.internal.R.id.day_picker_view_pager);
+        assertDateIs(1, 5, 2016);
+
+        // Move up out again, then down back into the day-selection pager.
+        // It should land right below the prev button (1/3/2016)
+        sendKey(KeyEvent.KEYCODE_DPAD_UP);
+        sendKey(KeyEvent.KEYCODE_DPAD_DOWN);
+        sendKey(KeyEvent.KEYCODE_ENTER);
+        assertViewHasFocus(com.android.internal.R.id.day_picker_view_pager);
+        assertDateIs(1, 3, 2016);
+
+        // Move left to previous month (12/12/2015)
+        sendKey(KeyEvent.KEYCODE_DPAD_LEFT);
+        sendKey(KeyEvent.KEYCODE_ENTER);
+        assertDateIs(12, 12, 2015);
+        // Now make sure the start of the month works
+        // Move up to 12/5/2015 and right to 1/1/2016
+        sendKey(KeyEvent.KEYCODE_DPAD_UP);
+        sendKey(KeyEvent.KEYCODE_DPAD_RIGHT);
+        sendKey(KeyEvent.KEYCODE_ENTER);
+        assertDateIs(1, 1, 2016);
+        // Now make sure the left key goes back to previous month (12/5/2015)
+        sendKey(KeyEvent.KEYCODE_DPAD_LEFT);
+        sendKey(KeyEvent.KEYCODE_ENTER);
+        assertDateIs(12, 5, 2015);
+        // Now go to a mismatched row (no such row on previous month)
+        // This moves over to 1/31/2016 and then left to 12/31/2015
+        sendKey(KeyEvent.KEYCODE_DPAD_DOWN);
+        sendKey(KeyEvent.KEYCODE_DPAD_DOWN);
+        sendKey(KeyEvent.KEYCODE_DPAD_DOWN);
+        sendKey(KeyEvent.KEYCODE_DPAD_RIGHT);
+        sendKey(KeyEvent.KEYCODE_DPAD_DOWN);
+        sendKey(KeyEvent.KEYCODE_DPAD_DOWN);
+        sendKey(KeyEvent.KEYCODE_DPAD_LEFT);
+        sendKey(KeyEvent.KEYCODE_ENTER);
+        assertDateIs(12, 31, 2015);
+    }
+
+    private void assertDateIs(int month, final int day, final int year) throws Throwable {
+        final int monthInt = month - 1; // months are 0-based
+        runTestOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                assertEquals(day, mDatePicker.getDayOfMonth());
+                assertEquals(year, mDatePicker.getYear());
+                assertEquals(monthInt, mDatePicker.getMonth());
+            }
+        });
+    }
+
+    private void setKnownDate() throws Throwable {
+        runTestOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                mDatePicker.updateDate(2015, 11, 31); // December 31, 2015
+            }
+        });
+        mInstrumentation.waitForIdleSync();
+    }
+}
diff --git a/data/fonts/fonts.xml b/data/fonts/fonts.xml
index 554b6f1..731bf42 100644
--- a/data/fonts/fonts.xml
+++ b/data/fonts/fonts.xml
@@ -344,7 +344,7 @@
     <family>
         <font weight="400" style="normal">NanumGothic.ttf</font>
     </family>
-    <family lang="und-Qaae">
+    <family lang="und-Zsye">
         <font weight="400" style="normal">NotoColorEmoji.ttf</font>
     </family>
     <family>
diff --git a/drm/java/android/drm/DrmManagerClient.java b/drm/java/android/drm/DrmManagerClient.java
index c05ea2e..704f0ce 100644
--- a/drm/java/android/drm/DrmManagerClient.java
+++ b/drm/java/android/drm/DrmManagerClient.java
@@ -38,13 +38,14 @@
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * The main programming interface for the DRM framework. An application must instantiate this class
  * to access DRM agents through the DRM framework.
  *
  */
-public class DrmManagerClient {
+public class DrmManagerClient implements AutoCloseable {
     /**
      * Indicates that a request was successful or that no error occurred.
      */
@@ -61,6 +62,7 @@
     HandlerThread mEventThread;
     private static final String TAG = "DrmManagerClient";
 
+    private final AtomicBoolean mClosed = new AtomicBoolean();
     private final CloseGuard mCloseGuard = CloseGuard.get();
 
     static {
@@ -117,7 +119,6 @@
 
     private int mUniqueId;
     private long mNativeContext;
-    private volatile boolean mReleased;
     private Context mContext;
     private InfoHandler mInfoHandler;
     private EventHandler mEventHandler;
@@ -261,41 +262,47 @@
     @Override
     protected void finalize() throws Throwable {
         try {
-            if (mCloseGuard != null) {
-                mCloseGuard.warnIfOpen();
-            }
-            release();
+            mCloseGuard.warnIfOpen();
+            close();
         } finally {
             super.finalize();
         }
     }
 
     /**
-     * Releases resources associated with the current session of DrmManagerClient.
-     *
-     * It is considered good practice to call this method when the {@link DrmManagerClient} object
-     * is no longer needed in your application. After release() is called,
-     * {@link DrmManagerClient} is no longer usable since it has lost all of its required resource.
+     * Releases resources associated with the current session of
+     * DrmManagerClient. It is considered good practice to call this method when
+     * the {@link DrmManagerClient} object is no longer needed in your
+     * application. After this method is called, {@link DrmManagerClient} is no
+     * longer usable since it has lost all of its required resource.
      */
-    public void release() {
-        if (mReleased) return;
-        mReleased = true;
-
-        if (mEventHandler != null) {
-            mEventThread.quit();
-            mEventThread = null;
-        }
-        if (mInfoHandler != null) {
-            mInfoThread.quit();
-            mInfoThread = null;
-        }
-        mEventHandler = null;
-        mInfoHandler = null;
-        mOnEventListener = null;
-        mOnInfoListener = null;
-        mOnErrorListener = null;
-        _release(mUniqueId);
+    @Override
+    public void close() {
         mCloseGuard.close();
+        if (mClosed.compareAndSet(false, true)) {
+            if (mEventHandler != null) {
+                mEventThread.quit();
+                mEventThread = null;
+            }
+            if (mInfoHandler != null) {
+                mInfoThread.quit();
+                mInfoThread = null;
+            }
+            mEventHandler = null;
+            mInfoHandler = null;
+            mOnEventListener = null;
+            mOnInfoListener = null;
+            mOnErrorListener = null;
+            _release(mUniqueId);
+        }
+    }
+
+    /**
+     * @deprecated replaced by {@link #close()}.
+     */
+    @Deprecated
+    public void release() {
+        close();
     }
 
     /**
diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java
index da58884..175c726 100644
--- a/graphics/java/android/graphics/BitmapFactory.java
+++ b/graphics/java/android/graphics/BitmapFactory.java
@@ -163,8 +163,11 @@
         public boolean inPremultiplied;
 
         /**
-         * If dither is true, the decoder will attempt to dither the decoded
-         * image.
+         * @deprecated As of {@link android.os.Build.VERSION_CODES#N}, this is
+         * ignored.
+         *
+         * In {@link android.os.Build.VERSION_CODES#M} and below, if dither is
+         * true, the decoder will attempt to dither the decoded image.
          */
         public boolean inDither;
 
@@ -308,7 +311,11 @@
         public boolean inInputShareable;
 
         /**
-         * If inPreferQualityOverSpeed is set to true, the decoder will try to
+         * @deprecated As of {@link android.os.Build.VERSION_CODES#N}, this is
+         * ignored.  The output will always be high quality.
+         *
+         * In {@link android.os.Build.VERSION_CODES#M} and below, if
+         * inPreferQualityOverSpeed is set to true, the decoder will try to
          * decode the reconstructed image to a higher quality even at the
          * expense of the decoding speed. Currently the field only affects JPEG
          * decode, in the case of which a more accurate, but slightly slower,
@@ -347,8 +354,6 @@
          */
         public byte[] inTempStorage;
 
-        private native void requestCancel();
-
         /**
          * Flag to indicate that cancel has been called on this object.  This
          * is useful if there's an intermediary that wants to first decode the
@@ -359,16 +364,19 @@
         public boolean mCancel;
 
         /**
-         *  This can be called from another thread while this options object is
-         *  inside a decode... call. Calling this will notify the decoder that
-         *  it should cancel its operation. This is not guaranteed to cancel
-         *  the decode, but if it does, the decoder... operation will return
-         *  null, or if inJustDecodeBounds is true, will set outWidth/outHeight
+         *  @deprecated As of {@link android.os.Build.VERSION_CODES#N}, this
+         *  will not affect the decode, though it will still set mCancel.
+         *
+         *  In {@link android.os.Build.VERSION_CODES#M} and below, if this can
+         *  be called from another thread while this options object is inside
+         *  a decode... call. Calling this will notify the decoder that it
+         *  should cancel its operation. This is not guaranteed to cancel the
+         *  decode, but if it does, the decoder... operation will return null,
+         *  or if inJustDecodeBounds is true, will set outWidth/outHeight
          *  to -1
          */
         public void requestCancelDecode() {
             mCancel = true;
-            requestCancel();
         }
     }
 
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java
index d5166ab..1cc5346 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -654,6 +654,12 @@
     /**
      * Return, in ctm, the current transformation matrix. This does not alter
      * the matrix in the canvas, but just returns a copy of it.
+     *
+     * @deprecated {@link #isHardwareAccelerated() Hardware accelerated} canvases may have any
+     * matrix when passed to a View or Drawable, as it is implementation defined where in the
+     * hierarchy such canvases are created. It is recommended in such cases to either draw contents
+     * irrespective of the current matrix, or to track relevant transform state outside of the
+     * canvas.
      */
     @Deprecated
     public void getMatrix(@NonNull Matrix ctm) {
@@ -663,6 +669,12 @@
     /**
      * Return a new matrix with a copy of the canvas' current transformation
      * matrix.
+     *
+     * @deprecated {@link #isHardwareAccelerated() Hardware accelerated} canvases may have any
+     * matrix when passed to a View or Drawable, as it is implementation defined where in the
+     * hierarchy such canvases are created. It is recommended in such cases to either draw contents
+     * irrespective of the current matrix, or to track relevant transform state outside of the
+     * canvas.
      */
     @Deprecated
     public final @NonNull Matrix getMatrix() {
@@ -812,6 +824,7 @@
      * @deprecated Unlike all other clip calls this API does not respect the
      *             current matrix. Use {@link #clipRect(Rect)} as an alternative.
      */
+    @Deprecated
     public boolean clipRegion(@NonNull Region region, @NonNull Region.Op op) {
         return native_clipRegion(mNativeCanvasWrapper, region.ni(), op.nativeInt);
     }
@@ -829,6 +842,7 @@
      * @deprecated Unlike all other clip calls this API does not respect the
      *             current matrix. Use {@link #clipRect(Rect)} as an alternative.
      */
+    @Deprecated
     public boolean clipRegion(@NonNull Region region) {
         return clipRegion(region, Region.Op.INTERSECT);
     }
@@ -1830,16 +1844,16 @@
      * Draw the text in the array, with each character's origin specified by
      * the pos array.
      *
-     * This method does not support glyph composition and decomposition and
-     * should therefore not be used to render complex scripts. It also doesn't
-     * handle supplementary characters (eg emoji).
-     *
      * @param text     The text to be drawn
      * @param index    The index of the first character to draw
      * @param count    The number of characters to draw, starting from index.
      * @param pos      Array of [x,y] positions, used to position each
      *                 character
      * @param paint    The paint used for the text (e.g. color, size, style)
+     *
+     * @deprecated This method does not support glyph composition and decomposition and
+     * should therefore not be used to render complex scripts. It also doesn't
+     * handle supplementary characters (eg emoji).
      */
     @Deprecated
     public void drawPosText(@NonNull char[] text, int index, int count,
@@ -1857,13 +1871,13 @@
      * Draw the text in the array, with each character's origin specified by
      * the pos array.
      *
-     * This method does not support glyph composition and decomposition and
-     * should therefore not be used to render complex scripts. It also doesn't
-     * handle supplementary characters (eg emoji).
-     *
      * @param text  The text to be drawn
      * @param pos   Array of [x,y] positions, used to position each character
      * @param paint The paint used for the text (e.g. color, size, style)
+     *
+     * @deprecated This method does not support glyph composition and decomposition and
+     * should therefore not be used to render complex scripts. It also doesn't
+     * handle supplementary characters (eg emoji).
      */
     @Deprecated
     public void drawPosText(@NonNull String text, @NonNull @Size(multiple=2) float[] pos,
diff --git a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java
index 1857345..84ca546 100644
--- a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java
+++ b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java
@@ -19,6 +19,7 @@
 import android.animation.AnimatorListenerAdapter;
 import android.animation.AnimatorSet;
 import android.animation.Animator.AnimatorListener;
+import android.animation.ValueAnimator;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.res.ColorStateList;
@@ -140,6 +141,15 @@
     /** Local, mutable animator set. */
     private final AnimatorSet mAnimatorSet = new AnimatorSet();
 
+
+    private final ValueAnimator.AnimatorUpdateListener mUpdateListener =
+            new ValueAnimator.AnimatorUpdateListener() {
+                @Override
+                public void onAnimationUpdate(ValueAnimator animation) {
+                    invalidateSelf();
+                }
+            };
+
     /**
      * The resources against which this drawable was created. Used to attempt
      * to inflate animators if applyTheme() doesn't get called.
@@ -201,9 +211,6 @@
     @Override
     public void draw(Canvas canvas) {
         mAnimatedVectorState.mVectorDrawable.draw(canvas);
-        if (isStarted()) {
-            invalidateSelf();
-        }
     }
 
     @Override
@@ -486,6 +493,7 @@
          *            animators, or {@code null} if not available
          */
         public void prepareLocalAnimators(@NonNull AnimatorSet animatorSet,
+                @NonNull ValueAnimator.AnimatorUpdateListener updateListener,
                 @Nullable Resources res) {
             // Check for uninflated animators. We can remove this after we add
             // support for Animator.applyTheme(). See comments in inflate().
@@ -511,6 +519,17 @@
                     final Animator nextAnim = prepareLocalAnimator(i);
                     builder.with(nextAnim);
                 }
+
+                // Setup a value animator to get animation update callbacks.
+                long totalDuration = animatorSet.getTotalDuration();
+                ValueAnimator updateAnim = ValueAnimator.ofFloat(0f, 1f);
+                if (totalDuration == ValueAnimator.DURATION_INFINITE) {
+                    updateAnim.setRepeatCount(ValueAnimator.INFINITE);
+                } else {
+                    updateAnim.setDuration(totalDuration);
+                }
+                updateAnim.addUpdateListener(updateListener);
+                builder.with(updateAnim);
             }
         }
 
@@ -603,7 +622,7 @@
     @NonNull
     private void ensureAnimatorSet() {
         if (!mHasAnimatorSet) {
-            mAnimatedVectorState.prepareLocalAnimators(mAnimatorSet, mRes);
+            mAnimatedVectorState.prepareLocalAnimators(mAnimatorSet, mUpdateListener, mRes);
             mHasAnimatorSet = true;
             mRes = null;
         }
diff --git a/graphics/java/android/graphics/drawable/RippleBackground.java b/graphics/java/android/graphics/drawable/RippleBackground.java
index d313aa5..6bd2646 100644
--- a/graphics/java/android/graphics/drawable/RippleBackground.java
+++ b/graphics/java/android/graphics/drawable/RippleBackground.java
@@ -33,6 +33,7 @@
  * Draws a ripple background.
  */
 class RippleBackground extends RippleComponent {
+
     private static final TimeInterpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
 
     private static final int OPACITY_ENTER_DURATION = 600;
@@ -48,8 +49,14 @@
     // Software rendering properties.
     private float mOpacity = 0;
 
-    public RippleBackground(RippleDrawable owner, Rect bounds, boolean forceSoftware) {
+    /** Whether this ripple is bounded. */
+    private boolean mIsBounded;
+
+    public RippleBackground(RippleDrawable owner, Rect bounds, boolean isBounded,
+            boolean forceSoftware) {
         super(owner, bounds, forceSoftware);
+
+        mIsBounded = isBounded;
     }
 
     public boolean isVisible() {
@@ -105,7 +112,8 @@
         final AnimatorSet.Builder builder = set.play(exit);
 
         // Linear "fast" enter based on current opacity.
-        final int fastEnterDuration = (int) ((1 - mOpacity) * OPACITY_ENTER_DURATION_FAST);
+        final int fastEnterDuration = mIsBounded ?
+                (int) ((1 - mOpacity) * OPACITY_ENTER_DURATION_FAST) : 0;
         if (fastEnterDuration > 0) {
             final ObjectAnimator enter = ObjectAnimator.ofFloat(this, RippleBackground.OPACITY, 1);
             enter.setInterpolator(LINEAR_INTERPOLATOR);
@@ -131,15 +139,18 @@
         mPropX = CanvasProperty.createFloat(0);
         mPropY = CanvasProperty.createFloat(0);
 
-        final int fastEnterDuration = (int) ((1 - mOpacity) * OPACITY_ENTER_DURATION_FAST);
+        final int fastEnterDuration = mIsBounded ?
+                (int) ((1 - mOpacity) * OPACITY_ENTER_DURATION_FAST) : 0;
 
         // Linear exit after enter is completed.
         final RenderNodeAnimator exit = new RenderNodeAnimator(
                 mPropPaint, RenderNodeAnimator.PAINT_ALPHA, 0);
         exit.setInterpolator(LINEAR_INTERPOLATOR);
         exit.setDuration(OPACITY_EXIT_DURATION);
-        exit.setStartDelay(fastEnterDuration);
-        exit.setStartValue(targetAlpha);
+        if (fastEnterDuration > 0) {
+            exit.setStartDelay(fastEnterDuration);
+            exit.setStartValue(targetAlpha);
+        }
         set.add(exit);
 
         // Linear "fast" enter based on current opacity.
diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java
index 5213e10..9c691e5 100644
--- a/graphics/java/android/graphics/drawable/RippleDrawable.java
+++ b/graphics/java/android/graphics/drawable/RippleDrawable.java
@@ -540,7 +540,8 @@
      */
     private void tryBackgroundEnter(boolean focused) {
         if (mBackground == null) {
-            mBackground = new RippleBackground(this, mHotspotBounds, mForceSoftware);
+            final boolean isBounded = isBounded();
+            mBackground = new RippleBackground(this, mHotspotBounds, isBounded, mForceSoftware);
         }
 
         mBackground.setup(mState.mMaxRadius, mDensity);
diff --git a/include/androidfw/AssetManager.h b/include/androidfw/AssetManager.h
index 3d4e47d..914ac3d 100644
--- a/include/androidfw/AssetManager.h
+++ b/include/androidfw/AssetManager.h
@@ -100,16 +100,17 @@
      * then on success, *cookie is set to the value corresponding to the
      * newly-added asset source.
      */
-    bool addAssetPath(const String8& path, int32_t* cookie, bool appAsLib=false);
+    bool addAssetPath(const String8& path, int32_t* cookie,
+        bool appAsLib=false, bool isSystemAsset=false);
     bool addOverlayPath(const String8& path, int32_t* cookie);
 
-    /*                                                                       
+    /*
      * Convenience for adding the standard system assets.  Uses the
      * ANDROID_ROOT environment variable to find them.
      */
     bool addDefaultAssets();
 
-    /*                                                                       
+    /*
      * Iterate over the asset paths in this manager.  (Previously
      * added via addAssetPath() and addDefaultAssets().)  On first call,
      * 'cookie' must be 0, resulting in the first cookie being returned.
@@ -118,7 +119,7 @@
      */
     int32_t nextAssetPath(const int32_t cookie) const;
 
-    /*                                                                       
+    /*
      * Return an asset path in the manager.  'which' must be between 0 and
      * countAssetPaths().
      */
@@ -221,11 +222,11 @@
      * the current data.
      */
     bool isUpToDate();
-    
+
     /**
      * Get the known locales for this asset manager object.
      */
-    void getLocales(Vector<String8>* locales) const;
+    void getLocales(Vector<String8>* locales, bool includeSystemLocales=true) const;
 
     /**
      * Generate idmap data to translate resources IDs between a package and a
@@ -237,11 +238,13 @@
 private:
     struct asset_path
     {
-        asset_path() : path(""), type(kFileTypeRegular), idmap(""), isSystemOverlay(false) {}
+        asset_path() : path(""), type(kFileTypeRegular), idmap(""),
+                       isSystemOverlay(false), isSystemAsset(false) {}
         String8 path;
         FileType type;
         String8 idmap;
         bool isSystemOverlay;
+        bool isSystemAsset;
     };
 
     Asset* openInPathLocked(const char* fileName, AccessMode mode,
diff --git a/include/androidfw/ResourceTypes.h b/include/androidfw/ResourceTypes.h
index 49b6333..428a2b8 100644
--- a/include/androidfw/ResourceTypes.h
+++ b/include/androidfw/ResourceTypes.h
@@ -1552,9 +1552,9 @@
 
     status_t add(Asset* asset, const int32_t cookie=-1, bool copyData=false);
     status_t add(Asset* asset, Asset* idmapAsset, const int32_t cookie=-1, bool copyData=false,
-            bool appAsLib=false);
+            bool appAsLib=false, bool isSystemAsset=false);
 
-    status_t add(ResTable* src);
+    status_t add(ResTable* src, bool isSystemAsset=false);
     status_t addEmpty(const int32_t cookie);
 
     status_t getError() const;
@@ -1822,9 +1822,9 @@
 
     // Return the configurations (ResTable_config) that we know about
     void getConfigurations(Vector<ResTable_config>* configs, bool ignoreMipmap=false,
-            bool ignoreAndroidPackage=false) const;
+            bool ignoreAndroidPackage=false, bool includeSystemConfigs=true) const;
 
-    void getLocales(Vector<String8>* locales) const;
+    void getLocales(Vector<String8>* locales, bool includeSystemLocales=true) const;
 
     // Generate an idmap.
     //
@@ -1860,7 +1860,7 @@
     typedef Vector<Type*> TypeList;
 
     status_t addInternal(const void* data, size_t size, const void* idmapData, size_t idmapDataSize,
-            bool appAsLib, const int32_t cookie, bool copyData);
+            bool appAsLib, const int32_t cookie, bool copyData, bool isSystemAsset=false);
 
     ssize_t getResourcePackageIndex(uint32_t resID) const;
 
@@ -1873,10 +1873,11 @@
             size_t nameLen, uint32_t* outTypeSpecFlags) const;
 
     status_t parsePackage(
-        const ResTable_package* const pkg, const Header* const header, bool appAsLib);
+        const ResTable_package* const pkg, const Header* const header,
+        bool appAsLib, bool isSystemAsset);
 
     void print_value(const Package* pkg, const Res_value& value) const;
-    
+
     mutable Mutex               mLock;
 
     status_t                    mError;
diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp
index 8a03b94..6913f43 100644
--- a/libs/androidfw/AssetManager.cpp
+++ b/libs/androidfw/AssetManager.cpp
@@ -176,7 +176,8 @@
     delete[] mVendor;
 }
 
-bool AssetManager::addAssetPath(const String8& path, int32_t* cookie, bool appAsLib)
+bool AssetManager::addAssetPath(
+        const String8& path, int32_t* cookie, bool appAsLib, bool isSystemAsset)
 {
     AutoMutex _l(mLock);
 
@@ -222,6 +223,7 @@
     }
     delete manifestAsset;
 
+    ap.isSystemAsset = isSystemAsset;
     mAssetPaths.add(ap);
 
     // new paths are always added at the end
@@ -233,6 +235,7 @@
     // Load overlays, if any
     asset_path oap;
     for (size_t idx = 0; mZipSet.getOverlay(ap.path, idx, &oap); idx++) {
+        oap.isSystemAsset = isSystemAsset;
         mAssetPaths.add(oap);
     }
 #endif
@@ -340,7 +343,7 @@
     String8 path(root);
     path.appendPath(kSystemAssets);
 
-    return addAssetPath(path, NULL);
+    return addAssetPath(path, NULL, false /* appAsLib */, true /* isSystemAsset */);
 }
 
 int32_t AssetManager::nextAssetPath(const int32_t cookie) const
@@ -682,10 +685,10 @@
         ALOGV("Installing resource asset %p in to table %p\n", ass, mResources);
         if (sharedRes != NULL) {
             ALOGV("Copying existing resources for %s", ap.path.string());
-            mResources->add(sharedRes);
+            mResources->add(sharedRes, ap.isSystemAsset);
         } else {
             ALOGV("Parsing resources for %s", ap.path.string());
-            mResources->add(ass, idmap, nextEntryIdx + 1, !shared, appAsLib);
+            mResources->add(ass, idmap, nextEntryIdx + 1, !shared, appAsLib, ap.isSystemAsset);
         }
         onlyEmptyResources = false;
 
@@ -831,11 +834,11 @@
     return mZipSet.isUpToDate();
 }
 
-void AssetManager::getLocales(Vector<String8>* locales) const
+void AssetManager::getLocales(Vector<String8>* locales, bool includeSystemLocales) const
 {
     ResTable* res = mResources;
     if (res != NULL) {
-        res->getLocales(locales);
+        res->getLocales(locales, includeSystemLocales);
     }
 
     const size_t numLocales = locales->size();
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp
index 21b543e..44f92c7 100644
--- a/libs/androidfw/ResourceTypes.cpp
+++ b/libs/androidfw/ResourceTypes.cpp
@@ -3080,13 +3080,16 @@
 // table that defined the package); the ones after are skins on top of it.
 struct ResTable::PackageGroup
 {
-    PackageGroup(ResTable* _owner, const String16& _name, uint32_t _id, bool appAsLib)
+    PackageGroup(
+            ResTable* _owner, const String16& _name, uint32_t _id,
+            bool appAsLib, bool _isSystemAsset)
         : owner(_owner)
         , name(_name)
         , id(_id)
         , largestTypeId(0)
         , bags(NULL)
         , dynamicRefTable(static_cast<uint8_t>(_id), appAsLib)
+        , isSystemAsset(_isSystemAsset)
     { }
 
     ~PackageGroup() {
@@ -3178,6 +3181,10 @@
     // by having these tables in a per-package scope rather than
     // per-package-group.
     DynamicRefTable                 dynamicRefTable;
+
+    // If the package group comes from a system asset. Used in
+    // determining non-system locales.
+    const bool                      isSystemAsset;
 };
 
 struct ResTable::bag_set
@@ -3572,8 +3579,9 @@
             copyData);
 }
 
-status_t ResTable::add(Asset* asset, Asset* idmapAsset, const int32_t cookie, bool copyData,
-        bool appAsLib) {
+status_t ResTable::add(
+        Asset* asset, Asset* idmapAsset, const int32_t cookie, bool copyData,
+        bool appAsLib, bool isSystemAsset) {
     const void* data = asset->getBuffer(true);
     if (data == NULL) {
         ALOGW("Unable to get buffer of resource asset file");
@@ -3592,20 +3600,21 @@
     }
 
     return addInternal(data, static_cast<size_t>(asset->getLength()),
-            idmapData, idmapSize, appAsLib, cookie, copyData);
+            idmapData, idmapSize, appAsLib, cookie, copyData, isSystemAsset);
 }
 
-status_t ResTable::add(ResTable* src)
+status_t ResTable::add(ResTable* src, bool isSystemAsset)
 {
     mError = src->mError;
 
-    for (size_t i=0; i<src->mHeaders.size(); i++) {
+    for (size_t i=0; i < src->mHeaders.size(); i++) {
         mHeaders.add(src->mHeaders[i]);
     }
 
-    for (size_t i=0; i<src->mPackageGroups.size(); i++) {
+    for (size_t i=0; i < src->mPackageGroups.size(); i++) {
         PackageGroup* srcPg = src->mPackageGroups[i];
-        PackageGroup* pg = new PackageGroup(this, srcPg->name, srcPg->id, false);
+        PackageGroup* pg = new PackageGroup(this, srcPg->name, srcPg->id,
+                false /* appAsLib */, isSystemAsset || srcPg->isSystemAsset);
         for (size_t j=0; j<srcPg->packages.size(); j++) {
             pg->packages.add(srcPg->packages[j]);
         }
@@ -3646,7 +3655,7 @@
 }
 
 status_t ResTable::addInternal(const void* data, size_t dataSize, const void* idmapData, size_t idmapDataSize,
-        bool appAsLib, const int32_t cookie, bool copyData)
+        bool appAsLib, const int32_t cookie, bool copyData, bool isSystemAsset)
 {
     if (!data) {
         return NO_ERROR;
@@ -3749,7 +3758,8 @@
                 return (mError=BAD_TYPE);
             }
 
-            if (parsePackage((ResTable_package*)chunk, header, appAsLib) != NO_ERROR) {
+            if (parsePackage(
+                    (ResTable_package*)chunk, header, appAsLib, isSystemAsset) != NO_ERROR) {
                 return mError;
             }
             curPackage++;
@@ -5663,7 +5673,7 @@
 }
 
 void ResTable::getConfigurations(Vector<ResTable_config>* configs, bool ignoreMipmap,
-        bool ignoreAndroidPackage) const {
+        bool ignoreAndroidPackage, bool includeSystemConfigs) const {
     const size_t packageCount = mPackageGroups.size();
     String16 android("android");
     for (size_t i = 0; i < packageCount; i++) {
@@ -5671,6 +5681,9 @@
         if (ignoreAndroidPackage && android == packageGroup->name) {
             continue;
         }
+        if (!includeSystemConfigs && packageGroup->isSystemAsset) {
+            continue;
+        }
         const size_t typeCount = packageGroup->types.size();
         for (size_t j = 0; j < typeCount; j++) {
             const TypeList& typeList = packageGroup->types[j];
@@ -5707,11 +5720,14 @@
     }
 }
 
-void ResTable::getLocales(Vector<String8>* locales) const
+void ResTable::getLocales(Vector<String8>* locales, bool includeSystemLocales) const
 {
     Vector<ResTable_config> configs;
     ALOGV("calling getConfigurations");
-    getConfigurations(&configs);
+    getConfigurations(&configs,
+            false /* ignoreMipmap */,
+            false /* ignoreAndroidPackage */,
+            includeSystemLocales /* includeSystemConfigs */);
     ALOGV("called getConfigurations size=%d", (int)configs.size());
     const size_t I = configs.size();
 
@@ -5937,7 +5953,7 @@
 }
 
 status_t ResTable::parsePackage(const ResTable_package* const pkg,
-                                const Header* const header, bool appAsLib)
+                                const Header* const header, bool appAsLib, bool isSystemAsset)
 {
     const uint8_t* base = (const uint8_t*)pkg;
     status_t err = validate_chunk(&pkg->header, sizeof(*pkg) - sizeof(pkg->typeIdOffset),
@@ -5985,8 +6001,8 @@
     if (id >= 256) {
         LOG_ALWAYS_FATAL("Package id out of range");
         return NO_ERROR;
-    } else if (id == 0 || appAsLib) {
-        // This is a library so assign an ID
+    } else if (id == 0 || appAsLib || isSystemAsset) {
+        // This is a library or a system asset, so assign an ID
         id = mNextPackageId++;
     }
 
@@ -6018,7 +6034,7 @@
 
         char16_t tmpName[sizeof(pkg->name)/sizeof(pkg->name[0])];
         strcpy16_dtoh(tmpName, pkg->name, sizeof(pkg->name)/sizeof(pkg->name[0]));
-        group = new PackageGroup(this, String16(tmpName), id, appAsLib);
+        group = new PackageGroup(this, String16(tmpName), id, appAsLib, isSystemAsset);
         if (group == NULL) {
             delete package;
             return (mError=NO_MEMORY);
diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk
index f48c509..11056d4 100644
--- a/libs/hwui/Android.mk
+++ b/libs/hwui/Android.mk
@@ -108,6 +108,7 @@
     hwui_src_files += \
         BakedOpDispatcher.cpp \
         BakedOpRenderer.cpp \
+        BakedOpState.cpp \
         OpReorderer.cpp \
         RecordingCanvas.cpp
 
diff --git a/libs/hwui/BakedOpDispatcher.cpp b/libs/hwui/BakedOpDispatcher.cpp
index 0f0768f..097675a 100644
--- a/libs/hwui/BakedOpDispatcher.cpp
+++ b/libs/hwui/BakedOpDispatcher.cpp
@@ -79,7 +79,9 @@
             .setTransform(Matrix4::identity(), TransformFlags::None)
             .setModelViewIdentityEmptyBounds()
             .build();
-    renderer.renderGlop(nullptr, opList.clipSideFlags ? &opList.clip : nullptr, glop);
+    ClipRect renderTargetClip(opList.clip);
+    const ClipBase* clip = opList.clipSideFlags ? &renderTargetClip : nullptr;
+    renderer.renderGlop(nullptr, clip, glop);
 }
 
 void BakedOpDispatcher::onMergedPatchOps(BakedOpRenderer& renderer,
@@ -183,7 +185,9 @@
             .setTransform(Matrix4::identity(), TransformFlags::None)
             .setModelViewIdentityEmptyBounds()
             .build();
-    renderer.renderGlop(nullptr, opList.clipSideFlags ? &opList.clip : nullptr, glop);
+    ClipRect renderTargetClip(opList.clip);
+    const ClipBase* clip = opList.clipSideFlags ? &renderTargetClip : nullptr;
+    renderer.renderGlop(nullptr, clip, glop);
 }
 
 static void renderTextShadow(BakedOpRenderer& renderer, FontRenderer& fontRenderer,
@@ -224,7 +228,7 @@
 };
 
 static void renderTextOp(BakedOpRenderer& renderer, const TextOp& op, const BakedOpState& state,
-        const Rect* renderClip, TextRenderType renderType) {
+        const ClipBase* renderClip, TextRenderType renderType) {
     FontRenderer& fontRenderer = renderer.caches().fontRenderer.getFontRenderer();
 
     if (CC_UNLIKELY(PaintUtils::hasTextShadow(op.paint))) {
@@ -272,7 +276,7 @@
 
     bool forceFinish = (renderType == TextRenderType::Flush);
     bool mustDirtyRenderTarget = renderer.offscreenRenderTarget();
-    const Rect* localOpClip = pureTranslate ? &state.computedState.clipRect : nullptr;
+    const Rect* localOpClip = pureTranslate ? &state.computedState.clipRect() : nullptr;
     fontRenderer.renderPosText(op.paint, localOpClip,
             (const char*) op.glyphs, op.glyphCount, x, y,
             op.positions, mustDirtyRenderTarget ? &layerBounds : nullptr, &functor, forceFinish);
@@ -287,7 +291,8 @@
 
 void BakedOpDispatcher::onMergedTextOps(BakedOpRenderer& renderer,
         const MergedBakedOpList& opList) {
-    const Rect* clip = opList.clipSideFlags ? &opList.clip : nullptr;
+    ClipRect renderTargetClip(opList.clip);
+    const ClipBase* clip = opList.clipSideFlags ? &renderTargetClip : nullptr;
     for (size_t i = 0; i < opList.count; i++) {
         const BakedOpState& state = *(opList.states[i]);
         const TextOp& op = *(static_cast<const TextOp*>(state.op));
@@ -297,26 +302,6 @@
     }
 }
 
-void BakedOpDispatcher::onRenderNodeOp(BakedOpRenderer&, const RenderNodeOp&, const BakedOpState&) {
-    LOG_ALWAYS_FATAL("unsupported operation");
-}
-
-void BakedOpDispatcher::onBeginLayerOp(BakedOpRenderer&, const BeginLayerOp&, const BakedOpState&) {
-    LOG_ALWAYS_FATAL("unsupported operation");
-}
-
-void BakedOpDispatcher::onEndLayerOp(BakedOpRenderer&, const EndLayerOp&, const BakedOpState&) {
-    LOG_ALWAYS_FATAL("unsupported operation");
-}
-
-void BakedOpDispatcher::onCirclePropsOp(BakedOpRenderer&, const CirclePropsOp&, const BakedOpState&) {
-    LOG_ALWAYS_FATAL("unsupported operation");
-}
-
-void BakedOpDispatcher::onRoundRectPropsOp(BakedOpRenderer&, const RoundRectPropsOp&, const BakedOpState&) {
-    LOG_ALWAYS_FATAL("unsupported operation");
-}
-
 namespace VertexBufferRenderFlags {
     enum {
         Offset = 0x1,
@@ -701,14 +686,13 @@
 }
 
 void BakedOpDispatcher::onTextOp(BakedOpRenderer& renderer, const TextOp& op, const BakedOpState& state) {
-    const Rect* clip = state.computedState.clipSideFlags ? &state.computedState.clipRect : nullptr;
-    renderTextOp(renderer, op, state, clip, TextRenderType::Flush);
+    renderTextOp(renderer, op, state, state.computedState.getClipIfNeeded(), TextRenderType::Flush);
 }
 
 void BakedOpDispatcher::onTextOnPathOp(BakedOpRenderer& renderer, const TextOnPathOp& op, const BakedOpState& state) {
     // Note: can't trust clipSideFlags since we record with unmappedBounds == clip.
     // TODO: respect clipSideFlags, once we record with bounds
-    const Rect* renderTargetClip = &state.computedState.clipRect;
+    auto renderTargetClip = state.computedState.clipState;
 
     FontRenderer& fontRenderer = renderer.caches().fontRenderer.getFontRenderer();
     fontRenderer.setFont(op.paint, SkMatrix::I());
diff --git a/libs/hwui/BakedOpDispatcher.h b/libs/hwui/BakedOpDispatcher.h
index ed34ada..4dfdd3f 100644
--- a/libs/hwui/BakedOpDispatcher.h
+++ b/libs/hwui/BakedOpDispatcher.h
@@ -36,13 +36,13 @@
     // Declares all "onMergedBitmapOps(...)" style methods for mergeable op types
 #define X(Type) \
         static void onMerged##Type##s(BakedOpRenderer& renderer, const MergedBakedOpList& opList);
-    MAP_MERGED_OPS(X)
+    MAP_MERGEABLE_OPS(X)
 #undef X
 
     // Declares all "onBitmapOp(...)" style methods for every op type
 #define X(Type) \
         static void on##Type(BakedOpRenderer& renderer, const Type& op, const BakedOpState& state);
-    MAP_OPS(X)
+    MAP_RENDERABLE_OPS(X)
 #undef X
 
 };
diff --git a/libs/hwui/BakedOpRenderer.cpp b/libs/hwui/BakedOpRenderer.cpp
index f8282dc..a0d5fae 100644
--- a/libs/hwui/BakedOpRenderer.cpp
+++ b/libs/hwui/BakedOpRenderer.cpp
@@ -60,27 +60,67 @@
 }
 
 void BakedOpRenderer::endLayer() {
+    if (mRenderTarget.stencil) {
+        // if stencil was used for clipping, detach it and return it to pool
+        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
+        LOG_ALWAYS_FATAL_IF(GLUtils::dumpGLErrors(), "glfbrb endlayer failed");
+        mCaches.renderBufferCache.put(mRenderTarget.stencil);
+        mRenderTarget.stencil = nullptr;
+    }
+    mRenderTarget.lastStencilClip = nullptr;
+
     mRenderTarget.offscreenBuffer->updateMeshFromRegion();
-    mRenderTarget.offscreenBuffer = nullptr;
+    mRenderTarget.offscreenBuffer = nullptr; // It's in drawLayerOp's hands now.
 
     // Detach the texture from the FBO
     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
     LOG_ALWAYS_FATAL_IF(GLUtils::dumpGLErrors(), "endLayer FAILED");
     mRenderState.deleteFramebuffer(mRenderTarget.frameBufferId);
-    mRenderTarget.frameBufferId = -1;
+    mRenderTarget.frameBufferId = 0;
 }
 
 void BakedOpRenderer::startFrame(uint32_t width, uint32_t height, const Rect& repaintRect) {
+    LOG_ALWAYS_FATAL_IF(mRenderTarget.frameBufferId != 0, "primary framebufferId must be 0");
     mRenderState.bindFramebuffer(0);
     setViewport(width, height);
-    mCaches.clearGarbage();
 
     if (!mOpaque) {
         clearColorBuffer(repaintRect);
     }
+
+    mRenderState.debugOverdraw(true, true);
 }
 
-void BakedOpRenderer::endFrame() {
+void BakedOpRenderer::endFrame(const Rect& repaintRect) {
+    if (CC_UNLIKELY(Properties::debugOverdraw)) {
+        ClipRect overdrawClip(repaintRect);
+        Rect viewportRect(mRenderTarget.viewportWidth, mRenderTarget.viewportHeight);
+        // overdraw visualization
+        for (int i = 1; i <= 4; i++) {
+            if (i < 4) {
+                // nth level of overdraw tests for n+1 draws per pixel
+                mRenderState.stencil().enableDebugTest(i + 1, false);
+            } else {
+                // 4th level tests for 4 or higher draws per pixel
+                mRenderState.stencil().enableDebugTest(4, true);
+            }
+
+            SkPaint paint;
+            paint.setColor(mCaches.getOverdrawColor(i));
+            Glop glop;
+            GlopBuilder(mRenderState, mCaches, &glop)
+                    .setRoundRectClipState(nullptr)
+                    .setMeshUnitQuad()
+                    .setFillPaint(paint, 1.0f)
+                    .setTransform(Matrix4::identity(), TransformFlags::None)
+                    .setModelViewMapUnitToRect(viewportRect)
+                    .build();
+            renderGlop(nullptr, &overdrawClip, glop);
+        }
+        mRenderState.stencil().disable();
+    }
+
+    mCaches.clearGarbage();
     mCaches.pathCache.trim();
     mCaches.tessellationCache.trim();
 
@@ -128,12 +168,121 @@
     return texture;
 }
 
-void BakedOpRenderer::prepareRender(const Rect* dirtyBounds, const Rect* clip) {
+// clears and re-fills stencil with provided rendertarget space quads,
+// and then put stencil into test mode
+void BakedOpRenderer::setupStencilQuads(std::vector<Vertex>& quadVertices,
+        int incrementThreshold) {
+    mRenderState.stencil().enableWrite(incrementThreshold);
+    mRenderState.stencil().clear();
+    Glop glop;
+    GlopBuilder(mRenderState, mCaches, &glop)
+            .setRoundRectClipState(nullptr)
+            .setMeshIndexedQuads(quadVertices.data(), quadVertices.size() / 4)
+            .setFillBlack()
+            .setTransform(Matrix4::identity(), TransformFlags::None)
+            .setModelViewIdentityEmptyBounds()
+            .build();
+    mRenderState.render(glop, mRenderTarget.orthoMatrix);
+    mRenderState.stencil().enableTest(incrementThreshold);
+}
+
+void BakedOpRenderer::setupStencilRectList(const ClipBase* clip) {
+    auto&& rectList = reinterpret_cast<const ClipRectList*>(clip)->rectList;
+    int quadCount = rectList.getTransformedRectanglesCount();
+    std::vector<Vertex> rectangleVertices;
+    rectangleVertices.reserve(quadCount * 4);
+    for (int i = 0; i < quadCount; i++) {
+        const TransformedRectangle& tr(rectList.getTransformedRectangle(i));
+        const Matrix4& transform = tr.getTransform();
+        Rect bounds = tr.getBounds();
+        if (transform.rectToRect()) {
+            // If rectToRect, can simply map bounds before storing verts
+            transform.mapRect(bounds);
+            bounds.doIntersect(clip->rect);
+            if (bounds.isEmpty()) {
+                continue; // will be outside of scissor, skip
+            }
+        }
+
+        rectangleVertices.push_back(Vertex{bounds.left, bounds.top});
+        rectangleVertices.push_back(Vertex{bounds.right, bounds.top});
+        rectangleVertices.push_back(Vertex{bounds.left, bounds.bottom});
+        rectangleVertices.push_back(Vertex{bounds.right, bounds.bottom});
+
+        if (!transform.rectToRect()) {
+            // If not rectToRect, must map each point individually
+            for (auto cur = rectangleVertices.end() - 4; cur < rectangleVertices.end(); cur++) {
+                transform.mapPoint(cur->x, cur->y);
+            }
+        }
+    }
+    setupStencilQuads(rectangleVertices, rectList.getTransformedRectanglesCount());
+}
+
+void BakedOpRenderer::setupStencilRegion(const ClipBase* clip) {
+    auto&& region = reinterpret_cast<const ClipRegion*>(clip)->region;
+
+    std::vector<Vertex> regionVertices;
+    SkRegion::Cliperator it(region, clip->rect.toSkIRect());
+    while (!it.done()) {
+        const SkIRect& r = it.rect();
+        regionVertices.push_back(Vertex{(float)r.fLeft, (float)r.fTop});
+        regionVertices.push_back(Vertex{(float)r.fRight, (float)r.fTop});
+        regionVertices.push_back(Vertex{(float)r.fLeft, (float)r.fBottom});
+        regionVertices.push_back(Vertex{(float)r.fRight, (float)r.fBottom});
+        it.next();
+    }
+    setupStencilQuads(regionVertices, 0);
+}
+
+void BakedOpRenderer::prepareRender(const Rect* dirtyBounds, const ClipBase* clip) {
+    // prepare scissor / stencil
     mRenderState.scissor().setEnabled(clip != nullptr);
     if (clip) {
-        mRenderState.scissor().set(clip->left, mRenderTarget.viewportHeight - clip->bottom,
-            clip->getWidth(), clip->getHeight());
+        mRenderState.scissor().set(mRenderTarget.viewportHeight, clip->rect);
     }
+
+    if (CC_LIKELY(!Properties::debugOverdraw)) {
+        // only modify stencil mode and content when it's not used for overdraw visualization
+        if (CC_UNLIKELY(clip && clip->mode != ClipMode::Rectangle)) {
+            // NOTE: this pointer check is only safe for non-rect clips,
+            // since rect clips may be created on the stack
+            if (mRenderTarget.lastStencilClip != clip) {
+                // Stencil needed, but current stencil isn't up to date
+                mRenderTarget.lastStencilClip = clip;
+
+                if (mRenderTarget.frameBufferId != 0 && !mRenderTarget.stencil) {
+                    OffscreenBuffer* layer = mRenderTarget.offscreenBuffer;
+                    mRenderTarget.stencil = mCaches.renderBufferCache.get(
+                            Stencil::getLayerStencilFormat(),
+                            layer->texture.width, layer->texture.height);
+                    // stencil is bound + allocated - associate it with current FBO
+                    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
+                            GL_RENDERBUFFER, mRenderTarget.stencil->getName());
+                }
+
+                if (clip->mode == ClipMode::RectangleList) {
+                    setupStencilRectList(clip);
+                } else {
+                    setupStencilRegion(clip);
+                }
+            } else {
+                // stencil is up to date - just need to ensure it's enabled (since an unclipped
+                // or scissor-only clipped op may have been drawn, disabling the stencil)
+                int incrementThreshold = 0;
+                if (CC_LIKELY(clip->mode == ClipMode::RectangleList)) {
+                    auto&& rectList = reinterpret_cast<const ClipRectList*>(clip)->rectList;
+                    incrementThreshold = rectList.getTransformedRectanglesCount();
+                }
+                mRenderState.stencil().enableTest(incrementThreshold);
+            }
+        } else {
+            // either scissor or no clip, so disable stencil test
+            mRenderState.stencil().disable();
+        }
+    }
+
+    // dirty offscreenbuffer
     if (dirtyBounds && mRenderTarget.offscreenBuffer) {
         // register layer damage to draw-back region
         android::Rect dirty(dirtyBounds->left, dirtyBounds->top,
@@ -142,17 +291,18 @@
     }
 }
 
-void BakedOpRenderer::renderGlop(const Rect* dirtyBounds, const Rect* clip, const Glop& glop) {
+void BakedOpRenderer::renderGlop(const Rect* dirtyBounds, const ClipBase* clip,
+        const Glop& glop) {
     prepareRender(dirtyBounds, clip);
     mRenderState.render(glop, mRenderTarget.orthoMatrix);
     if (!mRenderTarget.frameBufferId) mHasDrawn = true;
 }
 
 void BakedOpRenderer::renderFunctor(const FunctorOp& op, const BakedOpState& state) {
-    prepareRender(&state.computedState.clippedBounds, &state.computedState.clipRect);
+    prepareRender(&state.computedState.clippedBounds, state.computedState.getClipIfNeeded());
 
     DrawGlInfo info;
-    auto&& clip = state.computedState.clipRect;
+    auto&& clip = state.computedState.clipRect();
     info.clipLeft = clip.left;
     info.clipTop = clip.top;
     info.clipRight = clip.right;
diff --git a/libs/hwui/BakedOpRenderer.h b/libs/hwui/BakedOpRenderer.h
index f158e8b..65e8b29 100644
--- a/libs/hwui/BakedOpRenderer.h
+++ b/libs/hwui/BakedOpRenderer.h
@@ -27,6 +27,7 @@
 struct Glop;
 class Layer;
 class RenderState;
+struct ClipBase;
 
 /**
  * Main rendering manager for a collection of work - one frame + any contained FBOs.
@@ -59,7 +60,7 @@
     Caches& caches() { return mCaches; }
 
     void startFrame(uint32_t width, uint32_t height, const Rect& repaintRect);
-    void endFrame();
+    void endFrame(const Rect& repaintRect);
     OffscreenBuffer* startTemporaryLayer(uint32_t width, uint32_t height);
     void startRepaintLayer(OffscreenBuffer* offscreenBuffer, const Rect& repaintRect);
     void endLayer();
@@ -68,21 +69,23 @@
     const LightInfo& getLightInfo() const { return mLightInfo; }
 
     void renderGlop(const BakedOpState& state, const Glop& glop) {
-        bool useScissor = state.computedState.clipSideFlags != OpClipSideFlags::None;
         renderGlop(&state.computedState.clippedBounds,
-                useScissor ? &state.computedState.clipRect : nullptr,
+                state.computedState.getClipIfNeeded(),
                 glop);
     }
     void renderFunctor(const FunctorOp& op, const BakedOpState& state);
 
-    void renderGlop(const Rect* dirtyBounds, const Rect* clip, const Glop& glop);
+    void renderGlop(const Rect* dirtyBounds, const ClipBase* clip, const Glop& glop);
     bool offscreenRenderTarget() { return mRenderTarget.offscreenBuffer != nullptr; }
     void dirtyRenderTarget(const Rect& dirtyRect);
     bool didDraw() const { return mHasDrawn; }
 private:
     void setViewport(uint32_t width, uint32_t height);
     void clearColorBuffer(const Rect& clearRect);
-    void prepareRender(const Rect* dirtyBounds, const Rect* clip);
+    void prepareRender(const Rect* dirtyBounds, const ClipBase* clip);
+    void setupStencilRectList(const ClipBase* clip);
+    void setupStencilRegion(const ClipBase* clip);
+    void setupStencilQuads(std::vector<Vertex>& quadVertices, int incrementThreshold);
 
     RenderState& mRenderState;
     Caches& mCaches;
@@ -92,10 +95,23 @@
     // render target state - setup by start/end layer/frame
     // only valid to use in between start/end pairs.
     struct {
+        // If not drawing to a layer: fbo = 0, offscreenBuffer = null,
+        // Otherwise these refer to currently painting layer's state
         GLuint frameBufferId = 0;
         OffscreenBuffer* offscreenBuffer = nullptr;
+
+        // Used when drawing to a layer and using stencil clipping. otherwise null.
+        RenderBuffer* stencil = nullptr;
+
+        // value representing the ClipRectList* or ClipRegion* currently stored in
+        // the stencil of the current render target
+        const ClipBase* lastStencilClip = nullptr;
+
+        // Size of renderable region in current render target - for layers, may not match actual
+        // bounds of FBO texture. offscreenBuffer->texture has this information.
         uint32_t viewportWidth = 0;
         uint32_t viewportHeight = 0;
+
         Matrix4 orthoMatrix;
     } mRenderTarget;
 
diff --git a/libs/hwui/BakedOpState.cpp b/libs/hwui/BakedOpState.cpp
new file mode 100644
index 0000000..e6b943a
--- /dev/null
+++ b/libs/hwui/BakedOpState.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "BakedOpState.h"
+
+#include "ClipArea.h"
+
+namespace android {
+namespace uirenderer {
+
+ResolvedRenderState::ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot,
+        const RecordedOp& recordedOp, bool expandForStroke) {
+    // resolvedMatrix = parentMatrix * localMatrix
+    transform.loadMultiply(*snapshot.transform, recordedOp.localMatrix);
+
+    // resolvedClippedBounds = intersect(resolvedMatrix * opBounds, resolvedClipRect)
+    clippedBounds = recordedOp.unmappedBounds;
+    if (CC_UNLIKELY(expandForStroke)) {
+        // account for non-hairline stroke
+        clippedBounds.outset(recordedOp.paint->getStrokeWidth() * 0.5f);
+    }
+    transform.mapRect(clippedBounds);
+    if (CC_UNLIKELY(expandForStroke
+            && (!transform.isPureTranslate() || recordedOp.paint->getStrokeWidth() < 1.0f))) {
+        // account for hairline stroke when stroke may be < 1 scaled pixel
+        // Non translate || strokeWidth < 1 is conservative, but will cover all cases
+        clippedBounds.outset(0.5f);
+    }
+
+    // resolvedClipRect = intersect(parentMatrix * localClip, parentClip)
+    clipState = snapshot.mutateClipArea().serializeIntersectedClip(allocator,
+            recordedOp.localClip, *(snapshot.transform));
+    LOG_ALWAYS_FATAL_IF(!clipState, "must clip!");
+
+    const Rect& clipRect = clipState->rect;
+    if (CC_UNLIKELY(clipRect.isEmpty() || !clippedBounds.intersects(clipRect))) {
+        // Rejected based on either empty clip, or bounds not intersecting with clip
+        if (clipState) {
+            allocator.rewindIfLastAlloc(clipState);
+            clipState = nullptr;
+        }
+        clippedBounds.setEmpty();
+    } else {
+        // Not rejected! compute true clippedBounds and clipSideFlags
+        if (clipRect.left > clippedBounds.left) clipSideFlags |= OpClipSideFlags::Left;
+        if (clipRect.top > clippedBounds.top) clipSideFlags |= OpClipSideFlags::Top;
+        if (clipRect.right < clippedBounds.right) clipSideFlags |= OpClipSideFlags::Right;
+        if (clipRect.bottom < clippedBounds.bottom) clipSideFlags |= OpClipSideFlags::Bottom;
+        clippedBounds.doIntersect(clipRect);
+    }
+}
+
+ResolvedRenderState::ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot) {
+    transform = *snapshot.transform;
+
+    // Since the op doesn't have known bounds, we conservatively set the mapped bounds
+    // to the current clipRect, and clipSideFlags to Full.
+    clipState = snapshot.mutateClipArea().serializeClip(allocator);
+    LOG_ALWAYS_FATAL_IF(!clipState, "clipState required");
+    clippedBounds = clipState->rect;
+    transform.mapRect(clippedBounds);
+    clipSideFlags = OpClipSideFlags::Full;
+}
+
+} // namespace uirenderer
+} // namespace android
diff --git a/libs/hwui/BakedOpState.h b/libs/hwui/BakedOpState.h
index b12c0c9..9df4e3a 100644
--- a/libs/hwui/BakedOpState.h
+++ b/libs/hwui/BakedOpState.h
@@ -52,89 +52,35 @@
  */
 class ResolvedRenderState {
 public:
-    // TODO: remove the mapRects/matrix multiply when snapshot & recorded transforms are translates
-    ResolvedRenderState(const Snapshot& snapshot, const RecordedOp& recordedOp, bool expandForStroke) {
-        /* TODO: benchmark a fast path for translate-only matrices, such as:
-        if (CC_LIKELY(snapshot.transform->getType() == Matrix4::kTypeTranslate
-                && recordedOp.localMatrix.getType() == Matrix4::kTypeTranslate)) {
-            float translateX = snapshot.transform->getTranslateX() + recordedOp.localMatrix.getTranslateX();
-            float translateY = snapshot.transform->getTranslateY() + recordedOp.localMatrix.getTranslateY();
-            transform.loadTranslate(translateX, translateY, 0);
+    ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot,
+            const RecordedOp& recordedOp, bool expandForStroke);
 
-            // resolvedClipRect = intersect(parentMatrix * localClip, parentClip)
-            clipRect = recordedOp.localClipRect;
-            clipRect.translate(translateX, translateY);
-            clipRect.doIntersect(snapshot.getClipRect());
-            clipRect.snapToPixelBoundaries();
-
-            // resolvedClippedBounds = intersect(resolvedMatrix * opBounds, resolvedClipRect)
-            clippedBounds = recordedOp.unmappedBounds;
-            clippedBounds.translate(translateX, translateY);
-        } ... */
-
-        // resolvedMatrix = parentMatrix * localMatrix
-        transform.loadMultiply(*snapshot.transform, recordedOp.localMatrix);
-
-        // resolvedClipRect = intersect(parentMatrix * localClip, parentClip)
-        clipRect = recordedOp.localClipRect;
-        snapshot.transform->mapRect(clipRect);
-        clipRect.doIntersect(snapshot.getRenderTargetClip());
-        clipRect.snapToPixelBoundaries();
-
-        // resolvedClippedBounds = intersect(resolvedMatrix * opBounds, resolvedClipRect)
-        clippedBounds = recordedOp.unmappedBounds;
-        if (CC_UNLIKELY(expandForStroke)) {
-            // account for non-hairline stroke
-            clippedBounds.outset(recordedOp.paint->getStrokeWidth() * 0.5f);
-        }
-        transform.mapRect(clippedBounds);
-        if (CC_UNLIKELY(expandForStroke
-                && (!transform.isPureTranslate() || recordedOp.paint->getStrokeWidth() < 1.0f))) {
-            // account for hairline stroke when stroke may be < 1 scaled pixel
-            // Non translate || strokeWidth < 1 is conservative, but will cover all cases
-            clippedBounds.outset(0.5f);
-        }
-
-        if (clipRect.left > clippedBounds.left) clipSideFlags |= OpClipSideFlags::Left;
-        if (clipRect.top > clippedBounds.top) clipSideFlags |= OpClipSideFlags::Top;
-        if (clipRect.right < clippedBounds.right) clipSideFlags |= OpClipSideFlags::Right;
-        if (clipRect.bottom < clippedBounds.bottom) clipSideFlags |= OpClipSideFlags::Bottom;
-        clippedBounds.doIntersect(clipRect);
-
-        /**
-         * TODO: once we support complex clips, we may want to reject to avoid that work where
-         * possible. Should we:
-         * 1 - quickreject based on clippedBounds, quick early (duplicating logic in resolvedOp)
-         * 2 - merge stuff into tryConstruct factory method, so it can handle quickRejection
-         *         and early return null in one place.
-         */
-    }
-
-    /**
-     * Constructor for unbounded ops without transform/clip (namely shadows)
-     *
-     * Since the op doesn't have known bounds, we conservatively set the mapped bounds
-     * to the current clipRect, and clipSideFlags to Full.
-     */
-    ResolvedRenderState(const Snapshot& snapshot) {
-        transform = *snapshot.transform;
-        clipRect = snapshot.getRenderTargetClip();
-        clippedBounds = clipRect;
-        transform.mapRect(clippedBounds);
-        clipSideFlags = OpClipSideFlags::Full;
-    }
+    // Constructor for unbounded ops without transform/clip (namely shadows)
+    ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot);
 
     Rect computeLocalSpaceClip() const {
         Matrix4 inverse;
         inverse.loadInverse(transform);
 
-        Rect outClip(clipRect);
+        Rect outClip(clipRect());
         inverse.mapRect(outClip);
         return outClip;
     }
 
     Matrix4 transform;
-    Rect clipRect;
+    const Rect& clipRect() const {
+        return clipState->rect;
+    }
+    bool requiresClip() const {
+        return clipSideFlags != OpClipSideFlags::None
+                || CC_UNLIKELY(clipState->mode != ClipMode::Rectangle);
+    }
+
+    // returns the clip if it's needed to draw the operation, otherwise nullptr
+    const ClipBase* getClipIfNeeded() const {
+        return requiresClip() ? clipState : nullptr;
+    }
+    const ClipBase* clipState = nullptr;
     int clipSideFlags = 0;
     Rect clippedBounds;
 };
@@ -147,8 +93,9 @@
 class BakedOpState {
 public:
     static BakedOpState* tryConstruct(LinearAllocator& allocator,
-            const Snapshot& snapshot, const RecordedOp& recordedOp) {
-        BakedOpState* bakedState = new (allocator) BakedOpState(snapshot, recordedOp, false);
+            Snapshot& snapshot, const RecordedOp& recordedOp) {
+        BakedOpState* bakedState = new (allocator) BakedOpState(
+                allocator, snapshot, recordedOp, false);
         if (bakedState->computedState.clippedBounds.isEmpty()) {
             // bounds are empty, so op is rejected
             allocator.rewindIfLastAlloc(bakedState);
@@ -165,13 +112,13 @@
     };
 
     static BakedOpState* tryStrokeableOpConstruct(LinearAllocator& allocator,
-            const Snapshot& snapshot, const RecordedOp& recordedOp, StrokeBehavior strokeBehavior) {
+            Snapshot& snapshot, const RecordedOp& recordedOp, StrokeBehavior strokeBehavior) {
         bool expandForStroke = (strokeBehavior == StrokeBehavior::StyleDefined)
                 ? (recordedOp.paint && recordedOp.paint->getStyle() != SkPaint::kFill_Style)
                 : true;
 
         BakedOpState* bakedState = new (allocator) BakedOpState(
-                snapshot, recordedOp, expandForStroke);
+                allocator, snapshot, recordedOp, expandForStroke);
         if (bakedState->computedState.clippedBounds.isEmpty()) {
             // bounds are empty, so op is rejected
             allocator.rewindIfLastAlloc(bakedState);
@@ -181,11 +128,11 @@
     }
 
     static BakedOpState* tryShadowOpConstruct(LinearAllocator& allocator,
-            const Snapshot& snapshot, const ShadowOp* shadowOpPtr) {
+            Snapshot& snapshot, const ShadowOp* shadowOpPtr) {
         if (snapshot.getRenderTargetClip().isEmpty()) return nullptr;
 
         // clip isn't empty, so construct the op
-        return new (allocator) BakedOpState(snapshot, shadowOpPtr);
+        return new (allocator) BakedOpState(allocator, snapshot, shadowOpPtr);
     }
 
     static void* operator new(size_t size, LinearAllocator& allocator) {
@@ -202,15 +149,16 @@
     const RecordedOp* op;
 
 private:
-    BakedOpState(const Snapshot& snapshot, const RecordedOp& recordedOp, bool expandForStroke)
-            : computedState(snapshot, recordedOp, expandForStroke)
+    BakedOpState(LinearAllocator& allocator, Snapshot& snapshot,
+            const RecordedOp& recordedOp, bool expandForStroke)
+            : computedState(allocator, snapshot, recordedOp, expandForStroke)
             , alpha(snapshot.alpha)
             , roundRectClipState(snapshot.roundRectClipState)
             , projectionPathMask(snapshot.projectionPathMask)
             , op(&recordedOp) {}
 
-    BakedOpState(const Snapshot& snapshot, const ShadowOp* shadowOpPtr)
-            : computedState(snapshot)
+    BakedOpState(LinearAllocator& allocator, Snapshot& snapshot, const ShadowOp* shadowOpPtr)
+            : computedState(allocator, snapshot)
             , alpha(snapshot.alpha)
             , roundRectClipState(snapshot.roundRectClipState)
             , projectionPathMask(snapshot.projectionPathMask)
diff --git a/libs/hwui/CanvasState.cpp b/libs/hwui/CanvasState.cpp
index cf76e6b..cf2726b 100644
--- a/libs/hwui/CanvasState.cpp
+++ b/libs/hwui/CanvasState.cpp
@@ -45,6 +45,21 @@
     }
 }
 
+void CanvasState::initializeRecordingSaveStack(int viewportWidth, int viewportHeight) {
+    if (mWidth != viewportWidth || mHeight != viewportHeight) {
+        mWidth = viewportWidth;
+        mHeight = viewportHeight;
+        mFirstSnapshot.initializeViewport(viewportWidth, viewportHeight);
+        mCanvas.onViewportInitialized();
+    }
+
+    freeAllSnapshots();
+    mSnapshot = allocSnapshot(&mFirstSnapshot,
+            SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
+    mSnapshot->setRelativeLightCenter(Vector3());
+    mSaveCount = 1;
+}
+
 void CanvasState::initializeSaveStack(
         int viewportWidth, int viewportHeight,
         float clipLeft, float clipTop,
diff --git a/libs/hwui/CanvasState.h b/libs/hwui/CanvasState.h
index 4709ef4..b9e87ae 100644
--- a/libs/hwui/CanvasState.h
+++ b/libs/hwui/CanvasState.h
@@ -80,6 +80,12 @@
      * Initializes the first snapshot, computing the projection matrix,
      * and stores the dimensions of the render target.
      */
+    void initializeRecordingSaveStack(int viewportWidth, int viewportHeight);
+
+    /**
+     * Initializes the first snapshot, computing the projection matrix,
+     * and stores the dimensions of the render target.
+     */
     void initializeSaveStack(int viewportWidth, int viewportHeight,
             float clipLeft, float clipTop, float clipRight, float clipBottom,
             const Vector3& lightCenter);
@@ -168,6 +174,7 @@
     void freeAllSnapshots();
 
     /// indicates that the clip has been changed since the last time it was consumed
+    // TODO: delete when switching to HWUI_NEW_OPS
     bool mDirtyClip;
 
     /// Dimensions of the drawing surface
diff --git a/libs/hwui/ClipArea.cpp b/libs/hwui/ClipArea.cpp
index 5f166ca..160090d 100644
--- a/libs/hwui/ClipArea.cpp
+++ b/libs/hwui/ClipArea.cpp
@@ -15,10 +15,11 @@
  */
 #include "ClipArea.h"
 
+#include "utils/LinearAllocator.h"
+
 #include <SkPath.h>
 #include <limits>
-
-#include "Rect.h"
+#include <type_traits>
 
 namespace android {
 namespace uirenderer {
@@ -171,12 +172,18 @@
     return rectangleListAsRegion;
 }
 
+void RectangleList::transform(const Matrix4& transform) {
+    for (int index = 0; index < mTransformedRectanglesCount; index++) {
+        mTransformedRectangles[index].transform(transform);
+    }
+}
+
 /*
  * ClipArea
  */
 
 ClipArea::ClipArea()
-        : mMode(Mode::Rectangle) {
+        : mMode(ClipMode::Rectangle) {
 }
 
 /*
@@ -184,39 +191,44 @@
  */
 
 void ClipArea::setViewportDimensions(int width, int height) {
+    mPostViewportClipObserved = false;
     mViewportBounds.set(0, 0, width, height);
     mClipRect = mViewportBounds;
 }
 
 void ClipArea::setEmpty() {
-    mMode = Mode::Rectangle;
+    onClipUpdated();
+    mMode = ClipMode::Rectangle;
     mClipRect.setEmpty();
     mClipRegion.setEmpty();
     mRectangleList.setEmpty();
 }
 
 void ClipArea::setClip(float left, float top, float right, float bottom) {
-    mMode = Mode::Rectangle;
+    onClipUpdated();
+    mMode = ClipMode::Rectangle;
     mClipRect.set(left, top, right, bottom);
     mClipRegion.setEmpty();
 }
 
 void ClipArea::clipRectWithTransform(const Rect& r, const mat4* transform,
         SkRegion::Op op) {
+    onClipUpdated();
     switch (mMode) {
-    case Mode::Rectangle:
+    case ClipMode::Rectangle:
         rectangleModeClipRectWithTransform(r, transform, op);
         break;
-    case Mode::RectangleList:
+    case ClipMode::RectangleList:
         rectangleListModeClipRectWithTransform(r, transform, op);
         break;
-    case Mode::Region:
+    case ClipMode::Region:
         regionModeClipRectWithTransform(r, transform, op);
         break;
     }
 }
 
 void ClipArea::clipRegion(const SkRegion& region, SkRegion::Op op) {
+    onClipUpdated();
     enterRegionMode();
     mClipRegion.op(region, op);
     onClipRegionUpdated();
@@ -224,6 +236,7 @@
 
 void ClipArea::clipPathWithTransform(const SkPath& path, const mat4* transform,
         SkRegion::Op op) {
+    onClipUpdated();
     SkMatrix skTransform;
     transform->copyTo(skTransform);
     SkPath transformed;
@@ -241,7 +254,7 @@
     // Entering rectangle mode discards any
     // existing clipping information from the other modes.
     // The only way this occurs is by a clip setting operation.
-    mMode = Mode::Rectangle;
+    mMode = ClipMode::Rectangle;
 }
 
 void ClipArea::rectangleModeClipRectWithTransform(const Rect& r,
@@ -276,8 +289,8 @@
     // Is is only legal to enter rectangle list mode from
     // rectangle mode, since rectangle list mode cannot represent
     // all clip areas that can be represented by a region.
-    ALOG_ASSERT(mMode == Mode::Rectangle);
-    mMode = Mode::RectangleList;
+    ALOG_ASSERT(mMode == ClipMode::Rectangle);
+    mMode = ClipMode::RectangleList;
     mRectangleList.set(mClipRect, Matrix4::identity());
 }
 
@@ -295,12 +308,11 @@
  */
 
 void ClipArea::enterRegionMode() {
-    Mode oldMode = mMode;
-    mMode = Mode::Region;
-    if (oldMode != Mode::Region) {
-        if (oldMode == Mode::Rectangle) {
-            mClipRegion.setRect(mClipRect.left, mClipRect.top,
-                    mClipRect.right, mClipRect.bottom);
+    ClipMode oldMode = mMode;
+    mMode = ClipMode::Region;
+    if (oldMode != ClipMode::Region) {
+        if (oldMode == ClipMode::Rectangle) {
+            mClipRegion.setRect(mClipRect.toSkIRect());
         } else {
             mClipRegion = mRectangleList.convertToRegion(createViewportRegion());
             onClipRegionUpdated();
@@ -330,5 +342,172 @@
     }
 }
 
+/**
+ * Clip serialization
+ */
+
+const ClipBase* ClipArea::serializeClip(LinearAllocator& allocator) {
+    if (!mPostViewportClipObserved) {
+        // Only initial clip-to-viewport observed, so no serialization of clip necessary
+        return nullptr;
+    }
+
+    static_assert(std::is_trivially_destructible<Rect>::value,
+            "expect Rect to be trivially destructible");
+    static_assert(std::is_trivially_destructible<RectangleList>::value,
+            "expect RectangleList to be trivially destructible");
+
+    if (mLastSerialization == nullptr) {
+        switch (mMode) {
+        case ClipMode::Rectangle:
+            mLastSerialization = allocator.create<ClipRect>(mClipRect);
+            break;
+        case ClipMode::RectangleList:
+            mLastSerialization = allocator.create<ClipRectList>(mRectangleList);
+            break;
+        case ClipMode::Region:
+            mLastSerialization = allocator.create<ClipRegion>(mClipRegion);
+            break;
+        }
+    }
+    return mLastSerialization;
+}
+
+inline static const Rect& getRect(const ClipBase* scb) {
+    return reinterpret_cast<const ClipRect*>(scb)->rect;
+}
+
+inline static const RectangleList& getRectList(const ClipBase* scb) {
+    return reinterpret_cast<const ClipRectList*>(scb)->rectList;
+}
+
+inline static const SkRegion& getRegion(const ClipBase* scb) {
+    return reinterpret_cast<const ClipRegion*>(scb)->region;
+}
+
+// Conservative check for too many rectangles to fit in rectangle list.
+// For simplicity, doesn't account for rect merging
+static bool cannotFitInRectangleList(const ClipArea& clipArea, const ClipBase* scb) {
+    int currentRectCount = clipArea.isRectangleList()
+            ? clipArea.getRectangleList().getTransformedRectanglesCount()
+            : 1;
+    int recordedRectCount = (scb->mode == ClipMode::RectangleList)
+            ? getRectList(scb).getTransformedRectanglesCount()
+            : 1;
+    return currentRectCount + recordedRectCount > RectangleList::kMaxTransformedRectangles;
+}
+
+const ClipBase* ClipArea::serializeIntersectedClip(LinearAllocator& allocator,
+        const ClipBase* recordedClip, const Matrix4& recordedClipTransform) {
+    // if no recordedClip passed, just serialize current state
+    if (!recordedClip) return serializeClip(allocator);
+
+    if (!mLastResolutionResult
+            || recordedClip != mLastResolutionClip
+            || recordedClipTransform != mLastResolutionTransform) {
+        mLastResolutionClip = recordedClip;
+        mLastResolutionTransform = recordedClipTransform;
+
+        if (CC_LIKELY(mMode == ClipMode::Rectangle
+                && recordedClip->mode == ClipMode::Rectangle
+                && recordedClipTransform.rectToRect())) {
+            // common case - result is a single rectangle
+            auto rectClip = allocator.create<ClipRect>(getRect(recordedClip));
+            recordedClipTransform.mapRect(rectClip->rect);
+            rectClip->rect.doIntersect(mClipRect);
+            mLastResolutionResult = rectClip;
+        } else if (CC_UNLIKELY(mMode == ClipMode::Region
+                || recordedClip->mode == ClipMode::Region
+                || cannotFitInRectangleList(*this, recordedClip))) {
+            // region case
+            SkRegion other;
+            switch (recordedClip->mode) {
+            case ClipMode::Rectangle:
+                if (CC_LIKELY(recordedClipTransform.rectToRect())) {
+                    // simple transform, skip creating SkPath
+                    Rect resultClip(getRect(recordedClip));
+                    recordedClipTransform.mapRect(resultClip);
+                    other.setRect(resultClip.toSkIRect());
+                } else {
+                    SkPath transformedRect = pathFromTransformedRectangle(getRect(recordedClip),
+                            recordedClipTransform);
+                    other.setPath(transformedRect, createViewportRegion());
+                }
+                break;
+            case ClipMode::RectangleList: {
+                RectangleList transformedList(getRectList(recordedClip));
+                transformedList.transform(recordedClipTransform);
+                other = transformedList.convertToRegion(createViewportRegion());
+                break;
+            }
+            case ClipMode::Region:
+                other = getRegion(recordedClip);
+
+                // TODO: handle non-translate transforms properly!
+                other.translate(recordedClipTransform.getTranslateX(),
+                        recordedClipTransform.getTranslateY());
+            }
+
+            ClipRegion* regionClip = allocator.create<ClipRegion>();
+            switch (mMode) {
+            case ClipMode::Rectangle:
+                regionClip->region.op(mClipRect.toSkIRect(), other, SkRegion::kIntersect_Op);
+                break;
+            case ClipMode::RectangleList:
+                regionClip->region.op(mRectangleList.convertToRegion(createViewportRegion()),
+                        other, SkRegion::kIntersect_Op);
+                break;
+            case ClipMode::Region:
+                regionClip->region.op(mClipRegion, other, SkRegion::kIntersect_Op);
+                break;
+            }
+            regionClip->rect.set(regionClip->region.getBounds());
+            mLastResolutionResult = regionClip;
+        } else {
+            auto rectListClip = allocator.create<ClipRectList>(mRectangleList);
+            auto&& rectList = rectListClip->rectList;
+            if (mMode == ClipMode::Rectangle) {
+                rectList.set(mClipRect, Matrix4::identity());
+            }
+
+            if (recordedClip->mode == ClipMode::Rectangle) {
+                rectList.intersectWith(getRect(recordedClip), recordedClipTransform);
+            } else {
+                const RectangleList& other = getRectList(recordedClip);
+                for (int i = 0; i < other.getTransformedRectanglesCount(); i++) {
+                    auto&& tr = other.getTransformedRectangle(i);
+                    Matrix4 totalTransform(recordedClipTransform);
+                    totalTransform.multiply(tr.getTransform());
+                    rectList.intersectWith(tr.getBounds(), totalTransform);
+                }
+            }
+            rectListClip->rect = rectList.calculateBounds();
+            mLastResolutionResult = rectListClip;
+        }
+    }
+    return mLastResolutionResult;
+}
+
+void ClipArea::applyClip(const ClipBase* clip, const Matrix4& transform) {
+    if (!clip) return; // nothing to do
+
+    if (CC_LIKELY(clip->mode == ClipMode::Rectangle)) {
+        clipRectWithTransform(getRect(clip), &transform, SkRegion::kIntersect_Op);
+    } else if (CC_LIKELY(clip->mode == ClipMode::RectangleList)) {
+        auto&& rectList = getRectList(clip);
+        for (int i = 0; i < rectList.getTransformedRectanglesCount(); i++) {
+            auto&& tr = rectList.getTransformedRectangle(i);
+            Matrix4 totalTransform(transform);
+            totalTransform.multiply(tr.getTransform());
+            clipRectWithTransform(tr.getBounds(), &totalTransform, SkRegion::kIntersect_Op);
+        }
+    } else {
+        SkRegion region(getRegion(clip));
+        // TODO: handle non-translate transforms properly!
+        region.translate(transform.getTranslateX(), transform.getTranslateY());
+        clipRegion(region, SkRegion::kIntersect_Op);
+    }
+}
+
 } /* namespace uirenderer */
 } /* namespace android */
diff --git a/libs/hwui/ClipArea.h b/libs/hwui/ClipArea.h
index 268301c..479796d 100644
--- a/libs/hwui/ClipArea.h
+++ b/libs/hwui/ClipArea.h
@@ -16,15 +16,17 @@
 #ifndef CLIPAREA_H
 #define CLIPAREA_H
 
-#include <SkRegion.h>
-
 #include "Matrix.h"
 #include "Rect.h"
 #include "utils/Pair.h"
 
+#include <SkRegion.h>
+
 namespace android {
 namespace uirenderer {
 
+class LinearAllocator;
+
 Rect transformAndCalculateBounds(const Rect& r, const Matrix4& transform);
 
 class TransformedRectangle {
@@ -50,6 +52,12 @@
         return mTransform;
     }
 
+    void transform(const Matrix4& transform) {
+        Matrix4 t;
+        t.loadMultiply(transform, mTransform);
+        mTransform = t;
+    }
+
 private:
     Rect mBounds;
     Matrix4 mTransform;
@@ -66,27 +74,62 @@
     void setEmpty();
     void set(const Rect& bounds, const Matrix4& transform);
     bool intersectWith(const Rect& bounds, const Matrix4& transform);
+    void transform(const Matrix4& transform);
 
     SkRegion convertToRegion(const SkRegion& clip) const;
     Rect calculateBounds() const;
 
-private:
     enum {
         kMaxTransformedRectangles = 5
     };
 
+private:
     int mTransformedRectanglesCount;
     TransformedRectangle mTransformedRectangles[kMaxTransformedRectangles];
 };
 
-class ClipArea {
-private:
-    enum class Mode {
-        Rectangle,
-        Region,
-        RectangleList
-    };
+enum class ClipMode {
+    Rectangle,
+    RectangleList,
 
+    // region and path - intersected. if either is empty, don't use
+    Region
+};
+
+struct ClipBase {
+    ClipBase(ClipMode mode)
+            : mode(mode) {}
+    ClipBase(const Rect& rect)
+            : mode(ClipMode::Rectangle)
+            , rect(rect) {}
+    const ClipMode mode;
+    // Bounds of the clipping area, used to define the scissor, and define which
+    // portion of the stencil is updated/used
+    Rect rect;
+};
+
+struct ClipRect : ClipBase {
+    ClipRect(const Rect& rect)
+            : ClipBase(rect) {}
+};
+
+struct ClipRectList : ClipBase {
+    ClipRectList(const RectangleList& rectList)
+            : ClipBase(ClipMode::RectangleList)
+            , rectList(rectList) {}
+    RectangleList rectList;
+};
+
+struct ClipRegion : ClipBase {
+    ClipRegion(const SkRegion& region)
+            : ClipBase(ClipMode::Region)
+            , region(region) {}
+    ClipRegion()
+            : ClipBase(ClipMode::Region) {}
+    SkRegion region;
+};
+
+class ClipArea {
 public:
     ClipArea();
 
@@ -117,17 +160,22 @@
     }
 
     bool isRegion() const {
-        return Mode::Region == mMode;
+        return ClipMode::Region == mMode;
     }
 
     bool isSimple() const {
-        return mMode == Mode::Rectangle;
+        return mMode == ClipMode::Rectangle;
     }
 
     bool isRectangleList() const {
-        return mMode == Mode::RectangleList;
+        return mMode == ClipMode::RectangleList;
     }
 
+    const ClipBase* serializeClip(LinearAllocator& allocator);
+    const ClipBase* serializeIntersectedClip(LinearAllocator& allocator,
+            const ClipBase* recordedClip, const Matrix4& recordedClipTransform);
+    void applyClip(const ClipBase* recordedClip, const Matrix4& recordedClipTransform);
+
 private:
     void enterRectangleMode();
     void rectangleModeClipRectWithTransform(const Rect& r, const mat4* transform, SkRegion::Op op);
@@ -145,6 +193,13 @@
     void ensureClipRegion();
     void onClipRegionUpdated();
 
+    // Called by every state modifying public method.
+    void onClipUpdated() {
+        mPostViewportClipObserved = true;
+        mLastSerialization = nullptr;
+        mLastResolutionResult = nullptr;
+    }
+
     SkRegion createViewportRegion() {
         return SkRegion(mViewportBounds.toSkIRect());
     }
@@ -155,7 +210,22 @@
         pathAsRegion.setPath(path, createViewportRegion());
     }
 
-    Mode mMode;
+    ClipMode mMode;
+    bool mPostViewportClipObserved = false;
+
+    /**
+     * If mLastSerialization is non-null, it represents an already serialized copy
+     * of the current clip state. If null, it has not been computed.
+     */
+    const ClipBase* mLastSerialization = nullptr;
+
+    /**
+     * This pair of pointers is a single entry cache of most recently seen
+     */
+    const ClipBase* mLastResolutionResult = nullptr;
+    const ClipBase* mLastResolutionClip = nullptr;
+    Matrix4 mLastResolutionTransform;
+
     Rect mViewportBounds;
     Rect mClipRect;
     SkRegion mClipRegion;
diff --git a/libs/hwui/FontRenderer.h b/libs/hwui/FontRenderer.h
index ff4dc4a..9994498 100644
--- a/libs/hwui/FontRenderer.h
+++ b/libs/hwui/FontRenderer.h
@@ -47,6 +47,7 @@
 #if HWUI_NEW_OPS
 class BakedOpState;
 class BakedOpRenderer;
+struct ClipBase;
 #else
 class OpenGLRenderer;
 #endif
@@ -57,7 +58,7 @@
 #if HWUI_NEW_OPS
             BakedOpRenderer* renderer,
             const BakedOpState* bakedState,
-            const Rect* clip,
+            const ClipBase* clip,
 #else
             OpenGLRenderer* renderer,
 #endif
@@ -81,7 +82,7 @@
 #if HWUI_NEW_OPS
     BakedOpRenderer* renderer;
     const BakedOpState* bakedState;
-    const Rect* clip;
+    const ClipBase* clip;
 #else
     OpenGLRenderer* renderer;
 #endif
diff --git a/libs/hwui/Glop.h b/libs/hwui/Glop.h
index bcf819e..e72f396 100644
--- a/libs/hwui/Glop.h
+++ b/libs/hwui/Glop.h
@@ -64,7 +64,7 @@
 
         // Canvas transform isn't applied to the mesh at draw time,
         //since it's already built in.
-        MeshIgnoresCanvasTransform = 1 << 1, // TODO: remove
+        MeshIgnoresCanvasTransform = 1 << 1, // TODO: remove for HWUI_NEW_OPS
     };
 };
 
diff --git a/libs/hwui/GlopBuilder.cpp b/libs/hwui/GlopBuilder.cpp
index 2507ff3..45fc16c 100644
--- a/libs/hwui/GlopBuilder.cpp
+++ b/libs/hwui/GlopBuilder.cpp
@@ -78,7 +78,7 @@
     mOutGlop->mesh.vertices = {
             vbo,
             VertexAttribFlags::TextureCoord,
-            nullptr, nullptr, nullptr,
+            nullptr, (const void*) kMeshTextureOffset, nullptr,
             kTextureVertexStride };
     mOutGlop->mesh.elementCount = elementCount;
     return *this;
diff --git a/libs/hwui/OpReorderer.cpp b/libs/hwui/OpReorderer.cpp
index ad9559f..3f492d5 100644
--- a/libs/hwui/OpReorderer.cpp
+++ b/libs/hwui/OpReorderer.cpp
@@ -460,7 +460,7 @@
             deferBeginLayerOp(*new (mAllocator) BeginLayerOp(
                     saveLayerBounds,
                     Matrix4::identity(),
-                    saveLayerBounds,
+                    nullptr, // no record-time clip - need only respect defer-time one
                     &saveLayerPaint));
             deferNodeOps(node);
             deferEndLayerOp(*new (mAllocator) EndLayerOp());
@@ -604,7 +604,7 @@
             mCanvasState.getLocalClipBounds(),
             mCanvasState.currentSnapshot()->getRelativeLightCenter());
     BakedOpState* bakedOpState = BakedOpState::tryShadowOpConstruct(
-            mAllocator, *mCanvasState.currentSnapshot(), shadowOp);
+            mAllocator, *mCanvasState.writableSnapshot(), shadowOp);
     if (CC_LIKELY(bakedOpState)) {
         currentLayer().deferUnmergeableOp(mAllocator, bakedOpState, OpBatchType::Shadow);
     }
@@ -652,9 +652,7 @@
         [](OpReorderer& reorderer, const RecordedOp& op) { reorderer.defer##Type(static_cast<const Type&>(op)); },
 void OpReorderer::deferNodeOps(const RenderNode& renderNode) {
     typedef void (*OpDispatcher) (OpReorderer& reorderer, const RecordedOp& op);
-    static OpDispatcher receivers[] = {
-        MAP_OPS(OP_RECEIVER)
-    };
+    static OpDispatcher receivers[] = BUILD_DEFERRABLE_OP_LUT(OP_RECEIVER);
 
     // can't be null, since DL=null node rejection happens before deferNodePropsAndOps
     const DisplayList& displayList = *(renderNode.getDisplayList());
@@ -681,10 +679,10 @@
     if (op.renderNode->nothingToDraw()) return;
     int count = mCanvasState.save(SkCanvas::kClip_SaveFlag | SkCanvas::kMatrix_SaveFlag);
 
-    // apply state from RecordedOp
+    // apply state from RecordedOp (clip first, since op's clip is transformed by current matrix)
+    mCanvasState.writableSnapshot()->mutateClipArea().applyClip(op.localClip,
+            *mCanvasState.currentSnapshot()->transform);
     mCanvasState.concatMatrix(op.localMatrix);
-    mCanvasState.clipRect(op.localClipRect.left, op.localClipRect.top,
-            op.localClipRect.right, op.localClipRect.bottom, SkRegion::kIntersect_Op);
 
     // then apply state from node properties, and defer ops
     deferNodePropsAndOps(*op.renderNode);
@@ -706,7 +704,7 @@
         BakedOpState::StrokeBehavior strokeBehavior) {
     // Note: here we account for stroke when baking the op
     BakedOpState* bakedState = BakedOpState::tryStrokeableOpConstruct(
-            mAllocator, *mCanvasState.currentSnapshot(), op, strokeBehavior);
+            mAllocator, *mCanvasState.writableSnapshot(), op, strokeBehavior);
     if (!bakedState) return; // quick rejected
     currentLayer().deferUnmergeableOp(mAllocator, bakedState, batchId);
 }
@@ -769,7 +767,7 @@
     const OvalOp* resolvedOp = new (mAllocator) OvalOp(
             unmappedBounds,
             op.localMatrix,
-            op.localClipRect,
+            op.localClip,
             op.paint);
     deferOvalOp(*resolvedOp);
 }
@@ -829,7 +827,7 @@
     const RoundRectOp* resolvedOp = new (mAllocator) RoundRectOp(
             Rect(*(op.left), *(op.top), *(op.right), *(op.bottom)),
             op.localMatrix,
-            op.localClipRect,
+            op.localClip,
             op.paint, *op.rx, *op.ry);
     deferRoundRectOp(*resolvedOp);
 }
@@ -953,7 +951,7 @@
     LayerOp* drawLayerOp = new (mAllocator) LayerOp(
             beginLayerOp.unmappedBounds,
             beginLayerOp.localMatrix,
-            beginLayerOp.localClipRect,
+            beginLayerOp.localClip,
             beginLayerOp.paint,
             &mLayerReorderers[finishedLayerIndex].offscreenBuffer);
     BakedOpState* bakedOpState = tryBakeOpState(*drawLayerOp);
@@ -968,13 +966,5 @@
     }
 }
 
-void OpReorderer::deferLayerOp(const LayerOp& op) {
-    LOG_ALWAYS_FATAL("unsupported");
-}
-
-void OpReorderer::deferShadowOp(const ShadowOp& op) {
-    LOG_ALWAYS_FATAL("unsupported");
-}
-
 } // namespace uirenderer
 } // namespace android
diff --git a/libs/hwui/OpReorderer.h b/libs/hwui/OpReorderer.h
index dbbce8b..429913f 100644
--- a/libs/hwui/OpReorderer.h
+++ b/libs/hwui/OpReorderer.h
@@ -138,7 +138,7 @@
     template <typename StaticDispatcher, typename Renderer>
     void replayBakedOps(Renderer& renderer) {
         /**
-         * defines a LUT of lambdas which allow a recorded BakedOpState to use state->op->opId to
+         * Defines a LUT of lambdas which allow a recorded BakedOpState to use state->op->opId to
          * dispatch the op via a method on a static dispatcher when the op is replayed.
          *
          * For example a BitmapOp would resolve, via the lambda lookup, to calling:
@@ -149,29 +149,19 @@
                 [](void* renderer, const BakedOpState& state) { \
                     StaticDispatcher::on##Type(*(static_cast<Renderer*>(renderer)), static_cast<const Type&>(*(state.op)), state); \
                 },
-        static BakedOpReceiver unmergedReceivers[] = {
-            MAP_OPS(X)
-        };
+        static BakedOpReceiver unmergedReceivers[] = BUILD_RENDERABLE_OP_LUT(X);
         #undef X
 
         /**
-         * defines a LUT of lambdas which allow merged arrays of BakedOpState* to be passed to a
-         * static dispatcher when the group of merged ops is replayed. Unmergeable ops trigger
-         * a LOG_ALWAYS_FATAL().
+         * Defines a LUT of lambdas which allow merged arrays of BakedOpState* to be passed to a
+         * static dispatcher when the group of merged ops is replayed.
          */
         #define X(Type) \
                 [](void* renderer, const MergedBakedOpList& opList) { \
-                    LOG_ALWAYS_FATAL("op type %d does not support merging", opList.states[0]->op->opId); \
-                },
-        #define Y(Type) \
-                [](void* renderer, const MergedBakedOpList& opList) { \
                     StaticDispatcher::onMerged##Type##s(*(static_cast<Renderer*>(renderer)), opList); \
                 },
-        static MergedOpReceiver mergedReceivers[] = {
-            MAP_OPS_BASED_ON_MERGEABILITY(X, Y)
-        };
+        static MergedOpReceiver mergedReceivers[] = BUILD_MERGEABLE_OP_LUT(X);
         #undef X
-        #undef Y
 
         // Relay through layers in reverse order, since layers
         // later in the list will be drawn by earlier ones
@@ -192,7 +182,7 @@
         const LayerReorderer& fbo0 = mLayerReorderers[0];
         renderer.startFrame(fbo0.width, fbo0.height, fbo0.repaintRect);
         fbo0.replayBakedOpsImpl((void*)&renderer, unmergedReceivers, mergedReceivers);
-        renderer.endFrame();
+        renderer.endFrame(fbo0.repaintRect);
     }
 
     void dump() const {
@@ -223,7 +213,7 @@
     LayerReorderer& currentLayer() { return mLayerReorderers[mLayerStack.back()]; }
 
     BakedOpState* tryBakeOpState(const RecordedOp& recordedOp) {
-        return BakedOpState::tryConstruct(mAllocator, *mCanvasState.currentSnapshot(), recordedOp);
+        return BakedOpState::tryConstruct(mAllocator, *mCanvasState.writableSnapshot(), recordedOp);
     }
 
     // should always be surrounded by a save/restore pair, and not called if DisplayList is null
@@ -256,9 +246,9 @@
      * These private methods are called from within deferImpl to defer each individual op
      * type differently.
      */
-#define INTERNAL_OP_HANDLER(Type) \
-    void defer##Type(const Type& op);
-    MAP_OPS(INTERNAL_OP_HANDLER)
+#define X(Type) void defer##Type(const Type& op);
+    MAP_DEFERRABLE_OPS(X)
+#undef X
 
     std::vector<std::unique_ptr<SkPath> > mFrameAllocatedPaths;
 
diff --git a/libs/hwui/RecordedOp.h b/libs/hwui/RecordedOp.h
index cfdd0d2..b243f99 100644
--- a/libs/hwui/RecordedOp.h
+++ b/libs/hwui/RecordedOp.h
@@ -33,68 +33,96 @@
 namespace android {
 namespace uirenderer {
 
+struct ClipBase;
 class OffscreenBuffer;
 class RenderNode;
 struct Vertex;
 
 /**
- * On of the provided macros is executed for each op type in order. The first will be used for ops
- * that cannot merge, and the second for those that can.
+ * Authoritative op list, used for generating the op ID enum, ID based LUTS, and
+ * the functions to which they dispatch. Parameter macros are executed for each op,
+ * in order, based on the op's type.
  *
- * This serves as the authoritative list of ops, used for generating ID enum, and ID based LUTs.
+ * There are 4 types of op:
+ *
+ * Pre render - not directly consumed by renderer, reorder stage resolves this into renderable type
+ * Render only - generated renderable ops - never passed to a reorderer
+ * Unmergeable - reorderable, renderable (but not mergeable)
+ * Mergeable - reorderable, renderable (and mergeable)
  */
-#define MAP_OPS_BASED_ON_MERGEABILITY(U_OP_FN, M_OP_FN) \
-        U_OP_FN(ArcOp) \
-        M_OP_FN(BitmapOp) \
-        U_OP_FN(BitmapMeshOp) \
-        U_OP_FN(BitmapRectOp) \
-        U_OP_FN(CirclePropsOp) \
-        U_OP_FN(FunctorOp) \
-        U_OP_FN(LinesOp) \
-        U_OP_FN(OvalOp) \
-        M_OP_FN(PatchOp) \
-        U_OP_FN(PathOp) \
-        U_OP_FN(PointsOp) \
-        U_OP_FN(RectOp) \
-        U_OP_FN(RenderNodeOp) \
-        U_OP_FN(RoundRectOp) \
-        U_OP_FN(RoundRectPropsOp) \
-        U_OP_FN(ShadowOp) \
-        U_OP_FN(SimpleRectsOp) \
-        M_OP_FN(TextOp) \
-        U_OP_FN(TextOnPathOp) \
-        U_OP_FN(TextureLayerOp) \
-        U_OP_FN(BeginLayerOp) \
-        U_OP_FN(EndLayerOp) \
-        U_OP_FN(LayerOp)
+#define MAP_OPS_BASED_ON_TYPE(PRE_RENDER_OP_FN, RENDER_ONLY_OP_FN, UNMERGEABLE_OP_FN, MERGEABLE_OP_FN) \
+        PRE_RENDER_OP_FN(RenderNodeOp) \
+        PRE_RENDER_OP_FN(CirclePropsOp) \
+        PRE_RENDER_OP_FN(RoundRectPropsOp) \
+        PRE_RENDER_OP_FN(BeginLayerOp) \
+        PRE_RENDER_OP_FN(EndLayerOp) \
+        \
+        RENDER_ONLY_OP_FN(ShadowOp) \
+        RENDER_ONLY_OP_FN(LayerOp) \
+        \
+        UNMERGEABLE_OP_FN(ArcOp) \
+        UNMERGEABLE_OP_FN(BitmapMeshOp) \
+        UNMERGEABLE_OP_FN(BitmapRectOp) \
+        UNMERGEABLE_OP_FN(FunctorOp) \
+        UNMERGEABLE_OP_FN(LinesOp) \
+        UNMERGEABLE_OP_FN(OvalOp) \
+        UNMERGEABLE_OP_FN(PathOp) \
+        UNMERGEABLE_OP_FN(PointsOp) \
+        UNMERGEABLE_OP_FN(RectOp) \
+        UNMERGEABLE_OP_FN(RoundRectOp) \
+        UNMERGEABLE_OP_FN(SimpleRectsOp) \
+        UNMERGEABLE_OP_FN(TextOnPathOp) \
+        UNMERGEABLE_OP_FN(TextureLayerOp) \
+        \
+        MERGEABLE_OP_FN(BitmapOp) \
+        MERGEABLE_OP_FN(PatchOp) \
+        MERGEABLE_OP_FN(TextOp)
 
 /**
- * The provided macro is executed for each op type in order. This is used in cases where
- * merge-ability of ops doesn't matter.
+ * LUT generators, which will insert nullptr for unsupported ops
  */
-#define MAP_OPS(OP_FN) \
-        MAP_OPS_BASED_ON_MERGEABILITY(OP_FN, OP_FN)
+#define NULLPTR_OP_FN(Type) nullptr,
 
+#define BUILD_DEFERRABLE_OP_LUT(OP_FN) \
+        { MAP_OPS_BASED_ON_TYPE(OP_FN, NULLPTR_OP_FN, OP_FN, OP_FN) }
+
+#define BUILD_MERGEABLE_OP_LUT(OP_FN) \
+        { MAP_OPS_BASED_ON_TYPE(NULLPTR_OP_FN, NULLPTR_OP_FN, NULLPTR_OP_FN, OP_FN) }
+
+#define BUILD_RENDERABLE_OP_LUT(OP_FN) \
+        { MAP_OPS_BASED_ON_TYPE(NULLPTR_OP_FN, OP_FN, OP_FN, OP_FN) }
+
+/**
+ * Op mapping functions, which skip unsupported ops.
+ *
+ * Note: Do not use for LUTS, since these do not preserve ID order.
+ */
 #define NULL_OP_FN(Type)
 
-#define MAP_MERGED_OPS(OP_FN) \
-        MAP_OPS_BASED_ON_MERGEABILITY(NULL_OP_FN, OP_FN)
+#define MAP_MERGEABLE_OPS(OP_FN) \
+        MAP_OPS_BASED_ON_TYPE(NULL_OP_FN, NULL_OP_FN, NULL_OP_FN, OP_FN)
+
+#define MAP_RENDERABLE_OPS(OP_FN) \
+        MAP_OPS_BASED_ON_TYPE(NULL_OP_FN, OP_FN, OP_FN, OP_FN)
+
+#define MAP_DEFERRABLE_OPS(OP_FN) \
+        MAP_OPS_BASED_ON_TYPE(OP_FN, NULL_OP_FN, OP_FN, OP_FN)
 
 // Generate OpId enum
 #define IDENTITY_FN(Type) Type,
 namespace RecordedOpId {
     enum {
-        MAP_OPS(IDENTITY_FN)
+        MAP_OPS_BASED_ON_TYPE(IDENTITY_FN, IDENTITY_FN, IDENTITY_FN, IDENTITY_FN)
         Count,
     };
 }
-static_assert(RecordedOpId::ArcOp == 0,
+static_assert(RecordedOpId::RenderNodeOp == 0,
         "First index must be zero for LUTs to work");
 
-#define BASE_PARAMS const Rect& unmappedBounds, const Matrix4& localMatrix, const Rect& localClipRect, const SkPaint* paint
-#define BASE_PARAMS_PAINTLESS const Rect& unmappedBounds, const Matrix4& localMatrix, const Rect& localClipRect
-#define SUPER(Type) RecordedOp(RecordedOpId::Type, unmappedBounds, localMatrix, localClipRect, paint)
-#define SUPER_PAINTLESS(Type) RecordedOp(RecordedOpId::Type, unmappedBounds, localMatrix, localClipRect, nullptr)
+#define BASE_PARAMS const Rect& unmappedBounds, const Matrix4& localMatrix, const ClipBase* localClip, const SkPaint* paint
+#define BASE_PARAMS_PAINTLESS const Rect& unmappedBounds, const Matrix4& localMatrix, const ClipBase* localClip
+#define SUPER(Type) RecordedOp(RecordedOpId::Type, unmappedBounds, localMatrix, localClip, paint)
+#define SUPER_PAINTLESS(Type) RecordedOp(RecordedOpId::Type, unmappedBounds, localMatrix, localClip, nullptr)
 
 struct RecordedOp {
     /* ID from RecordedOpId - generally used for jumping into function tables */
@@ -106,8 +134,8 @@
     /* transform in recording space (vs DisplayList origin) */
     const Matrix4 localMatrix;
 
-    /* clip in recording space */
-    const Rect localClipRect;
+    /* clip in recording space - nullptr if not clipped */
+    const ClipBase* localClip;
 
     /* optional paint, stored in base object to simplify merging logic */
     const SkPaint* paint;
@@ -116,7 +144,7 @@
             : opId(opId)
             , unmappedBounds(unmappedBounds)
             , localMatrix(localMatrix)
-            , localClipRect(localClipRect)
+            , localClip(localClip)
             , paint(paint) {}
 };
 
@@ -187,9 +215,9 @@
 };
 
 struct CirclePropsOp : RecordedOp {
-    CirclePropsOp(const Matrix4& localMatrix, const Rect& localClipRect, const SkPaint* paint,
+    CirclePropsOp(const Matrix4& localMatrix, const ClipBase* localClip, const SkPaint* paint,
             float* x, float* y, float* radius)
-            : RecordedOp(RecordedOpId::CirclePropsOp, Rect(), localMatrix, localClipRect, paint)
+            : RecordedOp(RecordedOpId::CirclePropsOp, Rect(), localMatrix, localClip, paint)
             , x(x)
             , y(y)
             , radius(radius) {}
@@ -259,9 +287,9 @@
 };
 
 struct RoundRectPropsOp : RecordedOp {
-    RoundRectPropsOp(const Matrix4& localMatrix, const Rect& localClipRect, const SkPaint* paint,
+    RoundRectPropsOp(const Matrix4& localMatrix, const ClipBase* localClip, const SkPaint* paint,
             float* left, float* top, float* right, float* bottom, float *rx, float *ry)
-            : RecordedOp(RecordedOpId::RoundRectPropsOp, Rect(), localMatrix, localClipRect, paint)
+            : RecordedOp(RecordedOpId::RoundRectPropsOp, Rect(), localMatrix, localClip, paint)
             , left(left)
             , top(top)
             , right(right)
@@ -286,12 +314,13 @@
  */
 struct ShadowOp : RecordedOp {
     ShadowOp(const RenderNodeOp& casterOp, float casterAlpha, const SkPath* casterPath,
-            const Rect& clipRect, const Vector3& lightCenter)
-            : RecordedOp(RecordedOpId::ShadowOp, Rect(), Matrix4::identity(), clipRect, nullptr)
+            const Rect& localClipRect, const Vector3& lightCenter)
+            : RecordedOp(RecordedOpId::ShadowOp, Rect(), Matrix4::identity(), nullptr, nullptr)
             , shadowMatrixXY(casterOp.localMatrix)
             , shadowMatrixZ(casterOp.localMatrix)
             , casterAlpha(casterAlpha)
             , casterPath(casterPath)
+            , localClipRect(localClipRect)
             , lightCenter(lightCenter) {
         const RenderNode& node = *casterOp.renderNode;
         node.applyViewPropertyTransforms(shadowMatrixXY, false);
@@ -301,6 +330,7 @@
     Matrix4 shadowMatrixZ;
     const float casterAlpha;
     const SkPath* casterPath;
+    const Rect localClipRect;
     const Vector3 lightCenter;
 };
 
@@ -374,7 +404,7 @@
  */
 struct EndLayerOp : RecordedOp {
     EndLayerOp()
-            : RecordedOp(RecordedOpId::EndLayerOp, Rect(), Matrix4::identity(), Rect(), nullptr) {}
+            : RecordedOp(RecordedOpId::EndLayerOp, Rect(), Matrix4::identity(), nullptr, nullptr) {}
 };
 
 /**
@@ -388,13 +418,13 @@
     LayerOp(BASE_PARAMS, OffscreenBuffer** layerHandle)
             : SUPER_PAINTLESS(LayerOp)
             , layerHandle(layerHandle)
-            , alpha(paint->getAlpha() / 255.0f)
+            , alpha(paint ? paint->getAlpha() / 255.0f : 1.0f)
             , mode(PaintUtils::getXfermodeDirect(paint))
-            , colorFilter(paint->getColorFilter())
+            , colorFilter(paint ? paint->getColorFilter() : nullptr)
             , destroy(true) {}
 
     LayerOp(RenderNode& node)
-        : RecordedOp(RecordedOpId::LayerOp, Rect(node.getWidth(), node.getHeight()), Matrix4::identity(), Rect(node.getWidth(), node.getHeight()), nullptr)
+        : RecordedOp(RecordedOpId::LayerOp, Rect(node.getWidth(), node.getHeight()), Matrix4::identity(), nullptr, nullptr)
         , layerHandle(node.getLayerHandle())
         , alpha(node.properties().layerProperties().alpha() / 255.0f)
         , mode(node.properties().layerProperties().xferMode())
diff --git a/libs/hwui/RecordingCanvas.cpp b/libs/hwui/RecordingCanvas.cpp
index f75d8d4..f7f6caf 100644
--- a/libs/hwui/RecordingCanvas.cpp
+++ b/libs/hwui/RecordingCanvas.cpp
@@ -39,7 +39,7 @@
             "prepareDirty called a second time during a recording!");
     mDisplayList = new DisplayList();
 
-    mState.initializeSaveStack(width, height, 0, 0, width, height, Vector3());
+    mState.initializeRecordingSaveStack(width, height);
 
     mDeferredBarrierType = DeferredBarrierType::InOrder;
     mState.setDirtyClip(false);
@@ -155,6 +155,8 @@
         return saveValue;
     }
 
+    auto previousClip = getRecordedClip(); // note: done while snapshot == previous
+
     snapshot.flags |= Snapshot::kFlagFboTarget | Snapshot::kFlagIsFboLayer;
     snapshot.initializeViewport(untransformedBounds.getWidth(), untransformedBounds.getHeight());
     snapshot.transform->loadTranslate(-untransformedBounds.left, -untransformedBounds.top, 0.0f);
@@ -167,7 +169,7 @@
     addOp(new (alloc()) BeginLayerOp(
             Rect(left, top, right, bottom),
             *previous.transform, // transform to *draw* with
-            previous.getRenderTargetClip(), // clip to *draw* with
+            previousClip, // clip to *draw* with
             refPaint(paint)));
 
     return saveValue;
@@ -229,11 +231,10 @@
 }
 
 void RecordingCanvas::drawPaint(const SkPaint& paint) {
-    // TODO: more efficient recording?
     addOp(new (alloc()) RectOp(
-            mState.getRenderTargetClipBounds(),
+            mState.getRenderTargetClipBounds(), // OK, since we've not passed transform
             Matrix4::identity(),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(&paint)));
 }
 
@@ -253,7 +254,7 @@
     addOp(new (alloc()) PointsOp(
             calcBoundsOfPoints(points, floatCount),
             *mState.currentSnapshot()->transform,
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(&paint), refBuffer<float>(points, floatCount), floatCount));
 }
 
@@ -264,7 +265,7 @@
     addOp(new (alloc()) LinesOp(
             calcBoundsOfPoints(points, floatCount),
             *mState.currentSnapshot()->transform,
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(&paint), refBuffer<float>(points, floatCount), floatCount));
 }
 
@@ -272,7 +273,7 @@
     addOp(new (alloc()) RectOp(
             Rect(left, top, right, bottom),
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(&paint)));
 }
 
@@ -305,7 +306,7 @@
     addOp(new (alloc()) SimpleRectsOp(
             Rect(left, top, right, bottom),
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(paint), rectData, vertexCount));
 }
 
@@ -339,7 +340,7 @@
     addOp(new (alloc()) RoundRectOp(
             Rect(left, top, right, bottom),
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(&paint), rx, ry));
 }
 
@@ -358,7 +359,7 @@
     refBitmapsInShader(paint->value.getShader());
     addOp(new (alloc()) RoundRectPropsOp(
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             &paint->value,
             &left->value, &top->value, &right->value, &bottom->value,
             &rx->value, &ry->value));
@@ -380,7 +381,7 @@
     refBitmapsInShader(paint->value.getShader());
     addOp(new (alloc()) CirclePropsOp(
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             &paint->value,
             &x->value, &y->value, &radius->value));
 }
@@ -390,7 +391,7 @@
     addOp(new (alloc()) OvalOp(
             Rect(left, top, right, bottom),
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(&paint)));
 }
 
@@ -399,7 +400,7 @@
     addOp(new (alloc()) ArcOp(
             Rect(left, top, right, bottom),
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(&paint),
             startAngle, sweepAngle, useCenter));
 }
@@ -408,7 +409,7 @@
     addOp(new (alloc()) PathOp(
             Rect(path.getBounds()),
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(&paint), refPath(&path)));
 }
 
@@ -459,7 +460,7 @@
         addOp(new (alloc()) BitmapRectOp(
                 Rect(dstLeft, dstTop, dstRight, dstBottom),
                 *(mState.currentSnapshot()->transform),
-                mState.getRenderTargetClipBounds(),
+                getRecordedClip(),
                 refPaint(paint), refBitmap(bitmap),
                 Rect(srcLeft, srcTop, srcRight, srcBottom)));
     }
@@ -471,7 +472,7 @@
     addOp(new (alloc()) BitmapMeshOp(
             calcBoundsOfPoints(vertices, vertexCount * 2),
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(paint), refBitmap(bitmap), meshWidth, meshHeight,
             refBuffer<float>(vertices, vertexCount * 2), // 2 floats per vertex
             refBuffer<int>(colors, vertexCount))); // 1 color per vertex
@@ -483,7 +484,7 @@
     addOp(new (alloc()) PatchOp(
             Rect(dstLeft, dstTop, dstRight, dstBottom),
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(paint), refBitmap(bitmap), refPatch(&patch)));
 }
 
@@ -499,7 +500,7 @@
     addOp(new (alloc()) TextOp(
             Rect(boundsLeft, boundsTop, boundsRight, boundsBottom),
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(&paint), glyphs, positions, glyphCount, x, y));
     drawTextDecorations(x, y, totalAdvance, paint);
 }
@@ -509,9 +510,9 @@
     if (!glyphs || glyphCount <= 0 || PaintUtils::paintWillNotDrawText(paint)) return;
     glyphs = refBuffer<glyph_t>(glyphs, glyphCount);
     addOp(new (alloc()) TextOnPathOp(
-            mState.getRenderTargetClipBounds(), // TODO: explicitly define bounds
+            mState.getLocalClipBounds(), // TODO: explicitly define bounds
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(&paint), glyphs, glyphCount, refPath(&path), hOffset, vOffset));
 }
 
@@ -519,7 +520,7 @@
     addOp(new (alloc()) BitmapOp(
             Rect(bitmap->width(), bitmap->height()),
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             refPaint(paint), refBitmap(*bitmap)));
 }
 
@@ -528,7 +529,7 @@
     RenderNodeOp* op = new (alloc()) RenderNodeOp(
             Rect(stagingProps.getWidth(), stagingProps.getHeight()),
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             renderNode);
     int opIndex = addOp(op);
     int childIndex = mDisplayList->addChild(op);
@@ -554,16 +555,16 @@
     addOp(new (alloc()) TextureLayerOp(
             Rect(layer->getWidth(), layer->getHeight()),
             totalTransform,
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             layer));
 }
 
 void RecordingCanvas::callDrawGLFunction(Functor* functor) {
     mDisplayList->functors.push_back(functor);
     addOp(new (alloc()) FunctorOp(
-            mState.getRenderTargetClipBounds(), // TODO: explicitly define bounds
+            mState.getLocalClipBounds(), // TODO: explicitly define bounds
             *(mState.currentSnapshot()->transform),
-            mState.getRenderTargetClipBounds(),
+            getRecordedClip(),
             functor));
 }
 
diff --git a/libs/hwui/RecordingCanvas.h b/libs/hwui/RecordingCanvas.h
index 470f9ec..1a2ac97f 100644
--- a/libs/hwui/RecordingCanvas.h
+++ b/libs/hwui/RecordingCanvas.h
@@ -36,6 +36,7 @@
 namespace android {
 namespace uirenderer {
 
+struct ClipBase;
 class DeferredLayerUpdater;
 struct RecordedOp;
 
@@ -199,6 +200,9 @@
     virtual bool drawTextAbsolutePos() const override { return false; }
 
 private:
+    const ClipBase* getRecordedClip() {
+        return mState.writableSnapshot()->mutateClipArea().serializeClip(alloc());
+    }
 
     void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
     void drawSimpleRects(const float* rects, int vertexCount, const SkPaint* paint);
diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h
index 194aa57..5fac3a1 100644
--- a/libs/hwui/Snapshot.h
+++ b/libs/hwui/Snapshot.h
@@ -167,6 +167,7 @@
     const SkRegion& getClipRegion() const { return mClipArea->getClipRegion(); }
     bool clipIsSimple() const { return mClipArea->isSimple(); }
     const ClipArea& getClipArea() const { return *mClipArea; }
+    ClipArea& mutateClipArea() { return *mClipArea; }
 
     /**
      * Resets the clip to the specified rect.
diff --git a/libs/hwui/renderstate/Scissor.cpp b/libs/hwui/renderstate/Scissor.cpp
index 95dcd18..61dd8c3 100644
--- a/libs/hwui/renderstate/Scissor.cpp
+++ b/libs/hwui/renderstate/Scissor.cpp
@@ -15,6 +15,8 @@
  */
 #include "renderstate/Scissor.h"
 
+#include "Rect.h"
+
 #include <utils/Log.h>
 
 namespace android {
@@ -71,6 +73,26 @@
     return false;
 }
 
+void Scissor::set(int viewportHeight, const Rect& clip) {
+    // transform to Y-flipped GL space, and prevent negatives
+    GLint x = std::max(0, (int)clip.left);
+    GLint y = std::max(0, viewportHeight - (int)clip.bottom);
+    GLint width = std::max(0, ((int)clip.right) - x);
+    GLint height = std::max(0, (viewportHeight - (int)clip.top) - y);
+
+    if (x != mScissorX
+            || y != mScissorY
+            || width != mScissorWidth
+            || height != mScissorHeight) {
+        glScissor(x, y, width, height);
+
+        mScissorX = x;
+        mScissorY = y;
+        mScissorWidth = width;
+        mScissorHeight = height;
+    }
+}
+
 void Scissor::reset() {
     mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
 }
diff --git a/libs/hwui/renderstate/Scissor.h b/libs/hwui/renderstate/Scissor.h
index b37ec58..f302244 100644
--- a/libs/hwui/renderstate/Scissor.h
+++ b/libs/hwui/renderstate/Scissor.h
@@ -22,11 +22,14 @@
 namespace android {
 namespace uirenderer {
 
+class Rect;
+
 class Scissor {
     friend class RenderState;
 public:
     bool setEnabled(bool enabled);
     bool set(GLint x, GLint y, GLint width, GLint height);
+    void set(int viewportHeight, const Rect& clip);
     void reset();
     bool isEnabled() { return mEnabled; }
     void dump();
diff --git a/libs/hwui/tests/common/scenes/ClippingAnimation.cpp b/libs/hwui/tests/common/scenes/ClippingAnimation.cpp
new file mode 100644
index 0000000..db6402c
--- /dev/null
+++ b/libs/hwui/tests/common/scenes/ClippingAnimation.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "TestSceneBase.h"
+
+class ClippingAnimation;
+
+static TestScene::Registrar _RectGrid(TestScene::Info{
+    "clip",
+    "Complex clip cases"
+    "Low CPU/GPU load.",
+    TestScene::simpleCreateScene<ClippingAnimation>
+});
+
+class ClippingAnimation : public TestScene {
+public:
+    sp<RenderNode> card;
+    void createContent(int width, int height, TestCanvas& canvas) override {
+        canvas.drawColor(Color::White, SkXfermode::kSrcOver_Mode);
+        card = TestUtils::createNode(0, 0, 200, 400,
+                [](RenderProperties& props, TestCanvas& canvas) {
+            canvas.save(SkCanvas::kMatrixClip_SaveFlag);
+            {
+                canvas.clipRect(0, 0, 200, 200, SkRegion::kIntersect_Op);
+                canvas.translate(100, 100);
+                canvas.rotate(45);
+                canvas.translate(-100, -100);
+                canvas.clipRect(0, 0, 200, 200, SkRegion::kIntersect_Op);
+                canvas.drawColor(Color::Blue_500, SkXfermode::kSrcOver_Mode);
+            }
+            canvas.restore();
+
+            canvas.save(SkCanvas::kMatrixClip_SaveFlag);
+            {
+                SkPath clipCircle;
+                clipCircle.addCircle(100, 300, 100);
+                canvas.clipPath(&clipCircle, SkRegion::kIntersect_Op);
+                canvas.drawColor(Color::Red_500, SkXfermode::kSrcOver_Mode);
+            }
+            canvas.restore();
+
+            // put on a layer, to test stencil attachment
+            props.mutateLayerProperties().setType(LayerType::RenderLayer);
+            props.setAlpha(0.9f);
+        });
+        canvas.drawRenderNode(card.get());
+    }
+    void doFrame(int frameNr) override {
+        int curFrame = frameNr % 150;
+        card->mutateStagingProperties().setTranslationX(curFrame);
+        card->mutateStagingProperties().setTranslationY(curFrame);
+        card->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y);
+    }
+};
diff --git a/libs/hwui/tests/common/scenes/TestSceneBase.h b/libs/hwui/tests/common/scenes/TestSceneBase.h
index ac78124..935ddcf 100644
--- a/libs/hwui/tests/common/scenes/TestSceneBase.h
+++ b/libs/hwui/tests/common/scenes/TestSceneBase.h
@@ -22,6 +22,7 @@
 #include "tests/common/TestContext.h"
 #include "tests/common/TestScene.h"
 #include "tests/common/TestUtils.h"
+#include "utils/Color.h"
 
 #include <functional>
 
diff --git a/libs/hwui/tests/unit/BakedOpStateTests.cpp b/libs/hwui/tests/unit/BakedOpStateTests.cpp
index f9f5316..3fd822d 100644
--- a/libs/hwui/tests/unit/BakedOpStateTests.cpp
+++ b/libs/hwui/tests/unit/BakedOpStateTests.cpp
@@ -17,6 +17,7 @@
 #include <gtest/gtest.h>
 
 #include <BakedOpState.h>
+#include <ClipArea.h>
 #include <RecordedOp.h>
 #include <tests/common/TestUtils.h>
 
@@ -24,31 +25,33 @@
 namespace uirenderer {
 
 TEST(ResolvedRenderState, construct) {
+    LinearAllocator allocator;
     Matrix4 translate10x20;
     translate10x20.loadTranslate(10, 20, 0);
 
     SkPaint paint;
-    RectOp recordedOp(Rect(30, 40, 100, 200), translate10x20, Rect(100, 200), &paint);
+    ClipRect clip(Rect(100, 200));
+    RectOp recordedOp(Rect(30, 40, 100, 200), translate10x20, &clip, &paint);
     {
         // recorded with transform, no parent transform
         auto parentSnapshot = TestUtils::makeSnapshot(Matrix4::identity(), Rect(100, 200));
-        ResolvedRenderState state(*parentSnapshot, recordedOp, false);
+        ResolvedRenderState state(allocator, *parentSnapshot, recordedOp, false);
         EXPECT_MATRIX_APPROX_EQ(state.transform, translate10x20);
-        EXPECT_EQ(Rect(100, 200), state.clipRect);
+        EXPECT_EQ(Rect(100, 200), state.clipRect());
         EXPECT_EQ(Rect(40, 60, 100, 200), state.clippedBounds); // translated and also clipped
         EXPECT_EQ(OpClipSideFlags::Right | OpClipSideFlags::Bottom, state.clipSideFlags);
     }
     {
         // recorded with transform and parent transform
         auto parentSnapshot = TestUtils::makeSnapshot(translate10x20, Rect(100, 200));
-        ResolvedRenderState state(*parentSnapshot, recordedOp, false);
+        ResolvedRenderState state(allocator, *parentSnapshot, recordedOp, false);
 
         Matrix4 expectedTranslate;
         expectedTranslate.loadTranslate(20, 40, 0);
         EXPECT_MATRIX_APPROX_EQ(expectedTranslate, state.transform);
 
         // intersection of parent & transformed child clip
-        EXPECT_EQ(Rect(10, 20, 100, 200), state.clipRect);
+        EXPECT_EQ(Rect(10, 20, 100, 200), state.clipRect());
 
         // translated and also clipped
         EXPECT_EQ(Rect(50, 80, 100, 200), state.clippedBounds);
@@ -57,22 +60,24 @@
 }
 
 TEST(ResolvedRenderState, computeLocalSpaceClip) {
+    LinearAllocator allocator;
     Matrix4 translate10x20;
     translate10x20.loadTranslate(10, 20, 0);
 
     SkPaint paint;
-    RectOp recordedOp(Rect(1000, 1000), translate10x20, Rect(100, 200), &paint);
+    ClipRect clip(Rect(100, 200));
+    RectOp recordedOp(Rect(1000, 1000), translate10x20, &clip, &paint);
     {
         // recorded with transform, no parent transform
         auto parentSnapshot = TestUtils::makeSnapshot(Matrix4::identity(), Rect(100, 200));
-        ResolvedRenderState state(*parentSnapshot, recordedOp, false);
+        ResolvedRenderState state(allocator, *parentSnapshot, recordedOp, false);
         EXPECT_EQ(Rect(-10, -20, 90, 180), state.computeLocalSpaceClip())
             << "Local clip rect should be 100x200, offset by -10,-20";
     }
     {
         // recorded with transform + parent transform
         auto parentSnapshot = TestUtils::makeSnapshot(translate10x20, Rect(100, 200));
-        ResolvedRenderState state(*parentSnapshot, recordedOp, false);
+        ResolvedRenderState state(allocator, *parentSnapshot, recordedOp, false);
         EXPECT_EQ(Rect(-10, -20, 80, 160), state.computeLocalSpaceClip())
             << "Local clip rect should be 90x190, offset by -10,-20";
     }
@@ -149,6 +154,7 @@
 };
 
 TEST(ResolvedRenderState, construct_expandForStroke) {
+    LinearAllocator allocator;
     // Loop over table of test cases and verify different combinations of stroke width and transform
     for (auto&& testCase : sStrokeTestCases) {
         SkPaint strokedPaint;
@@ -156,14 +162,15 @@
         strokedPaint.setStyle(SkPaint::kStroke_Style);
         strokedPaint.setStrokeWidth(testCase.strokeWidth);
 
+        ClipRect clip(Rect(200, 200));
         RectOp recordedOp(Rect(50, 50, 150, 150),
-                Matrix4::identity(), Rect(200, 200), &strokedPaint);
+                Matrix4::identity(), &clip, &strokedPaint);
 
         Matrix4 snapshotMatrix;
         snapshotMatrix.loadScale(testCase.scale, testCase.scale, 1);
         auto parentSnapshot = TestUtils::makeSnapshot(snapshotMatrix, Rect(200, 200));
 
-        ResolvedRenderState state(*parentSnapshot, recordedOp, true);
+        ResolvedRenderState state(allocator, *parentSnapshot, recordedOp, true);
         testCase.validator(state);
     }
 }
@@ -175,8 +182,9 @@
     translate100x0.loadTranslate(100, 0, 0);
 
     SkPaint paint;
+    ClipRect clip(Rect(100, 200));
     {
-        RectOp rejectOp(Rect(30, 40, 100, 200), translate100x0, Rect(100, 200), &paint);
+        RectOp rejectOp(Rect(30, 40, 100, 200), translate100x0, &clip, &paint);
         auto snapshot = TestUtils::makeSnapshot(Matrix4::identity(), Rect(100, 200));
         BakedOpState* bakedState = BakedOpState::tryConstruct(allocator, *snapshot, rejectOp);
 
@@ -184,7 +192,7 @@
         EXPECT_GT(8u, allocator.usedSize()); // no significant allocation space used for rejected op
     }
     {
-        RectOp successOp(Rect(30, 40, 100, 200), Matrix4::identity(), Rect(100, 200), &paint);
+        RectOp successOp(Rect(30, 40, 100, 200), Matrix4::identity(), &clip, &paint);
         auto snapshot = TestUtils::makeSnapshot(Matrix4::identity(), Rect(100, 200));
         BakedOpState* bakedState = BakedOpState::tryConstruct(allocator, *snapshot, successOp);
 
@@ -218,7 +226,8 @@
         SkPaint paint;
         paint.setStyle(SkPaint::kStrokeAndFill_Style);
         paint.setStrokeWidth(0.0f);
-        RectOp rejectOp(Rect(100, 200), Matrix4::identity(), Rect(100, 200), &paint);
+        ClipRect clip(Rect(100, 200));
+        RectOp rejectOp(Rect(100, 200), Matrix4::identity(), &clip, &paint);
         auto snapshot = TestUtils::makeSnapshot(Matrix4::identity(), Rect()); // Note: empty clip
         auto bakedState = BakedOpState::tryStrokeableOpConstruct(allocator, *snapshot, rejectOp,
                 BakedOpState::StrokeBehavior::StyleDefined);
@@ -231,7 +240,8 @@
         SkPaint paint;
         paint.setStyle(SkPaint::kStrokeAndFill_Style);
         paint.setStrokeWidth(10.0f);
-        RectOp rejectOp(Rect(50, 50, 150, 150), Matrix4::identity(), Rect(200, 200), &paint);
+        ClipRect clip(Rect(200, 200));
+        RectOp rejectOp(Rect(50, 50, 150, 150), Matrix4::identity(), &clip, &paint);
         auto snapshot = TestUtils::makeSnapshot(Matrix4::identity(), Rect(200, 200));
         auto bakedState = BakedOpState::tryStrokeableOpConstruct(allocator, *snapshot, rejectOp,
                 BakedOpState::StrokeBehavior::StyleDefined);
@@ -245,7 +255,8 @@
         SkPaint paint;
         paint.setStyle(SkPaint::kFill_Style);
         paint.setStrokeWidth(10.0f);
-        RectOp rejectOp(Rect(50, 50, 150, 150), Matrix4::identity(), Rect(200, 200), &paint);
+        ClipRect clip(Rect(200, 200));
+        RectOp rejectOp(Rect(50, 50, 150, 150), Matrix4::identity(), &clip, &paint);
         auto snapshot = TestUtils::makeSnapshot(Matrix4::identity(), Rect(200, 200));
         auto bakedState = BakedOpState::tryStrokeableOpConstruct(allocator, *snapshot, rejectOp,
                 BakedOpState::StrokeBehavior::Forced);
diff --git a/libs/hwui/tests/unit/ClipAreaTests.cpp b/libs/hwui/tests/unit/ClipAreaTests.cpp
index c4d305e..4cae737 100644
--- a/libs/hwui/tests/unit/ClipAreaTests.cpp
+++ b/libs/hwui/tests/unit/ClipAreaTests.cpp
@@ -119,5 +119,122 @@
     EXPECT_EQ(expected, area.getClipRect());
 }
 
+TEST(ClipArea, serializeClip) {
+    ClipArea area(createClipArea());
+    LinearAllocator allocator;
+
+    // unset clip
+    EXPECT_EQ(nullptr, area.serializeClip(allocator));
+
+    // rect clip
+    area.setClip(0, 0, 200, 200);
+    {
+        auto serializedClip = area.serializeClip(allocator);
+        ASSERT_NE(nullptr, serializedClip);
+        ASSERT_EQ(ClipMode::Rectangle, serializedClip->mode);
+        auto clipRect = reinterpret_cast<const ClipRect*>(serializedClip);
+        ASSERT_EQ(Rect(200, 200), clipRect->rect);
+        EXPECT_EQ(serializedClip, area.serializeClip(allocator))
+                << "Requery of clip on unmodified ClipArea must return same pointer.";
+    }
+
+    // rect list
+    Matrix4 rotate;
+    rotate.loadRotate(2.0f);
+    area.clipRectWithTransform(Rect(200, 200), &rotate, SkRegion::kIntersect_Op);
+    {
+        auto serializedClip = area.serializeClip(allocator);
+        ASSERT_NE(nullptr, serializedClip);
+        ASSERT_EQ(ClipMode::RectangleList, serializedClip->mode);
+        auto clipRectList = reinterpret_cast<const ClipRectList*>(serializedClip);
+        ASSERT_EQ(2, clipRectList->rectList.getTransformedRectanglesCount());
+        EXPECT_EQ(serializedClip, area.serializeClip(allocator))
+                << "Requery of clip on unmodified ClipArea must return same pointer.";
+    }
+
+    // region
+    SkPath circlePath;
+    circlePath.addCircle(100, 100, 100);
+    area.clipPathWithTransform(circlePath, &Matrix4::identity(), SkRegion::kReplace_Op);
+    {
+        auto serializedClip = area.serializeClip(allocator);
+        ASSERT_NE(nullptr, serializedClip);
+        ASSERT_EQ(ClipMode::Region, serializedClip->mode);
+        auto clipRegion = reinterpret_cast<const ClipRegion*>(serializedClip);
+        ASSERT_EQ(SkIRect::MakeWH(200, 200), clipRegion->region.getBounds())
+                << "Clip region should be 200x200";
+        EXPECT_EQ(serializedClip, area.serializeClip(allocator))
+                << "Requery of clip on unmodified ClipArea must return same pointer.";
+    }
 }
+
+TEST(ClipArea, serializeIntersectedClip) {
+    ClipArea area(createClipArea());
+    LinearAllocator allocator;
+
+    // simple state;
+    EXPECT_EQ(nullptr, area.serializeIntersectedClip(allocator, nullptr, Matrix4::identity()));
+    area.setClip(0, 0, 200, 200);
+    {
+        auto origRectClip = area.serializeClip(allocator);
+        ASSERT_NE(nullptr, origRectClip);
+        EXPECT_EQ(origRectClip, area.serializeIntersectedClip(allocator, nullptr, Matrix4::identity()));
+    }
+
+    // rect
+    {
+        ClipRect recordedClip(Rect(100, 100));
+        Matrix4 translateScale;
+        translateScale.loadTranslate(100, 100, 0);
+        translateScale.scale(2, 3, 1);
+        auto resolvedClip = area.serializeIntersectedClip(allocator, &recordedClip, translateScale);
+        ASSERT_NE(nullptr, resolvedClip);
+        ASSERT_EQ(ClipMode::Rectangle, resolvedClip->mode);
+        EXPECT_EQ(Rect(100, 100, 200, 200),
+                reinterpret_cast<const ClipRect*>(resolvedClip)->rect);
+
+        EXPECT_EQ(resolvedClip, area.serializeIntersectedClip(allocator, &recordedClip, translateScale))
+                << "Must return previous serialization, since input is same";
+
+        ClipRect recordedClip2(Rect(100, 100));
+        EXPECT_NE(resolvedClip, area.serializeIntersectedClip(allocator, &recordedClip2, translateScale))
+                << "Shouldn't return previous serialization, since matrix location is different";
+    }
+
+    // rect list
+    Matrix4 rotate;
+    rotate.loadRotate(2.0f);
+    area.clipRectWithTransform(Rect(200, 200), &rotate, SkRegion::kIntersect_Op);
+    {
+        ClipRect recordedClip(Rect(100, 100));
+        auto resolvedClip = area.serializeIntersectedClip(allocator, &recordedClip, Matrix4::identity());
+        ASSERT_NE(nullptr, resolvedClip);
+        ASSERT_EQ(ClipMode::RectangleList, resolvedClip->mode);
+        auto clipRectList = reinterpret_cast<const ClipRectList*>(resolvedClip);
+        EXPECT_EQ(2, clipRectList->rectList.getTransformedRectanglesCount());
+    }
+
+    // region
+    SkPath circlePath;
+    circlePath.addCircle(100, 100, 100);
+    area.clipPathWithTransform(circlePath, &Matrix4::identity(), SkRegion::kReplace_Op);
+    {
+        SkPath ovalPath;
+        ovalPath.addOval(SkRect::MakeLTRB(50, 0, 150, 200));
+
+        ClipRegion recordedClip;
+        recordedClip.region.setPath(ovalPath, SkRegion(SkIRect::MakeWH(200, 200)));
+
+        Matrix4 translate10x20;
+        translate10x20.loadTranslate(10, 20, 0);
+        auto resolvedClip = area.serializeIntersectedClip(allocator, &recordedClip,
+                translate10x20); // Note: only translate for now, others not handled correctly
+        ASSERT_NE(nullptr, resolvedClip);
+        ASSERT_EQ(ClipMode::Region, resolvedClip->mode);
+        auto clipRegion = reinterpret_cast<const ClipRegion*>(resolvedClip);
+        EXPECT_EQ(SkIRect::MakeLTRB(60, 20, 160, 200), clipRegion->region.getBounds());
+    }
 }
+
+} // namespace uirenderer
+} // namespace android
diff --git a/libs/hwui/tests/unit/LinearAllocatorTests.cpp b/libs/hwui/tests/unit/LinearAllocatorTests.cpp
index 78d65dd..5c44290 100644
--- a/libs/hwui/tests/unit/LinearAllocatorTests.cpp
+++ b/libs/hwui/tests/unit/LinearAllocatorTests.cpp
@@ -27,7 +27,7 @@
     int two = 2;
 };
 
-TEST(LinearAllocator, alloc) {
+TEST(LinearAllocator, create) {
     LinearAllocator la;
     EXPECT_EQ(0u, la.usedSize());
     la.alloc(64);
@@ -35,7 +35,7 @@
     // so the usedSize isn't strictly defined
     EXPECT_LE(64u, la.usedSize());
     EXPECT_GT(80u, la.usedSize());
-    auto pair = la.alloc<SimplePair>();
+    auto pair = la.create<SimplePair>();
     EXPECT_LE(64u + sizeof(SimplePair), la.usedSize());
     EXPECT_GT(80u + sizeof(SimplePair), la.usedSize());
     EXPECT_EQ(1, pair->one);
@@ -47,8 +47,8 @@
     {
         LinearAllocator la;
         for (int i = 0; i < 5; i++) {
-            la.alloc<TestUtils::SignalingDtor>()->setSignal(destroyed + i);
-            la.alloc<SimplePair>();
+            la.create<TestUtils::SignalingDtor>()->setSignal(destroyed + i);
+            la.create<SimplePair>();
         }
         la.alloc(100);
         for (int i = 0; i < 5; i++) {
@@ -75,7 +75,7 @@
         la.rewindIfLastAlloc(addr, 100);
         EXPECT_GT(16u, la.usedSize());
         size_t emptySize = la.usedSize();
-        auto sigdtor = la.alloc<TestUtils::SignalingDtor>();
+        auto sigdtor = la.create<TestUtils::SignalingDtor>();
         sigdtor->setSignal(&destroyed);
         EXPECT_EQ(0, destroyed);
         EXPECT_LE(emptySize, la.usedSize());
diff --git a/libs/hwui/tests/unit/OpReordererTests.cpp b/libs/hwui/tests/unit/OpReordererTests.cpp
index b28e436..66dccb4 100644
--- a/libs/hwui/tests/unit/OpReordererTests.cpp
+++ b/libs/hwui/tests/unit/OpReordererTests.cpp
@@ -64,14 +64,14 @@
         ADD_FAILURE() << "Layer updates not expected in this test";
     }
     virtual void startFrame(uint32_t width, uint32_t height, const Rect& repaintRect) {}
-    virtual void endFrame() {}
+    virtual void endFrame(const Rect& repaintRect) {}
 
     // define virtual defaults for single draw methods
 #define X(Type) \
     virtual void on##Type(const Type&, const BakedOpState&) { \
         ADD_FAILURE() << #Type " not expected in this test"; \
     }
-    MAP_OPS(X)
+    MAP_RENDERABLE_OPS(X)
 #undef X
 
     // define virtual defaults for merged draw methods
@@ -79,7 +79,7 @@
     virtual void onMerged##Type##s(const MergedBakedOpList& opList) { \
         ADD_FAILURE() << "Merged " #Type "s not expected in this test"; \
     }
-    MAP_MERGED_OPS(X)
+    MAP_MERGEABLE_OPS(X)
 #undef X
 
     int getIndex() { return mIndex; }
@@ -99,7 +99,7 @@
     static void on##Type(TestRendererBase& renderer, const Type& op, const BakedOpState& state) { \
         renderer.on##Type(op, state); \
     }
-    MAP_OPS(X);
+    MAP_RENDERABLE_OPS(X);
 #undef X
 
     // define merged op methods, which redirect to TestRendererBase
@@ -107,7 +107,7 @@
     static void onMerged##Type##s(TestRendererBase& renderer, const MergedBakedOpList& opList) { \
         renderer.onMerged##Type##s(opList); \
     }
-    MAP_MERGED_OPS(X);
+    MAP_MERGEABLE_OPS(X);
 #undef X
 };
 
@@ -127,7 +127,7 @@
         void onBitmapOp(const BitmapOp& op, const BakedOpState& state) override {
             EXPECT_EQ(2, mIndex++);
         }
-        void endFrame() override {
+        void endFrame(const Rect& repaintRect) override {
             EXPECT_EQ(3, mIndex++);
         }
     };
@@ -327,7 +327,7 @@
     public:
         void onTextureLayerOp(const TextureLayerOp& op, const BakedOpState& state) override {
             EXPECT_EQ(0, mIndex++);
-            EXPECT_EQ(Rect(50, 50, 150, 150), state.computedState.clipRect);
+            EXPECT_EQ(Rect(50, 50, 150, 150), state.computedState.clipRect());
             EXPECT_EQ(Rect(50, 50, 105, 105), state.computedState.clippedBounds);
 
             Matrix4 expected;
@@ -405,7 +405,7 @@
         void onBitmapOp(const BitmapOp& op, const BakedOpState& state) override {
             EXPECT_EQ(0, mIndex++);
             EXPECT_EQ(Rect(10, 20, 30, 40), state.computedState.clippedBounds);
-            EXPECT_EQ(Rect(10, 20, 30, 40), state.computedState.clipRect);
+            EXPECT_EQ(Rect(10, 20, 30, 40), state.computedState.clipRect());
             EXPECT_TRUE(state.computedState.transform.isIdentity());
         }
     };
@@ -439,7 +439,7 @@
             EXPECT_EQ(1, mIndex++);
             EXPECT_EQ(Rect(10, 10, 190, 190), op.unmappedBounds);
             EXPECT_EQ(Rect(180, 180), state.computedState.clippedBounds);
-            EXPECT_EQ(Rect(180, 180), state.computedState.clipRect);
+            EXPECT_EQ(Rect(180, 180), state.computedState.clipRect());
 
             Matrix4 expectedTransform;
             expectedTransform.loadTranslate(-10, -10, 0);
@@ -448,7 +448,7 @@
         void onLayerOp(const LayerOp& op, const BakedOpState& state) override {
             EXPECT_EQ(3, mIndex++);
             EXPECT_EQ(Rect(10, 10, 190, 190), state.computedState.clippedBounds);
-            EXPECT_EQ(Rect(200, 200), state.computedState.clipRect);
+            EXPECT_EQ(Rect(200, 200), state.computedState.clipRect());
             EXPECT_TRUE(state.computedState.transform.isIdentity());
         }
     };
@@ -494,7 +494,7 @@
         void startFrame(uint32_t width, uint32_t height, const Rect& repaintRect) override {
             EXPECT_EQ(7, mIndex++);
         }
-        void endFrame() override {
+        void endFrame(const Rect& repaintRect) override {
             EXPECT_EQ(9, mIndex++);
         }
         void onRectOp(const RectOp& op, const BakedOpState& state) override {
@@ -574,7 +574,7 @@
             EXPECT_TRUE(state.computedState.transform.isIdentity())
                     << "Transform should be reset within layer";
 
-            EXPECT_EQ(state.computedState.clipRect, Rect(25, 25, 75, 75))
+            EXPECT_EQ(Rect(25, 25, 75, 75), state.computedState.clipRect())
                     << "Damage rect should be used to clip layer content";
         }
         void endLayer() override {
@@ -586,7 +586,7 @@
         void onLayerOp(const LayerOp& op, const BakedOpState& state) override {
             EXPECT_EQ(4, mIndex++);
         }
-        void endFrame() override {
+        void endFrame(const Rect& repaintRect) override {
             EXPECT_EQ(5, mIndex++);
         }
     };
@@ -675,7 +675,7 @@
                 EXPECT_EQ(200u, layer->viewportHeight);
             } else { ADD_FAILURE(); }
         }
-        void endFrame() override {
+        void endFrame(const Rect& repaintRect) override {
             EXPECT_EQ(12, mIndex++);
         }
     };
diff --git a/libs/hwui/tests/unit/RecordingCanvasTests.cpp b/libs/hwui/tests/unit/RecordingCanvasTests.cpp
index 08f927c..a63cb18 100644
--- a/libs/hwui/tests/unit/RecordingCanvasTests.cpp
+++ b/libs/hwui/tests/unit/RecordingCanvasTests.cpp
@@ -33,6 +33,14 @@
     }
 }
 
+#define EXPECT_CLIP_RECT(expRect, clipStatePtr) \
+    EXPECT_NE(nullptr, (clipStatePtr)) << "Op is unclipped"; \
+    if ((clipStatePtr)->mode == ClipMode::Rectangle) { \
+        EXPECT_EQ((expRect), reinterpret_cast<const ClipRect*>(clipStatePtr)->rect); \
+    } else { \
+        ADD_FAILURE() << "ClipState not a rect"; \
+    }
+
 TEST(RecordingCanvas, emptyPlayback) {
     auto dl = TestUtils::createDisplayList<RecordingCanvas>(100, 200, [](RecordingCanvas& canvas) {
         canvas.save(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
@@ -41,6 +49,22 @@
     playbackOps(*dl, [](const RecordedOp& op) { ADD_FAILURE(); });
 }
 
+TEST(RecordingCanvas, clipRect) {
+    auto dl = TestUtils::createDisplayList<RecordingCanvas>(100, 100, [](RecordingCanvas& canvas) {
+        canvas.save(SkCanvas::kMatrixClip_SaveFlag);
+        canvas.clipRect(0, 0, 100, 100, SkRegion::kIntersect_Op);
+        canvas.drawRect(0, 0, 50, 50, SkPaint());
+        canvas.drawRect(50, 50, 100, 100, SkPaint());
+        canvas.restore();
+    });
+
+    ASSERT_EQ(2u, dl->getOps().size()) << "Must be exactly two ops";
+    EXPECT_CLIP_RECT(Rect(100, 100), dl->getOps()[0]->localClip);
+    EXPECT_CLIP_RECT(Rect(100, 100), dl->getOps()[1]->localClip);
+    EXPECT_EQ(dl->getOps()[0]->localClip, dl->getOps()[1]->localClip)
+            << "Clip should be serialized once";
+}
+
 TEST(RecordingCanvas, drawLines) {
     auto dl = TestUtils::createDisplayList<RecordingCanvas>(100, 200, [](RecordingCanvas& canvas) {
         SkPaint paint;
@@ -66,7 +90,7 @@
     ASSERT_EQ(1u, dl->getOps().size()) << "Must be exactly one op";
     auto op = *(dl->getOps()[0]);
     ASSERT_EQ(RecordedOpId::RectOp, op.opId);
-    EXPECT_EQ(Rect(100, 200), op.localClipRect);
+    EXPECT_EQ(nullptr, op.localClip);
     EXPECT_EQ(Rect(10, 20, 90, 180), op.unmappedBounds);
 }
 
@@ -83,7 +107,7 @@
     playbackOps(*dl, [&count](const RecordedOp& op) {
         count++;
         ASSERT_EQ(RecordedOpId::TextOp, op.opId);
-        EXPECT_EQ(Rect(200, 200), op.localClipRect);
+        EXPECT_EQ(nullptr, op.localClip);
         EXPECT_TRUE(op.localMatrix.isIdentity());
         EXPECT_TRUE(op.unmappedBounds.contains(25, 15, 50, 25))
                 << "Op expected to be 25+ pixels wide, 10+ pixels tall";
@@ -185,7 +209,7 @@
             ASSERT_NE(nullptr, op.paint);
             EXPECT_EQ(SK_ColorBLUE, op.paint->getColor());
             EXPECT_EQ(Rect(100, 200), op.unmappedBounds);
-            EXPECT_EQ(Rect(100, 200), op.localClipRect);
+            EXPECT_EQ(nullptr, op.localClip);
 
             Matrix4 expectedMatrix;
             expectedMatrix.loadIdentity();
@@ -194,7 +218,7 @@
             ASSERT_EQ(RecordedOpId::BitmapOp, op.opId);
             EXPECT_EQ(nullptr, op.paint);
             EXPECT_EQ(Rect(25, 25), op.unmappedBounds);
-            EXPECT_EQ(Rect(100, 200), op.localClipRect);
+            EXPECT_EQ(nullptr, op.localClip);
 
             Matrix4 expectedMatrix;
             expectedMatrix.loadTranslate(25, 25, 0);
@@ -219,12 +243,12 @@
         case 0:
             EXPECT_EQ(RecordedOpId::BeginLayerOp, op.opId);
             EXPECT_EQ(Rect(10, 20, 190, 180), op.unmappedBounds);
-            EXPECT_EQ(Rect(200, 200), op.localClipRect);
+            EXPECT_EQ(nullptr, op.localClip);
             EXPECT_TRUE(op.localMatrix.isIdentity());
             break;
         case 1:
             EXPECT_EQ(RecordedOpId::RectOp, op.opId);
-            EXPECT_EQ(Rect(180, 160), op.localClipRect);
+            EXPECT_CLIP_RECT(Rect(180, 160), op.localClip);
             EXPECT_EQ(Rect(10, 20, 190, 180), op.unmappedBounds);
             expectedMatrix.loadTranslate(-10, -20, 0);
             EXPECT_MATRIX_APPROX_EQ(expectedMatrix, op.localMatrix);
@@ -254,8 +278,8 @@
         if (count++ == 1) {
             Matrix4 expectedMatrix;
             EXPECT_EQ(RecordedOpId::RectOp, op.opId);
-            EXPECT_EQ(Rect(100, 100), op.localClipRect) << "Recorded clip rect should be"
-                    " intersection of viewport and saveLayer bounds, in layer space";
+            EXPECT_CLIP_RECT(Rect(100, 100), op.localClip) // Recorded clip rect should be
+            // intersection of viewport and saveLayer bounds, in layer space;
             EXPECT_EQ(Rect(400, 400), op.unmappedBounds);
             expectedMatrix.loadTranslate(-100, -100, 0);
             EXPECT_MATRIX_APPROX_EQ(expectedMatrix, op.localMatrix);
@@ -281,7 +305,7 @@
     playbackOps(*dl, [&count](const RecordedOp& op) {
         if (count++ == 1) {
             EXPECT_EQ(RecordedOpId::RectOp, op.opId);
-            EXPECT_EQ(Rect(100, 100), op.localClipRect);
+            EXPECT_CLIP_RECT(Rect(100, 100), op.localClip);
             EXPECT_EQ(Rect(100, 100), op.unmappedBounds);
             EXPECT_MATRIX_APPROX_EQ(Matrix4::identity(), op.localMatrix)
                     << "Recorded op shouldn't see any canvas transform before the saveLayer";
@@ -312,7 +336,16 @@
 
             // ...and get about 58.6, 58.6, 341.4 341.4, because the bounds are clipped by
             // the parent 200x200 viewport, but prior to rotation
-            EXPECT_RECT_APPROX_EQ(Rect(58.57864, 58.57864, 341.42136, 341.42136), op.localClipRect);
+            ASSERT_NE(nullptr, op.localClip);
+            ASSERT_EQ(ClipMode::Rectangle, op.localClip->mode);
+            // NOTE: this check relies on saveLayer altering the clip post-viewport init. This
+            // causes the clip to be recorded by contained draw commands, though it's not necessary
+            // since the same clip will be computed at draw time. If such a change is made, this
+            // check could be done at record time by querying the clip, or the clip could be altered
+            // slightly so that it is serialized.
+            EXPECT_RECT_APPROX_EQ(Rect(58.57864, 58.57864, 341.42136, 341.42136),
+                    (reinterpret_cast<const ClipRect*>(op.localClip))->rect);
+
             EXPECT_EQ(Rect(400, 400), op.unmappedBounds);
             expectedMatrix.loadIdentity();
             EXPECT_MATRIX_APPROX_EQ(expectedMatrix, op.localMatrix);
diff --git a/libs/hwui/utils/LinearAllocator.h b/libs/hwui/utils/LinearAllocator.h
index e1c6f6c..dcbc0dd 100644
--- a/libs/hwui/utils/LinearAllocator.h
+++ b/libs/hwui/utils/LinearAllocator.h
@@ -56,12 +56,12 @@
     void* alloc(size_t size);
 
     /**
-     * Allocates an instance of the template type with the default constructor
+     * Allocates an instance of the template type with the given construction parameters
      * and adds it to the automatic destruction list.
      */
-    template<class T>
-    T* alloc() {
-        T* ret = new (*this) T;
+    template<class T, typename... Params>
+    T* create(Params... params) {
+        T* ret = new (*this) T(params...);
         autoDestroy(ret);
         return ret;
     }
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index bb4f7d9..a810ff1 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -97,9 +97,10 @@
     /** Maximum value for sample rate */
     private static final int SAMPLE_RATE_HZ_MAX = 192000;
 
-    // FCC_8
-    /** Maximum value for AudioTrack channel count */
-    private static final int CHANNEL_COUNT_MAX = 8;
+    /** Maximum value for AudioTrack channel count
+     * @hide public for MediaCode only, do not un-hide or change to a numeric literal
+     */
+    public static final int CHANNEL_COUNT_MAX = native_get_FCC_8();
 
     /** indicates AudioTrack state is stopped */
     public static final int PLAYSTATE_STOPPED = 1;  // matches SL_PLAYSTATE_STOPPED
@@ -2583,6 +2584,7 @@
     private native final int native_getRoutedDeviceId();
     private native final void native_enableDeviceCallback();
     private native final void native_disableDeviceCallback();
+    static private native int native_get_FCC_8();
 
     //---------------------------------------------------------
     // Utility methods
diff --git a/media/java/android/media/MediaCodecInfo.java b/media/java/android/media/MediaCodecInfo.java
index e6bc8f1..9bcb5e3 100644
--- a/media/java/android/media/MediaCodecInfo.java
+++ b/media/java/android/media/MediaCodecInfo.java
@@ -907,7 +907,7 @@
             } else if (mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_RAW)) {
                 sampleRateRange = Range.create(1, 96000);
                 bitRates = Range.create(1, 10000000);
-                maxChannels = 8;
+                maxChannels = AudioTrack.CHANNEL_COUNT_MAX;
             } else if (mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_FLAC)) {
                 sampleRateRange = Range.create(1, 655350);
                 // lossless codec, so bitrate is ignored
diff --git a/media/java/android/media/MediaInserter.java b/media/java/android/media/MediaInserter.java
index 41b369d..dd06921 100644
--- a/media/java/android/media/MediaInserter.java
+++ b/media/java/android/media/MediaInserter.java
@@ -16,8 +16,8 @@
 
 package android.media;
 
+import android.content.ContentProviderClient;
 import android.content.ContentValues;
-import android.content.IContentProvider;
 import android.net.Uri;
 import android.os.RemoteException;
 
@@ -37,13 +37,11 @@
     private final HashMap<Uri, List<ContentValues>> mPriorityRowMap =
             new HashMap<Uri, List<ContentValues>>();
 
-    private final IContentProvider mProvider;
-    private final String mPackageName;
+    private final ContentProviderClient mProvider;
     private final int mBufferSizePerUri;
 
-    public MediaInserter(IContentProvider provider, String packageName, int bufferSizePerUri) {
+    public MediaInserter(ContentProviderClient provider, int bufferSizePerUri) {
         mProvider = provider;
-        mPackageName = packageName;
         mBufferSizePerUri = bufferSizePerUri;
     }
 
@@ -90,7 +88,7 @@
         if (!list.isEmpty()) {
             ContentValues[] valuesArray = new ContentValues[list.size()];
             valuesArray = list.toArray(valuesArray);
-            mProvider.bulkInsert(mPackageName, tableUri, valuesArray);
+            mProvider.bulkInsert(tableUri, valuesArray);
             list.clear();
         }
     }
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java
index 9ea6722..96c616b 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -16,14 +16,10 @@
 
 package android.media;
 
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
+import android.content.ContentProviderClient;
 import android.content.ContentUris;
 import android.content.ContentValues;
 import android.content.Context;
-import android.content.IContentProvider;
 import android.database.Cursor;
 import android.database.SQLException;
 import android.drm.DrmManagerClient;
@@ -50,6 +46,12 @@
 import android.util.Log;
 import android.util.Xml;
 
+import dalvik.system.CloseGuard;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileDescriptor;
@@ -61,6 +63,7 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Locale;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * Internal service helper that no-one should use directly.
@@ -107,8 +110,7 @@
  *
  * {@hide}
  */
-public class MediaScanner
-{
+public class MediaScanner implements AutoCloseable {
     static {
         System.loadLibrary("media_jni");
         native_init();
@@ -302,21 +304,23 @@
     };
 
     private long mNativeContext;
-    private Context mContext;
-    private String mPackageName;
-    private IContentProvider mMediaProvider;
-    private Uri mAudioUri;
-    private Uri mVideoUri;
-    private Uri mImagesUri;
-    private Uri mThumbsUri;
-    private Uri mPlaylistsUri;
-    private Uri mFilesUri;
-    private Uri mFilesUriNoNotify;
-    private boolean mProcessPlaylists, mProcessGenres;
+    private final Context mContext;
+    private final String mPackageName;
+    private final String mVolumeName;
+    private final ContentProviderClient mMediaProvider;
+    private final Uri mAudioUri;
+    private final Uri mVideoUri;
+    private final Uri mImagesUri;
+    private final Uri mThumbsUri;
+    private final Uri mPlaylistsUri;
+    private final Uri mFilesUri;
+    private final Uri mFilesUriNoNotify;
+    private final boolean mProcessPlaylists;
+    private final boolean mProcessGenres;
     private int mMtpObjectHandle;
 
-    private final String mExternalStoragePath;
-    private final boolean mExternalIsEmulated;
+    private final AtomicBoolean mClosed = new AtomicBoolean();
+    private final CloseGuard mCloseGuard = CloseGuard.get();
 
     /** whether to use bulk inserts or individual inserts for each item */
     private static final boolean ENABLE_BULK_INSERTS = true;
@@ -345,10 +349,6 @@
      */
     private static final String DEFAULT_RINGTONE_PROPERTY_PREFIX = "ro.config.";
 
-    // set to true if file path comparisons should be case insensitive.
-    // this should be set when scanning files on a case insensitive file system.
-    private boolean mCaseInsensitivePaths;
-
     private final BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options();
 
     private static class FileEntry {
@@ -378,26 +378,59 @@
         int bestmatchlevel;
     }
 
-    private ArrayList<PlaylistEntry> mPlaylistEntries = new ArrayList<PlaylistEntry>();
+    private final ArrayList<PlaylistEntry> mPlaylistEntries = new ArrayList<>();
+    private final ArrayList<FileEntry> mPlayLists = new ArrayList<>();
 
     private MediaInserter mMediaInserter;
 
-    private ArrayList<FileEntry> mPlayLists;
-
     private DrmManagerClient mDrmManagerClient = null;
 
-    public MediaScanner(Context c) {
+    public MediaScanner(Context c, String volumeName) {
         native_setup();
         mContext = c;
         mPackageName = c.getPackageName();
+        mVolumeName = volumeName;
+
         mBitmapOptions.inSampleSize = 1;
         mBitmapOptions.inJustDecodeBounds = true;
 
         setDefaultRingtoneFileNames();
 
-        mExternalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
-        mExternalIsEmulated = Environment.isExternalStorageEmulated();
-        //mClient.testGenreNameConverter();
+        mMediaProvider = mContext.getContentResolver()
+                .acquireContentProviderClient(MediaStore.AUTHORITY);
+
+        mAudioUri = Audio.Media.getContentUri(volumeName);
+        mVideoUri = Video.Media.getContentUri(volumeName);
+        mImagesUri = Images.Media.getContentUri(volumeName);
+        mThumbsUri = Images.Thumbnails.getContentUri(volumeName);
+        mFilesUri = Files.getContentUri(volumeName);
+        mFilesUriNoNotify = mFilesUri.buildUpon().appendQueryParameter("nonotify", "1").build();
+
+        if (!volumeName.equals("internal")) {
+            // we only support playlists on external media
+            mProcessPlaylists = true;
+            mProcessGenres = true;
+            mPlaylistsUri = Playlists.getContentUri(volumeName);
+        } else {
+            mProcessPlaylists = false;
+            mProcessGenres = false;
+            mPlaylistsUri = null;
+        }
+
+        final Locale locale = mContext.getResources().getConfiguration().locale;
+        if (locale != null) {
+            String language = locale.getLanguage();
+            String country = locale.getCountry();
+            if (language != null) {
+                if (country != null) {
+                    setLocale(language + "_" + country);
+                } else {
+                    setLocale(language);
+                }
+            }
+        }
+
+        mCloseGuard.open("close");
     }
 
     private void setDefaultRingtoneFileNames() {
@@ -956,7 +989,7 @@
                     if (inserter != null) {
                         inserter.flushAll();
                     }
-                    result = mMediaProvider.insert(mPackageName, tableUri, values);
+                    result = mMediaProvider.insert(tableUri, values);
                 } else if (entry.mFormat == MtpConstants.FORMAT_ASSOCIATION) {
                     inserter.insertwithPriority(tableUri, values);
                 } else {
@@ -988,7 +1021,7 @@
                     }
                     values.put(FileColumns.MEDIA_TYPE, mediaType);
                 }
-                mMediaProvider.update(mPackageName, result, values, null, null);
+                mMediaProvider.update(result, values, null, null);
             }
 
             if(needToSetSettings) {
@@ -1055,11 +1088,7 @@
         String where = null;
         String[] selectionArgs = null;
 
-        if (mPlayLists == null) {
-            mPlayLists = new ArrayList<FileEntry>();
-        } else {
-            mPlayLists.clear();
-        }
+        mPlayLists.clear();
 
         if (filePath != null) {
             // query for only one file
@@ -1077,8 +1106,7 @@
         // filesystem is mounted and unmounted while the scanner is running).
         Uri.Builder builder = mFilesUri.buildUpon();
         builder.appendQueryParameter(MediaStore.PARAM_DELETE_DATA, "false");
-        MediaBulkDeleter deleter = new MediaBulkDeleter(mMediaProvider, mPackageName,
-                builder.build());
+        MediaBulkDeleter deleter = new MediaBulkDeleter(mMediaProvider, builder.build());
 
         // Build the list of files from the content provider
         try {
@@ -1097,7 +1125,7 @@
                         c.close();
                         c = null;
                     }
-                    c = mMediaProvider.query(mPackageName, limitUri, FILES_PRESCAN_PROJECTION,
+                    c = mMediaProvider.query(limitUri, FILES_PRESCAN_PROJECTION,
                             where, selectionArgs, MediaStore.Files.FileColumns._ID, null);
                     if (c == null) {
                         break;
@@ -1138,8 +1166,7 @@
                                     if (path.toLowerCase(Locale.US).endsWith("/.nomedia")) {
                                         deleter.flush();
                                         String parent = new File(path).getParent();
-                                        mMediaProvider.call(mPackageName, MediaStore.UNHIDE_CALL,
-                                                parent, null);
+                                        mMediaProvider.call(MediaStore.UNHIDE_CALL, parent, null);
                                     }
                                 }
                             }
@@ -1157,7 +1184,7 @@
 
         // compute original size of images
         mOriginalCount = 0;
-        c = mMediaProvider.query(mPackageName, mImagesUri, ID_PROJECTION, null, null, null, null);
+        c = mMediaProvider.query(mImagesUri, ID_PROJECTION, null, null, null, null);
         if (c != null) {
             mOriginalCount = c.getCount();
             c.close();
@@ -1189,7 +1216,6 @@
 
         try {
             c = mMediaProvider.query(
-                    mPackageName,
                     mThumbsUri,
                     new String [] { "_data" },
                     null,
@@ -1225,13 +1251,11 @@
     static class MediaBulkDeleter {
         StringBuilder whereClause = new StringBuilder();
         ArrayList<String> whereArgs = new ArrayList<String>(100);
-        final IContentProvider mProvider;
-        final String mPackageName;
+        final ContentProviderClient mProvider;
         final Uri mBaseUri;
 
-        public MediaBulkDeleter(IContentProvider provider, String packageName, Uri baseUri) {
+        public MediaBulkDeleter(ContentProviderClient provider, Uri baseUri) {
             mProvider = provider;
-            mPackageName = packageName;
             mBaseUri = baseUri;
         }
 
@@ -1250,7 +1274,7 @@
             if (size > 0) {
                 String [] foo = new String [size];
                 foo = whereArgs.toArray(foo);
-                int numrows = mProvider.delete(mPackageName, mBaseUri,
+                int numrows = mProvider.delete(mBaseUri,
                         MediaStore.MediaColumns._ID + " IN (" +
                         whereClause.toString() + ")", foo);
                 //Log.i("@@@@@@@@@", "rows deleted: " + numrows);
@@ -1271,48 +1295,26 @@
             pruneDeadThumbnailFiles();
 
         // allow GC to clean up
-        mPlayLists = null;
-        mMediaProvider = null;
+        mPlayLists.clear();
     }
 
     private void releaseResources() {
         // release the DrmManagerClient resources
         if (mDrmManagerClient != null) {
-            mDrmManagerClient.release();
+            mDrmManagerClient.close();
             mDrmManagerClient = null;
         }
     }
 
-    private void initialize(String volumeName) {
-        mMediaProvider = mContext.getContentResolver().acquireProvider("media");
-
-        mAudioUri = Audio.Media.getContentUri(volumeName);
-        mVideoUri = Video.Media.getContentUri(volumeName);
-        mImagesUri = Images.Media.getContentUri(volumeName);
-        mThumbsUri = Images.Thumbnails.getContentUri(volumeName);
-        mFilesUri = Files.getContentUri(volumeName);
-        mFilesUriNoNotify = mFilesUri.buildUpon().appendQueryParameter("nonotify", "1").build();
-
-        if (!volumeName.equals("internal")) {
-            // we only support playlists on external media
-            mProcessPlaylists = true;
-            mProcessGenres = true;
-            mPlaylistsUri = Playlists.getContentUri(volumeName);
-
-            mCaseInsensitivePaths = true;
-        }
-    }
-
-    public void scanDirectories(String[] directories, String volumeName) {
+    public void scanDirectories(String[] directories) {
         try {
             long start = System.currentTimeMillis();
-            initialize(volumeName);
             prescan(null, true);
             long prescan = System.currentTimeMillis();
 
             if (ENABLE_BULK_INSERTS) {
                 // create MediaInserter for bulk inserts
-                mMediaInserter = new MediaInserter(mMediaProvider, mPackageName, 500);
+                mMediaInserter = new MediaInserter(mMediaProvider, 500);
             }
 
             for (int i = 0; i < directories.length; i++) {
@@ -1349,9 +1351,8 @@
     }
 
     // this function is used to scan a single file
-    public Uri scanSingleFile(String path, String volumeName, String mimeType) {
+    public Uri scanSingleFile(String path, String mimeType) {
         try {
-            initialize(volumeName);
             prescan(path, true);
 
             File file = new File(path);
@@ -1464,8 +1465,7 @@
         return isNoMediaFile(path);
     }
 
-    public void scanMtpFile(String path, String volumeName, int objectHandle, int format) {
-        initialize(volumeName);
+    public void scanMtpFile(String path, int objectHandle, int format) {
         MediaFile.MediaFileType mediaFileType = MediaFile.getFileType(path);
         int fileType = (mediaFileType == null ? 0 : mediaFileType.fileType);
         File file = new File(path);
@@ -1481,7 +1481,7 @@
             values.put(Files.FileColumns.DATE_MODIFIED, lastModifiedSeconds);
             try {
                 String[] whereArgs = new String[] {  Integer.toString(objectHandle) };
-                mMediaProvider.update(mPackageName, Files.getMtpObjectsUri(volumeName), values,
+                mMediaProvider.update(Files.getMtpObjectsUri(mVolumeName), values,
                         "_id=?", whereArgs);
             } catch (RemoteException e) {
                 Log.e(TAG, "RemoteException in scanMtpFile", e);
@@ -1498,7 +1498,7 @@
 
                 FileEntry entry = makeEntryFor(path);
                 if (entry != null) {
-                    fileList = mMediaProvider.query(mPackageName, mFilesUri,
+                    fileList = mMediaProvider.query(mFilesUri,
                             FILES_PRESCAN_PROJECTION, null, null, null, null);
                     processPlayList(entry, fileList);
                 }
@@ -1529,7 +1529,7 @@
         try {
             where = Files.FileColumns.DATA + "=?";
             selectionArgs = new String[] { path };
-            c = mMediaProvider.query(mPackageName, mFilesUriNoNotify, FILES_PRESCAN_PROJECTION,
+            c = mMediaProvider.query(mFilesUriNoNotify, FILES_PRESCAN_PROJECTION,
                     where, selectionArgs, null, null);
             if (c.moveToFirst()) {
                 long rowId = c.getLong(FILES_PRESCAN_ID_COLUMN_INDEX);
@@ -1641,7 +1641,7 @@
                     values.clear();
                     values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(index));
                     values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, Long.valueOf(entry.bestmatchid));
-                    mMediaProvider.insert(mPackageName, playlistUri, values);
+                    mMediaProvider.insert(playlistUri, values);
                     index++;
                 } catch (RemoteException e) {
                     Log.e(TAG, "RemoteException in MediaScanner.processCachedPlaylist()", e);
@@ -1806,16 +1806,16 @@
 
         if (rowId == 0) {
             values.put(MediaStore.Audio.Playlists.DATA, path);
-            uri = mMediaProvider.insert(mPackageName, mPlaylistsUri, values);
+            uri = mMediaProvider.insert(mPlaylistsUri, values);
             rowId = ContentUris.parseId(uri);
             membersUri = Uri.withAppendedPath(uri, Playlists.Members.CONTENT_DIRECTORY);
         } else {
             uri = ContentUris.withAppendedId(mPlaylistsUri, rowId);
-            mMediaProvider.update(mPackageName, uri, values, null, null);
+            mMediaProvider.update(uri, values, null, null);
 
             // delete members of existing playlist
             membersUri = Uri.withAppendedPath(uri, Playlists.Members.CONTENT_DIRECTORY);
-            mMediaProvider.delete(mPackageName, membersUri, null, null);
+            mMediaProvider.delete(membersUri, null, null);
         }
 
         String playListDirectory = path.substring(0, lastSlash + 1);
@@ -1837,7 +1837,7 @@
         try {
             // use the files uri and projection because we need the format column,
             // but restrict the query to just audio files
-            fileList = mMediaProvider.query(mPackageName, mFilesUri, FILES_PRESCAN_PROJECTION,
+            fileList = mMediaProvider.query(mFilesUri, FILES_PRESCAN_PROJECTION,
                     "media_type=2", null, null, null);
             while (iterator.hasNext()) {
                 FileEntry entry = iterator.next();
@@ -1856,7 +1856,7 @@
 
     private native void processDirectory(String path, MediaScannerClient client);
     private native void processFile(String path, String mimeType, MediaScannerClient client);
-    public native void setLocale(String locale);
+    private native void setLocale(String locale);
 
     public native byte[] extractAlbumArt(FileDescriptor fd);
 
@@ -1864,19 +1864,22 @@
     private native final void native_setup();
     private native final void native_finalize();
 
-    /**
-     * Releases resources associated with this MediaScanner object.
-     * It is considered good practice to call this method when
-     * one is done using the MediaScanner object. After this method
-     * is called, the MediaScanner object can no longer be used.
-     */
-    public void release() {
-        native_finalize();
+    @Override
+    public void close() {
+        mCloseGuard.close();
+        if (mClosed.compareAndSet(false, true)) {
+            mMediaProvider.close();
+            native_finalize();
+        }
     }
 
     @Override
-    protected void finalize() {
-        mContext.getContentResolver().releaseProvider(mMediaProvider);
-        native_finalize();
+    protected void finalize() throws Throwable {
+        try {
+            mCloseGuard.warnIfOpen();
+            close();
+        } finally {
+            super.finalize();
+        }
     }
 }
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java
index 3541fba..bc96e2e 100755
--- a/media/java/android/mtp/MtpDatabase.java
+++ b/media/java/android/mtp/MtpDatabase.java
@@ -17,9 +17,9 @@
 package android.mtp;
 
 import android.content.BroadcastReceiver;
-import android.content.Context;
+import android.content.ContentProviderClient;
 import android.content.ContentValues;
-import android.content.IContentProvider;
+import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
@@ -37,23 +37,30 @@
 import android.view.Display;
 import android.view.WindowManager;
 
+import dalvik.system.CloseGuard;
+
 import java.io.File;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Locale;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * {@hide}
  */
-public class MtpDatabase {
-
+public class MtpDatabase implements AutoCloseable {
     private static final String TAG = "MtpDatabase";
 
     private final Context mContext;
     private final String mPackageName;
-    private final IContentProvider mMediaProvider;
+    private final ContentProviderClient mMediaProvider;
     private final String mVolumeName;
     private final Uri mObjectsUri;
+    private final MediaScanner mMediaScanner;
+
+    private final AtomicBoolean mClosed = new AtomicBoolean();
+    private final CloseGuard mCloseGuard = CloseGuard.get();
+
     // path to primary storage
     private final String mMediaStoragePath;
     // if not null, restrict all queries to these subdirectories
@@ -120,7 +127,6 @@
     private static final String STORAGE_FORMAT_PARENT_WHERE = STORAGE_FORMAT_WHERE + " AND "
                                             + Files.FileColumns.PARENT + "=?";
 
-    private final MediaScanner mMediaScanner;
     private MtpServer mServer;
 
     // read from native code
@@ -156,11 +162,12 @@
 
         mContext = context;
         mPackageName = context.getPackageName();
-        mMediaProvider = context.getContentResolver().acquireProvider("media");
+        mMediaProvider = context.getContentResolver()
+                .acquireContentProviderClient(MediaStore.AUTHORITY);
         mVolumeName = volumeName;
         mMediaStoragePath = storagePath;
         mObjectsUri = Files.getMtpObjectsUri(volumeName);
-        mMediaScanner = new MediaScanner(context);
+        mMediaScanner = new MediaScanner(context, mVolumeName);
 
         mSubDirectories = subDirectories;
         if (subDirectories != null) {
@@ -187,20 +194,9 @@
             }
         }
 
-        // Set locale to MediaScanner.
-        Locale locale = context.getResources().getConfiguration().locale;
-        if (locale != null) {
-            String language = locale.getLanguage();
-            String country = locale.getCountry();
-            if (language != null) {
-                if (country != null) {
-                    mMediaScanner.setLocale(language + "_" + country);
-                } else {
-                    mMediaScanner.setLocale(language);
-                }
-            }
-        }
         initDeviceProperties(context);
+
+        mCloseGuard.open("close");
     }
 
     public void setServer(MtpServer server) {
@@ -221,9 +217,20 @@
     }
 
     @Override
+    public void close() {
+        mCloseGuard.close();
+        if (mClosed.compareAndSet(false, true)) {
+            mMediaScanner.close();
+            mMediaProvider.close();
+            native_finalize();
+        }
+    }
+
+    @Override
     protected void finalize() throws Throwable {
         try {
-            native_finalize();
+            mCloseGuard.warnIfOpen();
+            close();
         } finally {
             super.finalize();
         }
@@ -334,7 +341,7 @@
         if (path != null) {
             Cursor c = null;
             try {
-                c = mMediaProvider.query(mPackageName, mObjectsUri, ID_PROJECTION, PATH_WHERE,
+                c = mMediaProvider.query(mObjectsUri, ID_PROJECTION, PATH_WHERE,
                         new String[] { path }, null, null);
                 if (c != null && c.getCount() > 0) {
                     Log.w(TAG, "file already exists in beginSendObject: " + path);
@@ -359,7 +366,7 @@
         values.put(Files.FileColumns.DATE_MODIFIED, modified);
 
         try {
-            Uri uri = mMediaProvider.insert(mPackageName, mObjectsUri, values);
+            Uri uri = mMediaProvider.insert(mObjectsUri, values);
             if (uri != null) {
                 return Integer.parseInt(uri.getPathSegments().get(2));
             } else {
@@ -394,13 +401,13 @@
                 values.put(Files.FileColumns.DATE_MODIFIED, System.currentTimeMillis() / 1000);
                 values.put(MediaColumns.MEDIA_SCANNER_NEW_OBJECT_ID, handle);
                 try {
-                    Uri uri = mMediaProvider.insert(mPackageName,
+                    Uri uri = mMediaProvider.insert(
                             Audio.Playlists.EXTERNAL_CONTENT_URI, values);
                 } catch (RemoteException e) {
                     Log.e(TAG, "RemoteException in endSendObject", e);
                 }
             } else {
-                mMediaScanner.scanMtpFile(path, mVolumeName, handle, format);
+                mMediaScanner.scanMtpFile(path, handle, format);
             }
         } else {
             deleteFile(handle);
@@ -503,7 +510,7 @@
             }
         }
 
-        return mMediaProvider.query(mPackageName, mObjectsUri, ID_PROJECTION, where,
+        return mMediaProvider.query(mObjectsUri, ID_PROJECTION, where,
                 whereArgs, null, null);
     }
 
@@ -721,7 +728,7 @@
              propertyGroup = mPropertyGroupsByFormat.get(format);
              if (propertyGroup == null) {
                 int[] propertyList = getSupportedObjectProperties(format);
-                propertyGroup = new MtpPropertyGroup(this, mMediaProvider, mPackageName,
+                propertyGroup = new MtpPropertyGroup(this, mMediaProvider,
                         mVolumeName, propertyList);
                 mPropertyGroupsByFormat.put(new Integer(format), propertyGroup);
             }
@@ -729,7 +736,7 @@
               propertyGroup = mPropertyGroupsByProperty.get(property);
              if (propertyGroup == null) {
                 int[] propertyList = new int[] { (int)property };
-                propertyGroup = new MtpPropertyGroup(this, mMediaProvider, mPackageName,
+                propertyGroup = new MtpPropertyGroup(this, mMediaProvider,
                         mVolumeName, propertyList);
                 mPropertyGroupsByProperty.put(new Integer((int)property), propertyGroup);
             }
@@ -745,7 +752,7 @@
         String path = null;
         String[] whereArgs = new String[] {  Integer.toString(handle) };
         try {
-            c = mMediaProvider.query(mPackageName, mObjectsUri, PATH_PROJECTION, ID_WHERE,
+            c = mMediaProvider.query(mObjectsUri, PATH_PROJECTION, ID_WHERE,
                     whereArgs, null, null);
             if (c != null && c.moveToNext()) {
                 path = c.getString(1);
@@ -788,7 +795,7 @@
         try {
             // note - we are relying on a special case in MediaProvider.update() to update
             // the paths for all children in the case where this is a directory.
-            updated = mMediaProvider.update(mPackageName, mObjectsUri, values, ID_WHERE, whereArgs);
+            updated = mMediaProvider.update(mObjectsUri, values, ID_WHERE, whereArgs);
         } catch (RemoteException e) {
             Log.e(TAG, "RemoteException in mMediaProvider.update", e);
         }
@@ -805,7 +812,7 @@
             if (oldFile.getName().startsWith(".") && !newPath.startsWith(".")) {
                 // directory was unhidden
                 try {
-                    mMediaProvider.call(mPackageName, MediaStore.UNHIDE_CALL, newPath, null);
+                    mMediaProvider.call(MediaStore.UNHIDE_CALL, newPath, null);
                 } catch (RemoteException e) {
                     Log.e(TAG, "failed to unhide/rescan for " + newPath);
                 }
@@ -815,7 +822,7 @@
             if (oldFile.getName().toLowerCase(Locale.US).equals(".nomedia")
                     && !newPath.toLowerCase(Locale.US).equals(".nomedia")) {
                 try {
-                    mMediaProvider.call(mPackageName, MediaStore.UNHIDE_CALL, oldFile.getParent(), null);
+                    mMediaProvider.call(MediaStore.UNHIDE_CALL, oldFile.getParent(), null);
                 } catch (RemoteException e) {
                     Log.e(TAG, "failed to unhide/rescan for " + newPath);
                 }
@@ -886,7 +893,7 @@
                         char[] outName, long[] outCreatedModified) {
         Cursor c = null;
         try {
-            c = mMediaProvider.query(mPackageName, mObjectsUri, OBJECT_INFO_PROJECTION,
+            c = mMediaProvider.query(mObjectsUri, OBJECT_INFO_PROJECTION,
                             ID_WHERE, new String[] {  Integer.toString(handle) }, null, null);
             if (c != null && c.moveToNext()) {
                 outStorageFormatParent[0] = c.getInt(1);
@@ -933,7 +940,7 @@
         }
         Cursor c = null;
         try {
-            c = mMediaProvider.query(mPackageName, mObjectsUri, PATH_FORMAT_PROJECTION,
+            c = mMediaProvider.query(mObjectsUri, PATH_FORMAT_PROJECTION,
                             ID_WHERE, new String[] {  Integer.toString(handle) }, null, null);
             if (c != null && c.moveToNext()) {
                 String path = c.getString(1);
@@ -960,7 +967,7 @@
     private int getObjectFormat(int handle) {
         Cursor c = null;
         try {
-            c = mMediaProvider.query(mPackageName, mObjectsUri, FORMAT_PROJECTION,
+            c = mMediaProvider.query(mObjectsUri, FORMAT_PROJECTION,
                             ID_WHERE, new String[] {  Integer.toString(handle) }, null, null);
             if (c != null && c.moveToNext()) {
                 return c.getInt(1);
@@ -984,7 +991,7 @@
 
         Cursor c = null;
         try {
-            c = mMediaProvider.query(mPackageName, mObjectsUri, PATH_FORMAT_PROJECTION,
+            c = mMediaProvider.query(mObjectsUri, PATH_FORMAT_PROJECTION,
                             ID_WHERE, new String[] {  Integer.toString(handle) }, null, null);
             if (c != null && c.moveToNext()) {
                 // don't convert to media path here, since we will be matching
@@ -1007,7 +1014,7 @@
             if (format == MtpConstants.FORMAT_ASSOCIATION) {
                 // recursive case - delete all children first
                 Uri uri = Files.getMtpObjectsUri(mVolumeName);
-                int count = mMediaProvider.delete(mPackageName, uri,
+                int count = mMediaProvider.delete(uri,
                     // the 'like' makes it use the index, the 'lower()' makes it correct
                     // when the path contains sqlite wildcard characters
                     "_data LIKE ?1 AND lower(substr(_data,1,?2))=lower(?3)",
@@ -1015,12 +1022,12 @@
             }
 
             Uri uri = Files.getMtpObjectsUri(mVolumeName, handle);
-            if (mMediaProvider.delete(mPackageName, uri, null, null) > 0) {
+            if (mMediaProvider.delete(uri, null, null) > 0) {
                 if (format != MtpConstants.FORMAT_ASSOCIATION
                         && path.toLowerCase(Locale.US).endsWith("/.nomedia")) {
                     try {
                         String parentPath = path.substring(0, path.lastIndexOf("/"));
-                        mMediaProvider.call(mPackageName, MediaStore.UNHIDE_CALL, parentPath, null);
+                        mMediaProvider.call(MediaStore.UNHIDE_CALL, parentPath, null);
                     } catch (RemoteException e) {
                         Log.e(TAG, "failed to unhide/rescan for " + path);
                     }
@@ -1043,7 +1050,7 @@
         Uri uri = Files.getMtpReferencesUri(mVolumeName, handle);
         Cursor c = null;
         try {
-            c = mMediaProvider.query(mPackageName, uri, ID_PROJECTION, null, null, null, null);
+            c = mMediaProvider.query(uri, ID_PROJECTION, null, null, null, null);
             if (c == null) {
                 return null;
             }
@@ -1077,7 +1084,7 @@
             valuesList[i] = values;
         }
         try {
-            if (mMediaProvider.bulkInsert(mPackageName, uri, valuesList) > 0) {
+            if (mMediaProvider.bulkInsert(uri, valuesList) > 0) {
                 return MtpConstants.RESPONSE_OK;
             }
         } catch (RemoteException e) {
diff --git a/media/java/android/mtp/MtpDevice.java b/media/java/android/mtp/MtpDevice.java
index 95cb520..d24c5e8 100644
--- a/media/java/android/mtp/MtpDevice.java
+++ b/media/java/android/mtp/MtpDevice.java
@@ -19,9 +19,10 @@
 import android.hardware.usb.UsbDevice;
 import android.hardware.usb.UsbDeviceConnection;
 import android.os.CancellationSignal;
-import android.os.OperationCanceledException;
 import android.os.ParcelFileDescriptor;
 
+import java.io.IOException;
+
 /**
  * This class represents an MTP or PTP device connected on the USB host bus. An application can
  * instantiate an object of this type, by referencing an attached {@link
@@ -158,6 +159,22 @@
     }
 
     /**
+     * Obtains object bytes in the specified range and writes it to an array.
+     * This call may block for an arbitrary amount of time depending on the size
+     * of the data and speed of the devices.
+     *
+     * @param objectHandle handle of the object to read
+     * @param offset Start index of reading range.
+     * @param size Size of reading range.
+     * @param buffer Array to write data.
+     * @return Size of bytes that are actually read.
+     */
+    public int getPartialObject(int objectHandle, int offset, int size, byte[] buffer)
+            throws IOException {
+        return native_get_partial_object(objectHandle, offset, size, buffer);
+    }
+
+    /**
      * Returns the thumbnail data for an object as a byte array.
      * The size and format of the thumbnail data can be determined via
      * {@link MtpObjectInfo#getThumbCompressedSize} and
@@ -323,6 +340,8 @@
     private native int[] native_get_object_handles(int storageId, int format, int objectHandle);
     private native MtpObjectInfo native_get_object_info(int objectHandle);
     private native byte[] native_get_object(int objectHandle, int objectSize);
+    private native int native_get_partial_object(
+            int objectHandle, int offset, int objectSize, byte[] buffer) throws IOException;
     private native byte[] native_get_thumbnail(int objectHandle);
     private native boolean native_delete_object(int objectHandle);
     private native long native_get_parent(int objectHandle);
diff --git a/media/java/android/mtp/MtpPropertyGroup.java b/media/java/android/mtp/MtpPropertyGroup.java
index c80adfa..dea3008 100644
--- a/media/java/android/mtp/MtpPropertyGroup.java
+++ b/media/java/android/mtp/MtpPropertyGroup.java
@@ -16,7 +16,7 @@
 
 package android.mtp;
 
-import android.content.IContentProvider;
+import android.content.ContentProviderClient;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.RemoteException;
@@ -48,8 +48,7 @@
     }
 
     private final MtpDatabase mDatabase;
-    private final IContentProvider mProvider;
-    private final String mPackageName;
+    private final ContentProviderClient mProvider;
     private final String mVolumeName;
     private final Uri mUri;
 
@@ -65,13 +64,12 @@
     private static final String PARENT_WHERE = Files.FileColumns.PARENT + "=?";
     private static final String PARENT_FORMAT_WHERE = PARENT_WHERE + " AND " + FORMAT_WHERE;
     // constructs a property group for a list of properties
-    public MtpPropertyGroup(MtpDatabase database, IContentProvider provider, String packageName,
-            String volume, int[] properties) {
+    public MtpPropertyGroup(MtpDatabase database, ContentProviderClient provider, String volumeName,
+            int[] properties) {
         mDatabase = database;
         mProvider = provider;
-        mPackageName = packageName;
-        mVolumeName = volume;
-        mUri = Files.getMtpObjectsUri(volume);
+        mVolumeName = volumeName;
+        mUri = Files.getMtpObjectsUri(volumeName);
 
         int count = properties.length;
         ArrayList<String> columns = new ArrayList<String>(count);
@@ -201,7 +199,7 @@
         Cursor c = null;
         try {
             // for now we are only reading properties from the "objects" table
-            c = mProvider.query(mPackageName, mUri,
+            c = mProvider.query(mUri,
                             new String [] { Files.FileColumns._ID, column },
                             ID_WHERE, new String[] { Integer.toString(id) }, null, null);
             if (c != null && c.moveToNext()) {
@@ -221,7 +219,7 @@
     private String queryAudio(int id, String column) {
         Cursor c = null;
         try {
-            c = mProvider.query(mPackageName, Audio.Media.getContentUri(mVolumeName),
+            c = mProvider.query(Audio.Media.getContentUri(mVolumeName),
                             new String [] { Files.FileColumns._ID, column },
                             ID_WHERE, new String[] { Integer.toString(id) }, null, null);
             if (c != null && c.moveToNext()) {
@@ -242,7 +240,7 @@
         Cursor c = null;
         try {
             Uri uri = Audio.Genres.getContentUriForAudioId(mVolumeName, id);
-            c = mProvider.query(mPackageName, uri,
+            c = mProvider.query(uri,
                             new String [] { Files.FileColumns._ID, Audio.GenresColumns.NAME },
                             null, null, null, null);
             if (c != null && c.moveToNext()) {
@@ -264,7 +262,7 @@
         Cursor c = null;
         try {
             // for now we are only reading properties from the "objects" table
-            c = mProvider.query(mPackageName, mUri,
+            c = mProvider.query(mUri,
                             new String [] { Files.FileColumns._ID, column },
                             ID_WHERE, new String[] { Integer.toString(id) }, null, null);
             if (c != null && c.moveToNext()) {
@@ -335,7 +333,7 @@
         try {
             // don't query if not necessary
             if (depth > 0 || handle == 0xFFFFFFFF || mColumns.length > 1) {
-                c = mProvider.query(mPackageName, mUri, mColumns, where, whereArgs, null, null);
+                c = mProvider.query(mUri, mColumns, where, whereArgs, null, null);
                 if (c == null) {
                     return new MtpPropertyList(0, MtpConstants.RESPONSE_INVALID_OBJECT_HANDLE);
                 }
diff --git a/media/jni/android_mtp_MtpDevice.cpp b/media/jni/android_mtp_MtpDevice.cpp
index 3f4d183..14c15e5 100644
--- a/media/jni/android_mtp_MtpDevice.cpp
+++ b/media/jni/android_mtp_MtpDevice.cpp
@@ -29,6 +29,7 @@
 #include "JNIHelp.h"
 #include "android_runtime/AndroidRuntime.h"
 #include "android_runtime/Log.h"
+#include "nativehelper/ScopedLocalRef.h"
 #include "private/android_filesystem_config.h"
 
 #include "MtpTypes.h"
@@ -41,6 +42,8 @@
 
 // ----------------------------------------------------------------------------
 
+namespace {
+
 static jfieldID field_context;
 
 jclass clazz_deviceInfo;
@@ -93,6 +96,29 @@
 // MtpEvent fields
 static jfieldID field_event_eventCode;
 
+class JavaArrayWriter {
+public:
+    JavaArrayWriter(JNIEnv* env, jbyteArray array) :
+        mEnv(env), mArray(array), mSize(mEnv->GetArrayLength(mArray)) {}
+    bool write(void* data, uint32_t offset, uint32_t length) {
+        if (static_cast<uint32_t>(mSize) < offset + length) {
+            return false;
+        }
+        mEnv->SetByteArrayRegion(mArray, offset, length, static_cast<jbyte*>(data));
+        return true;
+    }
+    static bool writeTo(void* data, uint32_t offset, uint32_t length, void* clientData) {
+        return static_cast<JavaArrayWriter*>(clientData)->write(data, offset, length);
+    }
+
+private:
+    JNIEnv* mEnv;
+    jbyteArray mArray;
+    jsize mSize;
+};
+
+}
+
 MtpDevice* get_device_from_object(JNIEnv* env, jobject javaDevice)
 {
     return (MtpDevice*)env->GetLongField(javaDevice, field_context);
@@ -307,38 +333,59 @@
     return info;
 }
 
-struct get_object_callback_data {
-    JNIEnv *env;
-    jbyteArray array;
-};
-
-static bool get_object_callback(void* data, int offset, int length, void* clientData)
-{
-    get_object_callback_data* cbData = (get_object_callback_data *)clientData;
-    cbData->env->SetByteArrayRegion(cbData->array, offset, length, (jbyte *)data);
-    return true;
-}
-
 static jbyteArray
 android_mtp_MtpDevice_get_object(JNIEnv *env, jobject thiz, jint objectID, jint objectSize)
 {
     MtpDevice* device = get_device_from_object(env, thiz);
-    if (!device)
-        return NULL;
-
-    jbyteArray array = env->NewByteArray(objectSize);
-    if (!array) {
-        jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
-        return NULL;
+    if (!device) {
+        return nullptr;
     }
 
-    get_object_callback_data data;
-    data.env = env;
-    data.array = array;
+    ScopedLocalRef<jbyteArray> array(env, env->NewByteArray(objectSize));
+    if (!array.get()) {
+        jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
+        return nullptr;
+    }
 
-    if (device->readObject(objectID, get_object_callback, objectSize, &data))
-        return array;
-    return NULL;
+    JavaArrayWriter writer(env, array.get());
+
+    if (device->readObject(objectID, JavaArrayWriter::writeTo, objectSize, &writer)) {
+        return array.release();
+    }
+    return nullptr;
+}
+
+static jint
+android_mtp_MtpDevice_get_partial_object(JNIEnv *env,
+                                         jobject thiz,
+                                         jint objectID,
+                                         jint offset,
+                                         jint size,
+                                         jbyteArray array)
+{
+    if (!array) {
+        jniThrowException(env, "java/lang/IllegalArgumentException", "Array must not be null.");
+        return -1;
+    }
+
+    MtpDevice* const device = get_device_from_object(env, thiz);
+    if (!device) {
+        jniThrowException(env, "java/io/IOException", "Failed to obtain MtpDevice.");
+        return -1;
+    }
+
+    JavaArrayWriter writer(env, array);
+    uint32_t written_size;
+    bool success = device->readPartialObject(
+            objectID, offset, size, &written_size, JavaArrayWriter::writeTo, &writer);
+    if (!success) {
+        jniThrowException(env, "java/io/IOException", "Failed to read data.");
+        return -1;
+    }
+    // Note: assumption here is that a negative value will be treated as unsigned on the Java
+    //       level.
+    // TODO: Make sure that actually holds.
+    return static_cast<jint>(written_size);
 }
 
 static jbyteArray
@@ -547,6 +594,7 @@
     {"native_get_object_info",  "(I)Landroid/mtp/MtpObjectInfo;",
                                         (void *)android_mtp_MtpDevice_get_object_info},
     {"native_get_object",       "(II)[B",(void *)android_mtp_MtpDevice_get_object},
+    {"native_get_partial_object", "(III[B)I", (void *)android_mtp_MtpDevice_get_partial_object},
     {"native_get_thumbnail",    "(I)[B",(void *)android_mtp_MtpDevice_get_thumbnail},
     {"native_delete_object",    "(I)Z", (void *)android_mtp_MtpDevice_delete_object},
     {"native_get_parent",       "(I)J", (void *)android_mtp_MtpDevice_get_parent},
diff --git a/media/jni/soundpool/SoundPool.cpp b/media/jni/soundpool/SoundPool.cpp
index 70d651f..b63df6f 100644
--- a/media/jni/soundpool/SoundPool.cpp
+++ b/media/jni/soundpool/SoundPool.cpp
@@ -655,7 +655,7 @@
        goto error;
     }
 
-    if ((numChannels < 1) || (numChannels > 8)) {
+    if ((numChannels < 1) || (numChannels > FCC_8)) {
         ALOGE("Sample channel count (%d) out of range", numChannels);
         status = BAD_VALUE;
         goto error;
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java
index 05df014..06efa90 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaInserterTest.java
@@ -16,6 +16,7 @@
 
 package com.android.mediaframeworktest.unit;
 
+import android.content.ContentProviderClient;
 import android.content.ContentValues;
 import android.content.IContentProvider;
 import android.media.MediaInserter;
@@ -81,8 +82,9 @@
     protected void setUp() throws Exception {
         super.setUp();
         mMockProvider = EasyMock.createMock(IContentProvider.class);
-        mMediaInserter = new MediaInserter(mMockProvider,
-        mPackageName, TEST_BUFFER_SIZE);
+        final ContentProviderClient client = new ContentProviderClient(
+                getInstrumentation().getContext().getContentResolver(), mMockProvider, true);
+        mMediaInserter = new MediaInserter(client, TEST_BUFFER_SIZE);
         mPackageName = getInstrumentation().getContext().getPackageName();
         mFilesCounter = 0;
         mAudioCounter = 0;
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_album_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_album_alpha.png
deleted file mode 100644
index 2b21c12..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_album_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_apk_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_apk_alpha.png
deleted file mode 100644
index ed3ee45..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_apk_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_audio_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_audio_alpha.png
deleted file mode 100644
index 1a3ebc47..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_audio_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_certificate_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_certificate_alpha.png
deleted file mode 100644
index 3086a69..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_certificate_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_codes_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_codes_alpha.png
deleted file mode 100644
index b86f0f7..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_codes_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_compressed_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_compressed_alpha.png
deleted file mode 100644
index 9d0988d..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_compressed_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_contact_am_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_contact_am_alpha.png
deleted file mode 100644
index 6c31360..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_contact_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_event_am_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_event_am_alpha.png
deleted file mode 100644
index 1450ff0..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_event_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_excel_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_excel_alpha.png
deleted file mode 100644
index 4ad54bb..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_excel_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_folder_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_folder_alpha.png
deleted file mode 100644
index 7f7c636..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_folder_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_font_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_font_alpha.png
deleted file mode 100644
index d867847..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_font_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_generic_am_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_generic_am_alpha.png
deleted file mode 100644
index 5459767..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_generic_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_image_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_image_alpha.png
deleted file mode 100644
index 0cbd992..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_image_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_pdf_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_pdf_alpha.png
deleted file mode 100644
index db46702..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_pdf_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_powerpoint_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_powerpoint_alpha.png
deleted file mode 100644
index b9f7af5..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_powerpoint_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_presentation_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_presentation_alpha.png
deleted file mode 100644
index 1218c2f..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_presentation_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_spreadsheet_am_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_spreadsheet_am_alpha.png
deleted file mode 100644
index 46d755f..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_spreadsheet_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_text_am_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_text_am_alpha.png
deleted file mode 100644
index 933570b..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_text_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_video_am_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_video_am_alpha.png
deleted file mode 100644
index 30cea25..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_video_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_word_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_doc_word_alpha.png
deleted file mode 100644
index 67b60de..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_doc_word_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-hdpi/ic_root_sdcard_alpha.png b/packages/DocumentsUI/res/drawable-hdpi/ic_root_sdcard_alpha.png
deleted file mode 100644
index 65e42aa..0000000
--- a/packages/DocumentsUI/res/drawable-hdpi/ic_root_sdcard_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_album_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_album_alpha.png
deleted file mode 100644
index ac27eea..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_album_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_apk_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_apk_alpha.png
deleted file mode 100644
index a4add51..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_apk_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_audio_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_audio_alpha.png
deleted file mode 100644
index a9a7f20..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_audio_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_certificate_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_certificate_alpha.png
deleted file mode 100644
index 26beb79..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_certificate_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_codes_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_codes_alpha.png
deleted file mode 100644
index ed9cab7..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_codes_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_compressed_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_compressed_alpha.png
deleted file mode 100644
index 451d287..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_compressed_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_contact_am_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_contact_am_alpha.png
deleted file mode 100644
index 7bc02c9..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_contact_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_event_am_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_event_am_alpha.png
deleted file mode 100644
index de39cd4..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_event_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_excel_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_excel_alpha.png
deleted file mode 100644
index c3eb845..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_excel_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_folder_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_folder_alpha.png
deleted file mode 100644
index 97f6e507..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_folder_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_font_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_font_alpha.png
deleted file mode 100644
index b2f043f..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_font_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_generic_am_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_generic_am_alpha.png
deleted file mode 100644
index 483d7fb..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_generic_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_image_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_image_alpha.png
deleted file mode 100644
index 2941b8a..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_image_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_pdf_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_pdf_alpha.png
deleted file mode 100644
index d3ac072..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_pdf_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_powerpoint_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_powerpoint_alpha.png
deleted file mode 100644
index a43f902..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_powerpoint_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_presentation_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_presentation_alpha.png
deleted file mode 100644
index c572cd1..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_presentation_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_spreadsheet_am_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_spreadsheet_am_alpha.png
deleted file mode 100644
index 7ae671b..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_spreadsheet_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_text_am_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_text_am_alpha.png
deleted file mode 100644
index a5ebd51..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_text_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_video_am_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_video_am_alpha.png
deleted file mode 100644
index 89ac434..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_video_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_word_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_doc_word_alpha.png
deleted file mode 100644
index 855c44b..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_doc_word_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-mdpi/ic_root_sdcard_alpha.png b/packages/DocumentsUI/res/drawable-mdpi/ic_root_sdcard_alpha.png
deleted file mode 100644
index 1de8292..0000000
--- a/packages/DocumentsUI/res/drawable-mdpi/ic_root_sdcard_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_album_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_album_alpha.png
deleted file mode 100644
index 4203d35..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_album_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_apk_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_apk_alpha.png
deleted file mode 100644
index 41558f2..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_apk_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_audio_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_audio_alpha.png
deleted file mode 100644
index e190c4d..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_audio_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_certificate_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_certificate_alpha.png
deleted file mode 100644
index fabc8c3..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_certificate_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_codes_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_codes_alpha.png
deleted file mode 100644
index d8ba6e0..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_codes_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_compressed_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_compressed_alpha.png
deleted file mode 100644
index 1b5111a..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_compressed_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_contact_am_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_contact_am_alpha.png
deleted file mode 100644
index e7b7460..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_contact_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_event_am_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_event_am_alpha.png
deleted file mode 100644
index 3183bfc..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_event_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_excel_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_excel_alpha.png
deleted file mode 100644
index 9a4e844..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_excel_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_folder_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_folder_alpha.png
deleted file mode 100644
index 96d5721..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_folder_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_font_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_font_alpha.png
deleted file mode 100644
index 23a1302..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_font_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_generic_am_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_generic_am_alpha.png
deleted file mode 100644
index b0811f1..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_generic_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_image_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_image_alpha.png
deleted file mode 100644
index 5f1f537..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_image_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_pdf_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_pdf_alpha.png
deleted file mode 100644
index 8083584..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_pdf_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_powerpoint_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_powerpoint_alpha.png
deleted file mode 100644
index 898e26a..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_powerpoint_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_presentation_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_presentation_alpha.png
deleted file mode 100644
index 2e9c667..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_presentation_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_spreadsheet_am_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_spreadsheet_am_alpha.png
deleted file mode 100644
index 56951c3..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_spreadsheet_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_text_am_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_text_am_alpha.png
deleted file mode 100644
index 08ed9f0..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_text_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_video_am_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_video_am_alpha.png
deleted file mode 100644
index cd64e56..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_video_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_word_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_word_alpha.png
deleted file mode 100644
index 0bc40de..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_doc_word_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xhdpi/ic_root_sdcard_alpha.png b/packages/DocumentsUI/res/drawable-xhdpi/ic_root_sdcard_alpha.png
deleted file mode 100644
index 00b8a8b7..0000000
--- a/packages/DocumentsUI/res/drawable-xhdpi/ic_root_sdcard_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_album_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_album_alpha.png
deleted file mode 100644
index 60f59f5..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_album_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_apk_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_apk_alpha.png
deleted file mode 100644
index 6006b12..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_apk_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_audio_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_audio_alpha.png
deleted file mode 100644
index 7926188..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_audio_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_certificate_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_certificate_alpha.png
deleted file mode 100644
index e65d74c..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_certificate_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_codes_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_codes_alpha.png
deleted file mode 100644
index 7d32801..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_codes_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_compressed_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_compressed_alpha.png
deleted file mode 100644
index d528708..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_compressed_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_contact_am_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_contact_am_alpha.png
deleted file mode 100644
index 274c524..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_contact_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_event_am_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_event_am_alpha.png
deleted file mode 100644
index 6053b0a..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_event_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_excel_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_excel_alpha.png
deleted file mode 100644
index 78ee13b..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_excel_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_folder_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_folder_alpha.png
deleted file mode 100644
index dcf9cc2..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_folder_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_font_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_font_alpha.png
deleted file mode 100644
index 74fbbbc..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_font_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_generic_am_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_generic_am_alpha.png
deleted file mode 100644
index 11a219a..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_generic_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_image_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_image_alpha.png
deleted file mode 100644
index 9a461c9..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_image_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_pdf_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_pdf_alpha.png
deleted file mode 100644
index 9a67956..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_pdf_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_powerpoint_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_powerpoint_alpha.png
deleted file mode 100644
index 853aa8c..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_powerpoint_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_presentation_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_presentation_alpha.png
deleted file mode 100644
index 84ae9ae..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_presentation_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_spreadsheet_am_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_spreadsheet_am_alpha.png
deleted file mode 100644
index 111439e..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_spreadsheet_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_text_am_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_text_am_alpha.png
deleted file mode 100644
index b876f86..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_text_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_video_am_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_video_am_alpha.png
deleted file mode 100644
index 7cf656a..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_video_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_word_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_word_alpha.png
deleted file mode 100644
index acc3d7b..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_doc_word_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxhdpi/ic_root_sdcard_alpha.png b/packages/DocumentsUI/res/drawable-xxhdpi/ic_root_sdcard_alpha.png
deleted file mode 100644
index 5236774..0000000
--- a/packages/DocumentsUI/res/drawable-xxhdpi/ic_root_sdcard_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_album_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_album_alpha.png
deleted file mode 100644
index d2dd494..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_album_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_apk_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_apk_alpha.png
deleted file mode 100644
index 4f935bf..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_apk_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_audio_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_audio_alpha.png
deleted file mode 100644
index 7499cbc..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_audio_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_certificate_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_certificate_alpha.png
deleted file mode 100644
index ca12928..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_certificate_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_codes_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_codes_alpha.png
deleted file mode 100644
index c4afa37..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_codes_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_compressed_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_compressed_alpha.png
deleted file mode 100644
index 0b0aa04..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_compressed_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_contact_am_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_contact_am_alpha.png
deleted file mode 100644
index ebd0535..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_contact_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_event_am_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_event_am_alpha.png
deleted file mode 100644
index 29cdbb7..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_event_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_excel_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_excel_alpha.png
deleted file mode 100644
index ca349b6..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_excel_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_folder_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_folder_alpha.png
deleted file mode 100644
index 02249d2..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_folder_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_font_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_font_alpha.png
deleted file mode 100644
index 469b911..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_font_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_generic_am_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_generic_am_alpha.png
deleted file mode 100644
index ef479c3..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_generic_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_image_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_image_alpha.png
deleted file mode 100644
index 3168d6f..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_image_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_pdf_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_pdf_alpha.png
deleted file mode 100644
index 9bb4d66..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_pdf_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_powerpoint_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_powerpoint_alpha.png
deleted file mode 100644
index 88ba9ad..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_powerpoint_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_presentation_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_presentation_alpha.png
deleted file mode 100644
index 5fe18da..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_presentation_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_spreadsheet_am_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_spreadsheet_am_alpha.png
deleted file mode 100644
index 1d05f6f..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_spreadsheet_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_text_am_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_text_am_alpha.png
deleted file mode 100644
index c2308fe..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_text_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_video_am_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_video_am_alpha.png
deleted file mode 100644
index 9a173be..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_video_am_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_word_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_word_alpha.png
deleted file mode 100644
index a564f5a..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_doc_word_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_root_sdcard_alpha.png b/packages/DocumentsUI/res/drawable-xxxhdpi/ic_root_sdcard_alpha.png
deleted file mode 100644
index c7daa2a..0000000
--- a/packages/DocumentsUI/res/drawable-xxxhdpi/ic_root_sdcard_alpha.png
+++ /dev/null
Binary files differ
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_album.xml b/packages/DocumentsUI/res/drawable/ic_doc_album.xml
index e7965e6..1ce3f02 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_album.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_album.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_album_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF737373"
+        android:pathData="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10,-4.48 10,-10S17.52 2 12 2zm0 14.5c-2.49 0,-4.5,-2.01,-4.5,-4.5S9.51 7.5 12 7.5s4.5 2.01 4.5 4.5,-2.01 4.5,-4.5 4.5zm0,-5.5c-.55 0,-1 .45,-1 1s.45 1 1 1 1,-.45 1,-1,-.45,-1,-1,-1z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_apk.xml b/packages/DocumentsUI/res/drawable/ic_doc_apk.xml
index 4f8f06e..197445e 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_apk.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_apk.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_apk_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF737373"
+        android:pathData="M6 18c0 .55.45 1 1 1h1v3.5c0 .83.67 1.5 1.5 1.5s1.5,-.67 1.5,-1.5V19h2v3.5c0 .83.67 1.5 1.5 1.5s1.5,-.67 1.5,-1.5V19h1c.55 0 1,-.45 1,-1V8H6v10zM3.5 8C2.67 8 2 8.67 2 9.5v7c0 .83.67 1.5 1.5 1.5S5 17.33 5 16.5v-7C5 8.67 4.33 8 3.5 8zm17 0c-.83 0,-1.5.67,-1.5 1.5v7c0 .83.67 1.5 1.5 1.5s1.5,-.67 1.5,-1.5v-7c0,-.83,-.67,-1.5,-1.5,-1.5zm-4.97,-5.84l1.3,-1.3c.2,-.2.2,-.51 0,-.71,-.2,-.2,-.51,-.2,-.71 0l-1.48 1.48C13.85 1.23 12.95 1 12 1c-.96 0,-1.86.23,-2.66.63L7.85.15c-.2,-.2,-.51,-.2,-.71 0,-.2.2,-.2.51 0 .71l1.31 1.31C6.97 3.26 6 5.01 6 7h12c0,-1.99,-.97,-3.75,-2.47,-4.84zM10 5H9V4h1v1zm5 0h-1V4h1v1z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_audio.xml b/packages/DocumentsUI/res/drawable/ic_doc_audio.xml
index cf18b4f..454eea3 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_audio.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_audio.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_audio_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FFDB4437"
+        android:pathData="M19 3H5c-1.1 0,-2 .9,-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2,-.9 2,-2V5c0,-1.1,-.9,-2,-2,-2zM7.2 18c-.66 0,-1.2,-.54,-1.2,-1.2V12c0,-3.31 2.69,-6 6,-6s6 2.69 6 6v4.8c0 .66,-.54 1.2,-1.2 1.2H14v-4h2v-2c0,-2.21,-1.79,-4,-4,-4s-4 1.79,-4 4v2h2v4H7.2z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_certificate.xml b/packages/DocumentsUI/res/drawable/ic_doc_certificate.xml
index c28ed4f..b99baf6 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_certificate.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_certificate.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_certificate_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF737373"
+        android:pathData="M17.81 4.47c-.08 0,-.16,-.02,-.23,-.06C15.66 3.42 14 3 12.01 3c-1.98 0,-3.86.47,-5.57 1.41,-.24.13,-.54.04,-.68,-.2,-.13,-.24,-.04,-.55.2,-.68C7.82 2.52 9.86 2 12.01 2c2.13 0 3.99.47 6.03 1.52.25.13.34.43.21.67,-.09.18,-.26.28,-.44.28zM3.5 9.72c-.1 0,-.2,-.03,-.29,-.09,-.23,-.16,-.28,-.47,-.12,-.7.99,-1.4 2.25,-2.5 3.75,-3.27C9.98 4.04 14 4.03 17.15 5.65c1.5.77 2.76 1.86 3.75 3.25.16.22.11.54,-.12.7,-.23.16,-.54.11,-.7,-.12,-.9,-1.26,-2.04,-2.25,-3.39,-2.94,-2.87,-1.47,-6.54,-1.47,-9.4.01,-1.36.7,-2.5 1.7,-3.4 2.96,-.08.14,-.23.21,-.39.21zm6.25 12.07c-.13 0,-.26,-.05,-.35,-.15,-.87,-.87,-1.34,-1.43,-2.01,-2.64,-.69,-1.23,-1.05,-2.73,-1.05,-4.34 0,-2.97 2.54,-5.39 5.66,-5.39s5.66 2.42 5.66 5.39c0 .28,-.22.5,-.5.5s-.5,-.22,-.5,-.5c0,-2.42,-2.09,-4.39,-4.66,-4.39,-2.57 0,-4.66 1.97,-4.66 4.39 0 1.44.32 2.77.93 3.85.64 1.15 1.08 1.64 1.85 2.42.19.2.19.51 0 .71,-.11.1,-.24.15,-.37.15zm7.17,-1.85c-1.19 0,-2.24,-.3,-3.1,-.89,-1.49,-1.01,-2.38,-2.65,-2.38,-4.39 0,-.28.22,-.5.5,-.5s.5.22.5.5c0 1.41.72 2.74 1.94 3.56.71.48 1.54.71 2.54.71.24 0 .64,-.03 1.04,-.1.27,-.05.53.13.58.41.05.27,-.13.53,-.41.58,-.57.11,-1.07.12,-1.21.12zM14.91 22c-.04 0,-.09,-.01,-.13,-.02,-1.59,-.44,-2.63,-1.03,-3.72,-2.1,-1.4,-1.39,-2.17,-3.24,-2.17,-5.22 0,-1.62 1.38,-2.94 3.08,-2.94 1.7 0 3.08 1.32 3.08 2.94 0 1.07.93 1.94 2.08 1.94s2.08,-.87 2.08,-1.94c0,-3.77,-3.25,-6.83,-7.25,-6.83,-2.84 0,-5.44 1.58,-6.61 4.03,-.39.81,-.59 1.76,-.59 2.8 0 .78.07 2.01.67 3.61.1.26,-.03.55,-.29.64,-.26.1,-.55,-.04,-.64,-.29,-.49,-1.31,-.73,-2.61,-.73,-3.96 0,-1.2.23,-2.29.68,-3.24 1.33,-2.79 4.28,-4.6 7.51,-4.6 4.55 0 8.25 3.51 8.25 7.83 0 1.62,-1.38 2.94,-3.08 2.94s-3.08,-1.32,-3.08,-2.94c0,-1.07,-.93,-1.94,-2.08,-1.94s-2.08.87,-2.08 1.94c0 1.71.66 3.31 1.87 4.51.95.94 1.86 1.46 3.27 1.85.27.07.42.35.35.61,-.05.23,-.26.38,-.47.38z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_codes.xml b/packages/DocumentsUI/res/drawable/ic_doc_codes.xml
index 0de721a9..ea1c464 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_codes.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_codes.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_codes_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF737373"
+        android:pathData="M9.4 16.6L4.8 12l4.6,-4.6L8 6l-6 6 6 6 1.4,-1.4zm5.2 0l4.6,-4.6,-4.6,-4.6L16 6l6 6,-6 6,-1.4,-1.4z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_compressed.xml b/packages/DocumentsUI/res/drawable/ic_doc_compressed.xml
index a49cfa4..e0eb669 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_compressed.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_compressed.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_compressed_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF737373"
+        android:pathData="M19 3H5c-1.1 0,-2 .9,-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2,-.9 2,-2V5c0,-1.1,-.9,-2,-2,-2zm-5 6h-2v2h2v2h-2v-2h-2V9h2V7h-2V5h2v2h2v2zm0 8h-2v-2h-2v-2h2v2h2v2z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_contact.xml b/packages/DocumentsUI/res/drawable/ic_doc_contact.xml
index bf550cb..a77cb6b 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_contact.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_contact.xml
@@ -1,5 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_contact_am_alpha"
-    android:tint="?android:attr/colorControlNormal"
-    android:autoMirrored="true" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF737373"
+        android:pathData="M19 3H5c-1.11 0,-2 .89,-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2,-.9 2,-2V5c0,-1.11,-.9,-2,-2,-2zm-7 3c1.65 0 3 1.35 3 3 0 1.66,-1.35 3,-3 3s-3,-1.34,-3,-3c0,-1.65 1.35,-3 3,-3zm6 12H6v-1c0,-2 4,-3.1 6,-3.1s6 1.1 6 3.1v1z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_document.xml b/packages/DocumentsUI/res/drawable/ic_doc_document.xml
new file mode 100644
index 0000000..29251ad
--- /dev/null
+++ b/packages/DocumentsUI/res/drawable/ic_doc_document.xml
@@ -0,0 +1,24 @@
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF4883F3"
+        android:pathData="M19 3H5c-1.1 0,-2 .9,-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2,-.9 2,-2V5c0,-1.1,-.9,-2,-2,-2zm-1.99 6H7V7h10.01v2zm0 4H7v-2h10.01v2zm-3 4H7v-2h7.01v2z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_event.xml b/packages/DocumentsUI/res/drawable/ic_doc_event.xml
index 25cf0f3..113f079 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_event.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_event.xml
@@ -1,5 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_event_am_alpha"
-    android:tint="?android:attr/colorControlNormal"
-    android:autoMirrored="true" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF737373"
+        android:pathData="M17 12h-5v5h5v-5zM16 1v2H8V1H6v2H5c-1.11 0,-1.99.9,-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2,-.9 2,-2V5c0,-1.1,-.9,-2,-2,-2h-1V1h-2zm3 18H5V8h14v11z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_excel.xml b/packages/DocumentsUI/res/drawable/ic_doc_excel.xml
index 3354725..3ed27e1 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_excel.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_excel.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_excel_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF16A765"
+        android:pathData="M19 3H5c-1.1 0,-2 .9,-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2,-.9 2,-2V5c0,-1.1,-.9,-2,-2,-2zm-2.8 14h-2L12 13.2 9.8 17h-2l3.2,-5,-3.2,-5h2l2.2 3.8L14.2 7h2L13 12l3.2 5z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_folder.xml b/packages/DocumentsUI/res/drawable/ic_doc_folder.xml
index 73de60e..dcbce01 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_folder.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_folder.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_folder_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF737373"
+        android:pathData="M10 4H4c-1.1 0,-1.99.9,-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2,-.9 2,-2V8c0,-1.1,-.9,-2,-2,-2h-8l-2,-2z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_font.xml b/packages/DocumentsUI/res/drawable/ic_doc_font.xml
index c74cb9c..4c13d71 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_font.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_font.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_font_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF737373"
+        android:pathData="M9.93 13.5h4.14L12 7.98zM20 2H4c-1.1 0,-2 .9,-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2,-.9 2,-2V4c0,-1.1,-.9,-2,-2,-2zm-4.05 16.5l-1.14,-3H9.17l-1.12 3H5.96l5.11,-13h1.86l5.11 13h-2.09z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_generic.xml b/packages/DocumentsUI/res/drawable/ic_doc_generic.xml
index a4ee29d..006dfba 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_generic.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_generic.xml
@@ -1,5 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_generic_am_alpha"
-    android:tint="?android:attr/colorControlNormal"
-    android:autoMirrored="true" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF737373"
+        android:pathData="M6 2c-1.1 0,-1.99.9,-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2,-.9 2,-2V8l-6,-6H6zm7 7V3.5L18.5 9H13z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_image.xml b/packages/DocumentsUI/res/drawable/ic_doc_image.xml
index 9d4c359..23953f7 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_image.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_image.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_image_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FFDB4437"
+        android:pathData="M21 19V5c0,-1.1,-.9,-2,-2,-2H5c-1.1 0,-2 .9,-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2,-.9 2,-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5,-4.5z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_pdf.xml b/packages/DocumentsUI/res/drawable/ic_doc_pdf.xml
index 5c37498..b2d0193 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_pdf.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_pdf.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_pdf_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FFDB4437"
+        android:pathData="M7 11.5h1v-1H7v1zM19 3H5c-1.1 0,-2 .9,-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2,-.9 2,-2V5c0,-1.1,-.9,-2,-2,-2zm-9.5 8.5c0 .83,-.67 1.5,-1.5 1.5H7v2H5.5V9H8c.83 0 1.5.67 1.5 1.5v1zm10,-1H17v1h1.5V13H17v2h-1.5V9h4v1.5zm-5 3c0 .83,-.67 1.5,-1.5 1.5h-2.5V9H13c.83 0 1.5.67 1.5 1.5v3zm-2.5 0h1v-3h-1v3z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_powerpoint.xml b/packages/DocumentsUI/res/drawable/ic_doc_powerpoint.xml
index f0a6c39..aa5bfc8 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_powerpoint.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_powerpoint.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_powerpoint_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FFFF7537"
+        android:pathData="M19 3H5c-1.1 0,-2 .9,-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2,-.9 2,-2V5c0,-1.1,-.9,-2,-2,-2zM9.8 13.4V17H8V7h4.3c1.53 0 2.15.3 2.8.89.65.59.9 1.37.9 2.34 0 1.02,-.26 1.8,-.9 2.35s-1.3.82,-2.8.82H9.8zm0,-1.4V8.4h2.3c.66 0 1.17.25 1.5.6.33.35.5.72.5 1.25 0 .55,-.18.95,-.5 1.25,-.32.31,-.7.5,-1.38.5H9.8z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_presentation.xml b/packages/DocumentsUI/res/drawable/ic_doc_presentation.xml
index a14f866..7937bc1 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_presentation.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_presentation.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_presentation_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FFF4B400"
+        android:pathData="M19 3H5c-1.1 0,-1.99.9,-1.99 2v14c0 1.1.89 2 1.99 2h14c1.1 0 2,-.9 2,-2V5c0,-1.1,-.9,-2,-2,-2zm0 13H5V8h14v8z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_spreadsheet.xml b/packages/DocumentsUI/res/drawable/ic_doc_spreadsheet.xml
index 40f2515..1663c0a 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_spreadsheet.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_spreadsheet.xml
@@ -1,5 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_spreadsheet_am_alpha"
-    android:tint="?android:attr/colorControlNormal"
-    android:autoMirrored="true" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF16A765"
+        android:pathData="M19 3H5c-1.1 0,-1.99.9,-1.99 2L3 8v11c0 1.1.9 2 2 2h14c1.1 0 2,-.9 2,-2V5c0,-1.1,-.9,-2,-2,-2zm0 8h-8v8H9v-8H5V9h4V5h2v4h8v2z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_text.xml b/packages/DocumentsUI/res/drawable/ic_doc_text.xml
index ffa9e70..7fc04e8 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_text.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_text.xml
@@ -1,5 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_text_am_alpha"
-    android:tint="?android:attr/colorControlNormal"
-    android:autoMirrored="true" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF737373"
+        android:pathData="M14 2H6c-1.1 0,-1.99.9,-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2,-.9 2,-2V8l-6,-6zm2 16H8v-2h8v2zm0,-4H8v-2h8v2zm-3,-5V3.5L18.5 9H13z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_video.xml b/packages/DocumentsUI/res/drawable/ic_doc_video.xml
index 2d048c2..ad4dae8 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_video.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_video.xml
@@ -1,5 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_video_am_alpha"
-    android:tint="?android:attr/colorControlNormal"
-    android:autoMirrored="true" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FFDB4437"
+        android:pathData="M18 4l2 4h-3l-2,-4h-2l2 4h-3l-2,-4H8l2 4H7L5 4H4c-1.1 0,-1.99.9,-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2,-.9 2,-2V4h-4z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_doc_word.xml b/packages/DocumentsUI/res/drawable/ic_doc_word.xml
index afcc533..7a3a0ec 100644
--- a/packages/DocumentsUI/res/drawable/ic_doc_word.xml
+++ b/packages/DocumentsUI/res/drawable/ic_doc_word.xml
@@ -1,4 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_doc_word_alpha"
-    android:tint="?android:attr/colorControlNormal" />
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF4883F3"
+        android:pathData="M19 3H5c-1.1 0,-2 .9,-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2,-.9 2,-2V5c0,-1.1,-.9,-2,-2,-2zm-3.5 14H14l-2,-7.5,-2 7.5H8.5L6.1 7h1.7l1.54 7.51L11.3 7h1.4l1.97 7.51L16.2 7h1.7l-2.4 10z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/drawable/ic_root_sdcard.xml b/packages/DocumentsUI/res/drawable/ic_root_sdcard.xml
deleted file mode 100644
index 27cfa81d..0000000
--- a/packages/DocumentsUI/res/drawable/ic_root_sdcard.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:src="@drawable/ic_root_sdcard_alpha"
-    android:tint="?android:attr/colorControlNormal" />
diff --git a/packages/DocumentsUI/res/drawable/ic_root_smartphone.xml b/packages/DocumentsUI/res/drawable/ic_root_smartphone.xml
new file mode 100644
index 0000000..3021b16
--- /dev/null
+++ b/packages/DocumentsUI/res/drawable/ic_root_smartphone.xml
@@ -0,0 +1,24 @@
+<!--
+Copyright (C) 2015 The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M17 1.01L7 1c-1.1 0,-2 .9,-2 2v18c0 1.1.9 2 2 2h10c1.1 0 2,-.9 2,-2V3c0,-1.1,-.9,-1.99,-2,-1.99zM17 19H7V5h10v14z"/>
+</vector>
diff --git a/packages/DocumentsUI/res/layout/item_doc_grid.xml b/packages/DocumentsUI/res/layout/item_doc_grid.xml
index c0fc2c3..3c796bd 100644
--- a/packages/DocumentsUI/res/layout/item_doc_grid.xml
+++ b/packages/DocumentsUI/res/layout/item_doc_grid.xml
@@ -40,9 +40,10 @@
 
         <com.android.documentsui.GridItemThumbnail
             android:id="@+id/icon_mime"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:scaleType="centerInside"
+            android:layout_width="@dimen/icon_size"
+            android:layout_height="@dimen/icon_size"
+            android:layout_gravity="center"
+            android:scaleType="fitCenter"
             android:contentDescription="@null" />
 
     </FrameLayout>
diff --git a/packages/DocumentsUI/res/values-sw/strings.xml b/packages/DocumentsUI/res/values-sw/strings.xml
index b522e0a..c303e0c 100644
--- a/packages/DocumentsUI/res/values-sw/strings.xml
+++ b/packages/DocumentsUI/res/values-sw/strings.xml
@@ -97,8 +97,8 @@
     <string name="copy_failure_alert_content" msgid="3715575000297709082">"Faili hizi hazikunakiliwa: <xliff:g id="LIST">%1$s</xliff:g>"</string>
     <string name="move_failure_alert_content" msgid="7151140279020481180">"Faili hizi hazikuhamishwa: <xliff:g id="LIST">%1$s</xliff:g>"</string>
     <plurals name="clipboard_files_clipped" formatted="false" msgid="855459017537058539">
-      <item quantity="other">Alinakili faili <xliff:g id="COUNT_1">%1$d</xliff:g> kwenye ubaoklipu.</item>
-      <item quantity="one">Alinakili faili <xliff:g id="COUNT_0">%1$d</xliff:g> kwenye ubaoklipu.</item>
+      <item quantity="other">Alinakili faili <xliff:g id="COUNT_1">%1$d</xliff:g> kwenye ubao wa kunakili.</item>
+      <item quantity="one">Alinakili faili <xliff:g id="COUNT_0">%1$d</xliff:g> kwenye ubao wa kunakili.</item>
     </plurals>
     <string name="clipboard_files_cannot_paste" msgid="2878324825602325706">"Haiwezi kubandika faili zilizochaguliwa katika eneo hili."</string>
 </resources>
diff --git a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java
index 9c0a04c..a241667 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java
@@ -39,7 +39,6 @@
 import android.support.annotation.LayoutRes;
 import android.support.annotation.Nullable;
 import android.util.Log;
-import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuItem;
@@ -60,6 +59,7 @@
 import com.android.documentsui.model.DocumentStack;
 import com.android.documentsui.model.DurableUtils;
 import com.android.documentsui.model.RootInfo;
+import com.android.internal.util.Preconditions;
 
 import libcore.io.IoUtils;
 
@@ -111,6 +111,13 @@
         setContentView(mLayoutId);
 
         mRoots = DocumentsApplication.getRootsCache(this);
+        mRoots.setOnCacheUpdateListener(
+                new RootsCache.OnCacheUpdateListener() {
+                    @Override
+                    public void onCacheUpdate() {
+                        new HandleRootsChangedTask().execute(getCurrentRoot());
+                    }
+                });
         mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);
         mSearchManager = new SearchManager();
 
@@ -203,7 +210,25 @@
         if (mRoots.isRecentsRoot(root)) {
             onCurrentDirectoryChanged(ANIM_SIDE);
         } else {
-            new PickRootTask(root).executeOnExecutor(getExecutorForCurrentDirectory());
+            new PickRootTask(root, true).executeOnExecutor(getExecutorForCurrentDirectory());
+        }
+    }
+
+    void setRoot(RootInfo root) {
+        // Clear entire backstack and start in new root
+        mState.stack.root = root;
+        mState.stack.clear();
+        mState.stackTouched = false;
+
+        mSearchManager.update(root);
+
+        // Recents is always in memory, so we just load it directly.
+        // Otherwise we delegate loading data from disk to a task
+        // to ensure a responsive ui.
+        if (mRoots.isRecentsRoot(root)) {
+            onCurrentDirectoryChanged(ANIM_SIDE);
+        } else {
+            new PickRootTask(root, false).executeOnExecutor(getExecutorForCurrentDirectory());
         }
     }
 
@@ -483,9 +508,11 @@
 
     final class PickRootTask extends AsyncTask<Void, Void, DocumentInfo> {
         private RootInfo mRoot;
+        private boolean mTouched;
 
-        public PickRootTask(RootInfo root) {
+        public PickRootTask(RootInfo root, boolean touched) {
             mRoot = root;
+            mTouched = touched;
         }
 
         @Override
@@ -504,7 +531,7 @@
         protected void onPostExecute(DocumentInfo result) {
             if (result != null) {
                 mState.stack.push(result);
-                mState.stackTouched = true;
+                mState.stackTouched = mTouched;
                 onCurrentDirectoryChanged(ANIM_SIDE);
             }
         }
@@ -591,6 +618,34 @@
         }
     }
 
+    final class HandleRootsChangedTask extends AsyncTask<RootInfo, Void, RootInfo> {
+        @Override
+        protected RootInfo doInBackground(RootInfo... roots) {
+            Preconditions.checkArgument(roots.length == 1);
+            final RootInfo currentRoot = roots[0];
+            final Collection<RootInfo> cachedRoots = mRoots.getRootsBlocking();
+            RootInfo homeRoot = null;
+            for (final RootInfo root : cachedRoots) {
+                if (root.isHome()) {
+                    homeRoot = root;
+                }
+                if (root.getUri().equals(currentRoot.getUri())) {
+                    // We don't need to change the current root as the current root was not removed.
+                    return null;
+                }
+            }
+            Preconditions.checkNotNull(homeRoot);
+            return homeRoot;
+        }
+
+        @Override
+        protected void onPostExecute(RootInfo result) {
+            if (result != null) {
+                setRoot(result);
+            }
+        }
+    }
+
     final class ItemSelectedListener implements OnItemSelectedListener {
 
         boolean mIgnoreNextNavigation;
diff --git a/packages/DocumentsUI/src/com/android/documentsui/CopyService.java b/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
index 6a5911b..34614b4 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
@@ -502,11 +502,6 @@
         // If the file is virtual, but can be converted to another format, then try to copy it
         // as such format. Also, append an extension for the target mime type (if known).
         if (srcInfo.isVirtualDocument()) {
-            if (!srcInfo.isTypedDocument()) {
-                // Impossible to copy a file which is virtual, but not typed.
-                mFailedFiles.add(srcInfo);
-                return false;
-            }
             final String[] streamTypes = getContentResolver().getStreamTypes(
                     srcInfo.derivedUri, "*/*");
             if (streamTypes != null && streamTypes.length > 0) {
@@ -516,8 +511,7 @@
                 dstDisplayName = srcInfo.displayName +
                         (extension != null ? "." + extension : srcInfo.displayName);
             } else {
-                // The provider says that it supports typed documents, but doesn't say
-                // anything about available formats.
+                // The virtual file is not available as any alternative streamable format.
                 // TODO: Log failures. b/26192412
                 mFailedFiles.add(srcInfo);
                 return false;
@@ -640,9 +634,8 @@
 
         boolean success = true;
         try {
-            // If the file is virtual, but can be converted to another format, then try to copy it
-            // as such format.
-            if (srcInfo.isVirtualDocument() && srcInfo.isTypedDocument()) {
+            // If the file is virtual, then try to copy it as an alternative format.
+            if (srcInfo.isVirtualDocument()) {
                 final AssetFileDescriptor srcFileAsAsset =
                         mSrcClient.openTypedAssetFileDescriptor(
                                 srcInfo.derivedUri, mimeType, null, canceller);
diff --git a/packages/DocumentsUI/src/com/android/documentsui/DirectoryLoader.java b/packages/DocumentsUI/src/com/android/documentsui/DirectoryLoader.java
index 4eacee5..6719b23 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/DirectoryLoader.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/DirectoryLoader.java
@@ -114,11 +114,7 @@
         if (userMode != State.MODE_UNKNOWN) {
             result.mode = userMode;
         } else {
-            if ((mDoc.flags & Document.FLAG_DIR_PREFERS_GRID) != 0) {
-                result.mode = State.MODE_GRID;
-            } else {
-                result.mode = State.MODE_LIST;
-            }
+            result.mode = State.MODE_GRID;
         }
 
         if (mUserSortOrder != State.SORT_ORDER_UNKNOWN) {
diff --git a/packages/DocumentsUI/src/com/android/documentsui/IconUtils.java b/packages/DocumentsUI/src/com/android/documentsui/IconUtils.java
index a1213d2..c28fae8 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/IconUtils.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/IconUtils.java
@@ -159,8 +159,8 @@
         add("application/vnd.sun.xml.calc.template", icon);
         add("application/x-kspread", icon);
 
-        // Text
-        icon = R.drawable.ic_doc_text;
+        // Document
+        icon = R.drawable.ic_doc_document;
         add("application/vnd.oasis.opendocument.text", icon);
         add("application/vnd.oasis.opendocument.text-master", icon);
         add("application/vnd.oasis.opendocument.text-template", icon);
diff --git a/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java b/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java
index 72ee6cbab..21e7566 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java
@@ -63,6 +63,7 @@
 
     private final Context mContext;
     private final ContentObserver mObserver;
+    private OnCacheUpdateListener mCacheUpdateListener;
 
     private final RootInfo mRecentsRoot = new RootInfo();
 
@@ -94,6 +95,10 @@
         }
     }
 
+    static interface OnCacheUpdateListener {
+        void onCacheUpdate();
+    }
+
     /**
      * Gather roots from all known storage providers.
      */
@@ -209,6 +214,13 @@
             return null;
         }
 
+        @Override
+        protected void onPostExecute(Void result) {
+            if (mCacheUpdateListener != null) {
+                mCacheUpdateListener.onCacheUpdate();
+            }
+        }
+
         private void handleDocumentsProvider(ProviderInfo info) {
             // Ignore stopped packages for now; we might query them
             // later during UI interaction.
@@ -348,6 +360,10 @@
         }
     }
 
+    public void setOnCacheUpdateListener(OnCacheUpdateListener cacheUpdateListener) {
+        mCacheUpdateListener = cacheUpdateListener;
+    }
+
     @VisibleForTesting
     static List<RootInfo> getMatchingRoots(Collection<RootInfo> roots, State state) {
         final List<RootInfo> matching = new ArrayList<>();
diff --git a/packages/DocumentsUI/src/com/android/documentsui/State.java b/packages/DocumentsUI/src/com/android/documentsui/State.java
index c81d4fb..46372c0 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/State.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/State.java
@@ -36,7 +36,7 @@
     /** Explicit user choice */
     public int userMode = MODE_UNKNOWN;
     /** Derived after loader */
-    public int derivedMode = MODE_LIST;
+    public int derivedMode = MODE_GRID;
 
     /** Explicit user choice */
     public int userSortOrder = SORT_ORDER_UNKNOWN;
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java
index 0d5e34e..9617582 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java
@@ -53,6 +53,7 @@
 import android.support.annotation.Nullable;
 import android.support.design.widget.Snackbar;
 import android.support.v7.widget.GridLayoutManager;
+import android.support.v7.widget.GridLayoutManager.SpanSizeLookup;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.support.v7.widget.RecyclerView.LayoutManager;
@@ -99,18 +100,17 @@
 import com.android.documentsui.model.DocumentInfo;
 import com.android.documentsui.model.DocumentStack;
 import com.android.documentsui.model.RootInfo;
+
 import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Set;
 
 /**
  * Display the documents inside a single directory.
  */
-public class DirectoryFragment extends Fragment {
+public class DirectoryFragment extends Fragment implements DocumentsAdapter.Environment {
 
     public static final int TYPE_NORMAL = 1;
     public static final int TYPE_SEARCH = 2;
@@ -126,7 +126,7 @@
     private static final String TAG = "DirectoryFragment";
 
     private static final int LOADER_ID = 42;
-    private static final boolean DEBUG_ENABLE_DND = true;
+    static final boolean DEBUG_ENABLE_DND = true;
 
     private static final String EXTRA_TYPE = "type";
     private static final String EXTRA_ROOT = "root";
@@ -289,7 +289,11 @@
         final RootInfo root = getArguments().getParcelable(EXTRA_ROOT);
         final DocumentInfo doc = getArguments().getParcelable(EXTRA_DOC);
 
-        mAdapter = new DocumentsAdapter();
+        mIconHelper = new IconHelper(context, state.derivedMode);
+
+        mAdapter = new SectionBreakDocumentsAdapterWrapper(
+                this, new ModelBackedDocumentsAdapter(this, mIconHelper));
+
         mRecView.setAdapter(mAdapter);
 
         GestureDetector.SimpleOnGestureListener listener =
@@ -328,12 +332,13 @@
         // into the selection manager.
         mSelectionManager = new MultiSelectManager(
                 mRecView,
+                mAdapter,
                 state.allowMultiple
                     ? MultiSelectManager.MODE_MULTIPLE
                     : MultiSelectManager.MODE_SINGLE);
         mSelectionManager.addCallback(new SelectionModeListener());
 
-        mModel = new Model(context, mAdapter);
+        mModel = new Model(context);
         mModel.addUpdateListener(mAdapter);
         mModel.addUpdateListener(mModelUpdateListener);
 
@@ -343,8 +348,6 @@
         mTuner = FragmentTuner.pick(state);
         mClipper = new DocumentClipper(context);
 
-        mIconHelper = new IconHelper(context, state.derivedMode);
-
         boolean hideGridTitles;
         if (mType == TYPE_RECENT_OPEN) {
             // Hide titles when showing recents for picking images/videos
@@ -574,7 +577,10 @@
             case MODE_GRID:
                 if (mGridLayout == null) {
                     mGridLayout = new GridLayoutManager(getContext(), mColumnCount);
-                    mGridLayout.setSpanSizeLookup(mAdapter.createSpanSizeLookup());
+                    SpanSizeLookup lookup = mAdapter.createSpanSizeLookup();
+                    if (lookup != null) {
+                        mGridLayout.setSpanSizeLookup(lookup);
+                    }
                 }
                 layout = mGridLayout;
                 break;
@@ -609,6 +615,11 @@
         return columnCount;
     }
 
+    @Override
+    public int getColumnCount() {
+        return mColumnCount;
+    }
+
     /**
      * Manages the integration between our ActionMode and MultiSelectManager, initiating
      * ActionMode when there is a selection, canceling it when there is no selection,
@@ -893,10 +904,34 @@
         }.execute(selected);
     }
 
-    private State getDisplayState() {
+    @Override
+    public void initDocumentHolder(DocumentHolder holder) {
+        holder.addClickListener(mItemClickListener);
+        holder.addOnKeyListener(mSelectionManager);
+    }
+
+    @Override
+    public void onBindDocumentHolder(DocumentHolder holder, Cursor cursor) {
+        if (DEBUG_ENABLE_DND) {
+            setupDragAndDropOnDocumentView(holder.itemView, cursor);
+        }
+    }
+
+    @Override
+    public State getDisplayState() {
         return ((BaseActivity) getActivity()).getDisplayState();
     }
 
+    @Override
+    public Model getModel() {
+        return mModel;
+    }
+
+    @Override
+    public boolean isDocumentEnabled(String docMimeType, int docFlags) {
+        return mTuner.isDocumentEnabled(docMimeType, docFlags);
+    }
+
     void showEmptyView() {
         mEmptyView.setVisibility(View.VISIBLE);
         mRecView.setVisibility(View.GONE);
@@ -920,240 +955,6 @@
         mRecView.setVisibility(View.VISIBLE);
     }
 
-    final class DocumentsAdapter
-            extends RecyclerView.Adapter<DocumentHolder>
-            implements Model.UpdateListener {
-
-        private static final String TAG = "DocumentsAdapter";
-        public static final int ITEM_TYPE_LAYOUT_DIVIDER = 0;
-        public static final int ITEM_TYPE_DOCUMENT = 1;
-        public static final int ITEM_TYPE_DIRECTORY = 2;
-
-        /**
-         * An ordered list of model IDs. This is the data structure that determines what shows up in
-         * the UI, and where.
-         */
-        private List<String> mModelIds = new ArrayList<>();
-
-        // The list is divided into two segments - directories, and everything else. Record the
-        // position where the transition happens.
-        private int mDividerPosition;
-
-        public GridLayoutManager.SpanSizeLookup createSpanSizeLookup() {
-            return new GridLayoutManager.SpanSizeLookup() {
-                @Override
-                public int getSpanSize(int position) {
-                    // Make layout whitespace span the grid. This has the effect of breaking
-                    // grid rows whenever layout whitespace is encountered.
-                    if (getItemViewType(position) == ITEM_TYPE_LAYOUT_DIVIDER) {
-                        return mColumnCount;
-                    } else {
-                        return 1;
-                    }
-                }
-            };
-        }
-
-        @Override
-        public DocumentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
-            if (viewType == ITEM_TYPE_LAYOUT_DIVIDER) {
-                return new EmptyDocumentHolder(getContext());
-            };
-
-            DocumentHolder holder = null;
-            final State state = getDisplayState();
-            switch (state.derivedMode) {
-                case MODE_GRID:
-                    switch (viewType) {
-                        case ITEM_TYPE_DIRECTORY:
-                            holder = new GridDirectoryHolder(getContext(), parent);
-                            break;
-                        case ITEM_TYPE_DOCUMENT:
-                            holder = new GridDocumentHolder(getContext(), parent, mIconHelper);
-                            break;
-                        default:
-                            throw new IllegalStateException("Unsupported layout type.");
-                    }
-                    break;
-                case MODE_LIST:
-                    holder = new ListDocumentHolder(getContext(), parent, mIconHelper);
-                    break;
-                case MODE_UNKNOWN:
-                default:
-                    throw new IllegalStateException("Unsupported layout mode.");
-            }
-
-            holder.addClickListener(mItemClickListener);
-            holder.addOnKeyListener(mSelectionManager);
-            return holder;
-        }
-
-        /**
-         * Deal with selection changed events by using a custom ItemAnimator that just changes the
-         * background color.  This works around focus issues (otherwise items lose focus when their
-         * selection state changes) but also optimizes change animations for selection.
-         */
-        @Override
-        public void onBindViewHolder(DocumentHolder holder, int position, List<Object> payload) {
-            if (holder.getItemViewType() == ITEM_TYPE_LAYOUT_DIVIDER) {
-                // Whitespace items are hidden elements with no data to bind.
-                return;
-            }
-
-            final View itemView = holder.itemView;
-
-            if (payload.contains(MultiSelectManager.SELECTION_CHANGED_MARKER)) {
-                final boolean selected = isSelected(mModelIds.get(position));
-                itemView.setActivated(selected);
-                return;
-            } else {
-                onBindViewHolder(holder, position);
-            }
-        }
-
-        @Override
-        public void onBindViewHolder(DocumentHolder holder, int position) {
-            if (holder.getItemViewType() == ITEM_TYPE_LAYOUT_DIVIDER) {
-                // Whitespace items are hidden elements with no data to bind.
-                return;
-            }
-
-            String modelId = mModelIds.get(position);
-            Cursor cursor = mModel.getItem(modelId);
-            holder.bind(cursor, modelId, getDisplayState());
-
-            final String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
-            final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
-
-            holder.setSelected(isSelected(modelId));
-            holder.setEnabled(mTuner.isDocumentEnabled(docMimeType, docFlags));
-            if (DEBUG_ENABLE_DND) {
-                setupDragAndDropOnDocumentView(holder.itemView, cursor);
-            }
-        }
-
-        @Override
-        public int getItemCount() {
-            return mModelIds.size();
-        }
-
-        @Override
-        public void onModelUpdate(Model model) {
-            mModelIds = Lists.newArrayList(model.getModelIds());
-            // Start the divider at the end. That way if the code below encounters no documents
-            // (i.e. in a directory containing only directories), the divider is placed at the end
-            // of the list, as expected.
-            mDividerPosition = mModelIds.size();
-
-            // Walk down the list of IDs till we encounter something that's not a directory, and
-            // insert a whitespace element - this introduces a visual break in the grid between
-            // folders and documents.
-            // TODO: This code makes assumptions about the model, namely, that it performs a
-            // bucketed sort where directories will always be ordered before other files.  CBB.
-            for (int i = 0; i < mModelIds.size(); ++i) {
-                final String mimeType = getCursorString(
-                        model.getItem(mModelIds.get(i)), Document.COLUMN_MIME_TYPE);
-                if (!Document.MIME_TYPE_DIR.equals(mimeType)) {
-                    mDividerPosition = i;
-                    break;
-                }
-            }
-
-            mModelIds.add(mDividerPosition, null);
-        }
-
-        @Override
-        public void onModelUpdateFailed(Exception e) {
-            if (DEBUG) Log.d(TAG, "onModelUpdateFailed called ");
-            mModelIds.clear();
-        }
-
-        /**
-         * @return The model ID of the item at the given adapter position.
-         */
-        public String getModelId(int adapterPosition) {
-            return mModelIds.get(adapterPosition);
-        }
-
-        /**
-         * Hides a set of items from the associated RecyclerView.
-         *
-         * @param ids The Model IDs of the items to hide.
-         * @return A SparseArray that maps the hidden IDs to their old positions. This can be used
-         *         to {@link #unhide} the items if necessary.
-         */
-        public SparseArray<String> hide(String... ids) {
-            Set<String> toHide = Sets.newHashSet(ids);
-
-            // Proceed backwards through the list of items, because each removal causes the
-            // positions of all subsequent items to change.
-            SparseArray<String> hiddenItems = new SparseArray<>();
-            for (int i = mModelIds.size() - 1; i >= 0; --i) {
-                String id = mModelIds.get(i);
-                if (toHide.contains(id)) {
-                    hiddenItems.put(i, mModelIds.remove(i));
-                    notifyItemRemoved(i);
-                }
-            }
-
-            return hiddenItems;
-        }
-
-        /**
-         * Unhides a set of previously hidden items.
-         *
-         * @param ids A sparse array of IDs from a previous call to {@link #hide}.
-         */
-        public void unhide(SparseArray<String> ids) {
-            // Proceed backwards through the list of items, because each addition causes the
-            // positions of all subsequent items to change.
-            for (int i = ids.size() - 1; i >= 0; --i) {
-                int pos = ids.keyAt(i);
-                String id = ids.get(pos);
-                mModelIds.add(pos, id);
-                notifyItemInserted(pos);
-            }
-        }
-
-        /**
-         * Returns a list of model IDs of items currently in the adapter. Excludes items that are
-         * currently hidden (see {@link #hide(String...)}).
-         *
-         * @return A list of Model IDs.
-         */
-        public List<String> getModelIds() {
-            return mModelIds;
-        }
-
-        @Override
-        public int getItemViewType(int position) {
-            if (position < mDividerPosition) {
-                return ITEM_TYPE_DIRECTORY;
-            } else if (position == mDividerPosition) {
-                return ITEM_TYPE_LAYOUT_DIVIDER;
-            } else {
-                return ITEM_TYPE_DOCUMENT;
-            }
-        }
-
-        /**
-         * Triggers item-change notifications by stable ID. Passing an unrecognized ID will result
-         * in a warning in logcat, but no other error.
-         *
-         * @param id
-         * @param selectionChangedMarker
-         */
-        public void notifyItemChanged(String id, String selectionChangedMarker) {
-            int position = mModelIds.indexOf(id);
-
-            if (position >= 0) {
-                notifyItemChanged(position, selectionChangedMarker);
-            } else {
-                Log.w(TAG, "Item change notification received for unknown item: " + id);
-            }
-        }
-    }
-
     private String findCommonMimeType(List<String> mimeTypes) {
         String[] commonType = mimeTypes.get(0).split("/");
         if (commonType.length != 2) {
@@ -1504,7 +1305,8 @@
         abstract void onDocumentsReady(List<DocumentInfo> docs);
     }
 
-    boolean isSelected(String modelId) {
+    @Override
+    public boolean isSelected(String modelId) {
         return mSelectionManager.getSelection().contains(modelId);
     }
 
@@ -1520,7 +1322,7 @@
         }
     }
 
-    private class ModelUpdateListener implements Model.UpdateListener {
+    private final class ModelUpdateListener implements Model.UpdateListener {
         @Override
         public void onModelUpdate(Model model) {
             if (model.info != null || model.error != null) {
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DocumentsAdapter.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DocumentsAdapter.java
new file mode 100644
index 0000000..43c2f63
--- /dev/null
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DocumentsAdapter.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.documentsui.dirlist;
+
+import static com.android.documentsui.model.DocumentInfo.getCursorString;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.provider.DocumentsContract.Document;
+import android.support.v7.widget.GridLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.util.SparseArray;
+
+import com.android.documentsui.State;
+
+import java.nio.channels.UnsupportedAddressTypeException;
+import java.util.List;
+
+/**
+ * DocumentsAdapter provides glue between a directory Model, and RecylcerView. We've
+ * abstracted this a bit in order to decompose some specialized support
+ * for adding dummy layout objects (@see SectionBreakDocumentsAdapter). Handling of the
+ * dummy layout objects was error prone when interspersed with the core mode / adapter code.
+ *
+ * @see ModelBackedDocumentsAdapter
+ * @see SectionBreakDocumentsAdapter
+ */
+abstract class DocumentsAdapter
+        extends RecyclerView.Adapter<DocumentHolder>
+        implements Model.UpdateListener {
+
+    // Payloads for notifyItemChange to distinguish between selection and other events.
+    static final String SELECTION_CHANGED_MARKER = "Selection-Changed";
+
+    /**
+     * Returns a list of model IDs of items currently in the adapter. Excludes items that are
+     * currently hidden (see {@link #hide(String...)}).
+     *
+     * @return A list of Model IDs.
+     */
+    abstract List<String> getModelIds();
+
+    /**
+     * Triggers item-change notifications by stable ID (as opposed to position).
+     * Passing an unrecognized ID will result in a warning in logcat, but no other error.
+     */
+    abstract void onItemSelectionChanged(String id);
+
+    /**
+     * @return The model ID of the item at the given adapter position.
+     */
+    abstract String getModelId(int position);
+
+    /**
+     * Hides a set of items from the associated RecyclerView.
+     *
+     * @param ids The Model IDs of the items to hide.
+     * @return A SparseArray that maps the hidden IDs to their old positions. This can be used
+     *         to {@link #unhide} the items if necessary.
+     */
+    abstract public SparseArray<String> hide(String... ids);
+
+    /**
+     * Unhides a set of previously hidden items.
+     *
+     * @param ids A sparse array of IDs from a previous call to {@link #hide}.
+     */
+    abstract void unhide(SparseArray<String> ids);
+
+    /**
+     * Returns a class that yields the span size for a particular element. This is
+     * primarily useful in {@link SectionBreakDocumentsAdapterWrapper} where
+     * we adjust sizes.
+     */
+    GridLayoutManager.SpanSizeLookup createSpanSizeLookup() {
+        throw new UnsupportedAddressTypeException();
+    }
+
+    static boolean isDirectory(Cursor cursor) {
+        final String mimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
+        return Document.MIME_TYPE_DIR.equals(mimeType);
+    }
+
+    boolean isDirectory(Model model, int position) {
+        String modelId = getModelIds().get(position);
+        Cursor cursor = model.getItem(modelId);
+        return isDirectory(cursor);
+    }
+
+    /**
+     * Environmental access for View adapter implementations.
+     */
+    interface Environment {
+        Context getContext();
+        int getColumnCount();
+        State getDisplayState();
+        boolean isSelected(String id);
+        Model getModel();
+        boolean isDocumentEnabled(String mimeType, int flags);
+        void initDocumentHolder(DocumentHolder holder);
+        void onBindDocumentHolder(DocumentHolder holder, Cursor cursor);
+    }
+}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDocumentHolder.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDocumentHolder.java
index 63c667b..5f34ac3 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDocumentHolder.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/GridDocumentHolder.java
@@ -32,6 +32,7 @@
 import android.widget.ImageView;
 import android.widget.TextView;
 
+import com.android.documentsui.IconUtils;
 import com.android.documentsui.R;
 import com.android.documentsui.RootCursorWrapper;
 import com.android.documentsui.Shared;
@@ -43,18 +44,21 @@
     final TextView mTitle;
     final TextView mDate;
     final TextView mSize;
-    final ImageView mIconMime;
+    final ImageView mIconMimeLg;
+    final ImageView mIconMimeSm;
     final ImageView mIconThumb;
     final IconHelper mIconHelper;
 
+
     public GridDocumentHolder(Context context, ViewGroup parent, IconHelper iconHelper) {
         super(context, parent, R.layout.item_doc_grid);
 
         mTitle = (TextView) itemView.findViewById(android.R.id.title);
         mDate = (TextView) itemView.findViewById(R.id.date);
         mSize = (TextView) itemView.findViewById(R.id.size);
-        mIconMime = (ImageView) itemView.findViewById(R.id.icon_mime);
+        mIconMimeLg = (ImageView) itemView.findViewById(R.id.icon_mime);
         mIconThumb = (ImageView) itemView.findViewById(R.id.icon_thumb);
+        mIconMimeSm = (ImageView) itemView.findViewById(android.R.id.icon1);
         mIconHelper = iconHelper;
     }
 
@@ -80,13 +84,15 @@
 
         mIconHelper.stopLoading(mIconThumb);
 
-        mIconMime.animate().cancel();
-        mIconMime.setAlpha(1f);
+        mIconMimeLg.animate().cancel();
+        mIconMimeLg.setAlpha(1f);
         mIconThumb.animate().cancel();
         mIconThumb.setAlpha(0f);
 
+        mIconMimeSm.setImageDrawable(IconUtils.loadMimeIcon(mContext, docMimeType));
+
         final Uri uri = DocumentsContract.buildDocumentUri(docAuthority, docId);
-        mIconHelper.loadThumbnail(uri, docMimeType, docFlags, docIcon, mIconThumb, mIconMime);
+        mIconHelper.loadThumbnail(uri, docMimeType, docFlags, docIcon, mIconThumb, mIconMimeLg);
 
         if (mHideTitles) {
             mTitle.setVisibility(View.GONE);
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/Model.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/Model.java
index bea38c6..f2bade5 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/Model.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/Model.java
@@ -35,7 +35,6 @@
 import android.provider.DocumentsContract.Document;
 import android.support.annotation.Nullable;
 import android.support.annotation.VisibleForTesting;
-import android.support.v7.widget.RecyclerView;
 import android.util.Log;
 
 import com.android.documentsui.BaseActivity.SiblingProvider;
@@ -74,7 +73,7 @@
     @Nullable String info;
     @Nullable String error;
 
-    Model(Context context, RecyclerView.Adapter<?> viewAdapter) {
+    Model(Context context) {
         mContext = context;
     }
 
@@ -87,8 +86,19 @@
     private static String createModelId(Cursor c) {
         // TODO: Maybe more efficient to use just the document ID, in cases where there is only one
         // authority (which should be the majority of cases).
-        return getCursorString(c, RootCursorWrapper.COLUMN_AUTHORITY) +
-                "|" + getCursorString(c, Document.COLUMN_DOCUMENT_ID);
+        return createModelId(
+                getCursorString(c, RootCursorWrapper.COLUMN_AUTHORITY),
+                getCursorString(c, Document.COLUMN_DOCUMENT_ID));
+    }
+
+    /**
+     * Generates a Model ID for a cursor entry that refers to a document. The Model ID is a unique
+     * string that can be used to identify the document referred to by the cursor.
+     *
+     * @param c A cursor that refers to a document.
+     */
+    static String createModelId(String authority, String docId) {
+        return authority + "|" + docId;
     }
 
     private void notifyUpdateListeners() {
@@ -404,8 +414,14 @@
 
         @Override
         protected Void doInBackground(Selection... selected) {
-            List<DocumentInfo> toDelete = getDocuments(selected[0]);
-            mHadTrouble = false;
+            List<DocumentInfo> toDelete = null;
+            try {
+                toDelete = getDocuments(selected[0]);
+            } catch (NullPointerException e) {
+                Log.w(TAG, "Failed to retrieve documents for delete.");
+                mHadTrouble = true;
+                return null;
+            }
 
             for (DocumentInfo doc : toDelete) {
                 if (!doc.isDeleteSupported()) {
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java
new file mode 100644
index 0000000..68756a3
--- /dev/null
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapter.java
@@ -0,0 +1,230 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.documentsui.dirlist;
+
+import static com.android.documentsui.Shared.DEBUG;
+import static com.android.documentsui.State.MODE_GRID;
+import static com.android.documentsui.State.MODE_LIST;
+import static com.android.documentsui.State.MODE_UNKNOWN;
+import static com.android.documentsui.model.DocumentInfo.getCursorInt;
+import static com.android.documentsui.model.DocumentInfo.getCursorString;
+
+import android.database.Cursor;
+import android.provider.DocumentsContract.Document;
+import android.util.Log;
+import android.util.SparseArray;
+import android.view.ViewGroup;
+
+import com.android.documentsui.State;
+
+import com.google.common.collect.Sets;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Adapts from dirlist.Model to something RecyclerView understands.
+ */
+final class ModelBackedDocumentsAdapter extends DocumentsAdapter {
+
+    private static final String TAG = "ModelBackedDocumentsAdapter";
+    public static final int ITEM_TYPE_DOCUMENT = 1;
+    public static final int ITEM_TYPE_DIRECTORY = 2;
+
+    // Provides access to information needed when creating and view holders. This
+    // isn't an ideal pattern (more transitive dependency stuff) but good enough for now.
+    private final Environment mEnv;
+    private final IconHelper mIconHelper;  // a transitive dependency of the holders.
+
+    /**
+     * An ordered list of model IDs. This is the data structure that determines what shows up in
+     * the UI, and where.
+     */
+    private List<String> mModelIds = new ArrayList<>();
+
+    // List of files that have been deleted. Some transient directory updates
+    // may happen while files are being deleted. During this time we don't
+    // want once-hidden files to be re-shown. We only remove
+    // items from this list when we get a model update where the model
+    // does not contain a corresponding id. This ensures hidden entries
+    // don't momentarily re-appear if we get intermediate updates from
+    // the file system.
+    private Set<String> mHiddenIds = new HashSet<>();
+
+    public ModelBackedDocumentsAdapter(Environment env, IconHelper iconHelper) {
+        mEnv = env;
+        mIconHelper = iconHelper;
+    }
+
+    @Override
+    public DocumentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+        DocumentHolder holder = null;
+        final State state = mEnv.getDisplayState();
+        switch (state.derivedMode) {
+            case MODE_GRID:
+                switch (viewType) {
+                    case ITEM_TYPE_DIRECTORY:
+                        holder = new GridDirectoryHolder(mEnv.getContext(), parent);
+                        break;
+                    case ITEM_TYPE_DOCUMENT:
+                        holder = new GridDocumentHolder(mEnv.getContext(), parent, mIconHelper);
+                        break;
+                    default:
+                        throw new IllegalStateException("Unsupported layout type.");
+                }
+                break;
+            case MODE_LIST:
+                holder = new ListDocumentHolder(mEnv.getContext(), parent, mIconHelper);
+                break;
+            case MODE_UNKNOWN:
+            default:
+                throw new IllegalStateException("Unsupported layout mode.");
+        }
+
+        mEnv.initDocumentHolder(holder);
+        return holder;
+    }
+
+    @Override
+    public void onBindViewHolder(DocumentHolder holder, int position, List<Object> payload) {
+        if (payload.contains(SELECTION_CHANGED_MARKER)) {
+            final boolean selected = mEnv.isSelected(mModelIds.get(position));
+            holder.setSelected(selected);
+        } else {
+            onBindViewHolder(holder, position);
+        }
+    }
+
+    @Override
+    public void onBindViewHolder(DocumentHolder holder, int position) {
+        String modelId = mModelIds.get(position);
+        Cursor cursor = mEnv.getModel().getItem(modelId);
+        holder.bind(cursor, modelId, mEnv.getDisplayState());
+
+        final String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
+        final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
+
+        holder.setSelected(mEnv.isSelected(modelId));
+        holder.setEnabled(mEnv.isDocumentEnabled(docMimeType, docFlags));
+
+        mEnv.onBindDocumentHolder(holder, cursor);
+    }
+
+    @Override
+    public int getItemCount() {
+        return mModelIds.size();
+    }
+
+    @Override
+    public void onModelUpdate(Model model) {
+        if (DEBUG && mHiddenIds.size() > 0) {
+            Log.d(TAG, "Updating model with hidden ids: " + mHiddenIds);
+        }
+
+        List<String> modelIds = model.getModelIds();
+        mModelIds = new ArrayList<>(modelIds.size());
+        for (String id : modelIds) {
+            if (!mHiddenIds.contains(id)) {
+                mModelIds.add(id);
+            } else {
+                if (DEBUG) Log.d(TAG, "Omitting hidden id from model during update: " + id);
+            }
+        }
+
+        // Finally remove any hidden ids that aren't present in the model.
+        // This assumes that model updates represent a complete set of files.
+        mHiddenIds.retainAll(mModelIds);
+    }
+
+    @Override
+    public void onModelUpdateFailed(Exception e) {
+        Log.w(TAG, "Model update failed.", e);
+        mModelIds.clear();
+    }
+
+    @Override
+    public String getModelId(int adapterPosition) {
+        return mModelIds.get(adapterPosition);
+    }
+
+    @Override
+    public SparseArray<String> hide(String... ids) {
+        if (DEBUG) Log.d(TAG, "Hiding ids: " + ids);
+        Set<String> toHide = Sets.newHashSet(ids);
+
+        // Proceed backwards through the list of items, because each removal causes the
+        // positions of all subsequent items to change.
+        SparseArray<String> hiddenItems = new SparseArray<>();
+        for (int i = mModelIds.size() - 1; i >= 0; --i) {
+            String id = mModelIds.get(i);
+            if (toHide.contains(id)) {
+                mHiddenIds.add(id);
+                hiddenItems.put(i, mModelIds.remove(i));
+                notifyItemRemoved(i);
+            }
+        }
+
+        return hiddenItems;
+    }
+
+    @Override
+    public void unhide(SparseArray<String> ids) {
+        if (DEBUG) Log.d(TAG, "Un-iding ids: " + ids);
+
+        // An ArrayList can shrink at runtime...and in fact
+        // it does when we clear it completely.
+        // This means we can't call add(pos, id) without
+        // first checking the list size.
+        List<String> oldIds = mModelIds;
+        mModelIds = new ArrayList<>(oldIds.size() + ids.size());
+        mModelIds.addAll(oldIds);
+
+        // Finally insert the unhidden items.
+        for (int i = 0; i < ids.size(); i++) {
+            int pos = ids.keyAt(i);
+            String id = ids.get(pos);
+            mHiddenIds.remove(id);
+            mModelIds.add(pos, id);
+            notifyItemInserted(pos);
+        }
+    }
+
+    @Override
+    public List<String> getModelIds() {
+        return mModelIds;
+    }
+
+    @Override
+    public int getItemViewType(int position) {
+        return isDirectory(mEnv.getModel(), position)
+                ? ITEM_TYPE_DIRECTORY
+                : ITEM_TYPE_DOCUMENT;
+    }
+
+    @Override
+    public void onItemSelectionChanged(String id) {
+        int position = mModelIds.indexOf(id);
+
+        if (position >= 0) {
+            notifyItemChanged(position, SELECTION_CHANGED_MARKER);
+        } else {
+            Log.w(TAG, "Item change notification received for unknown item: " + id);
+        }
+    }
+}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/MultiSelectManager.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/MultiSelectManager.java
index e47af67..5f317ff 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/MultiSelectManager.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/MultiSelectManager.java
@@ -68,24 +68,23 @@
 
     private final Selection mSelection = new Selection();
 
-    private Range mRanger;
-    private SelectionEnvironment mEnvironment;
-
+    private final SelectionEnvironment mEnvironment;
+    private final DocumentsAdapter mAdapter;
     private final List<MultiSelectManager.Callback> mCallbacks = new ArrayList<>(1);
 
+    private Range mRanger;
     private boolean mSingleSelect;
 
-    // Payloads for notifyItemChange to distinguish between selection and other events.
-    public static final String SELECTION_CHANGED_MARKER = "Selection-Changed";
-
     @Nullable private BandController mBandManager;
 
+
     /**
      * @param recyclerView
      * @param mode Selection mode
      */
-    public MultiSelectManager(final RecyclerView recyclerView, int mode) {
-        this(new RuntimeSelectionEnvironment(recyclerView), mode);
+    public MultiSelectManager(
+            final RecyclerView recyclerView, DocumentsAdapter adapter, int mode) {
+        this(new RuntimeSelectionEnvironment(recyclerView), adapter, mode);
 
         if (mode == MODE_MULTIPLE) {
             mBandManager = new BandController();
@@ -136,11 +135,12 @@
      * @hide
      */
     @VisibleForTesting
-    MultiSelectManager(SelectionEnvironment environment, int mode) {
+    MultiSelectManager(SelectionEnvironment environment, DocumentsAdapter adapter, int mode) {
         mEnvironment = checkNotNull(environment, "'environment' cannot be null.");
+        mAdapter = checkNotNull(adapter, "'adapter' cannot be null.");
         mSingleSelect = mode == MODE_SINGLE;
 
-        mEnvironment.registerDataObserver(
+        mAdapter.registerAdapterDataObserver(
                 new RecyclerView.AdapterDataObserver() {
 
                     private List<String> mModelIds;
@@ -149,7 +149,7 @@
                     public void onChanged() {
                         // TODO: This is causing b/22765812
                         mSelection.clear();
-                        mModelIds = mEnvironment.getModelIds();
+                        mModelIds = mAdapter.getModelIds();
                     }
 
                     @Override
@@ -339,7 +339,10 @@
             if (DEBUG) Log.d(TAG, "Ignoring toggle for element with no position.");
             return;
         }
-        toggleSelection(mEnvironment.getModelIdFromAdapterPosition(position));
+        String id = mAdapter.getModelId(position);
+        if (id != null) {
+            toggleSelection(id);
+        }
     }
 
     /**
@@ -348,6 +351,7 @@
      * @param modelId
      */
     public void toggleSelection(String modelId) {
+        checkNotNull(modelId);
         boolean changed = false;
         if (mSelection.contains(modelId)) {
             changed = attemptDeselect(modelId);
@@ -387,7 +391,7 @@
             return;
         }
 
-        if (mSelection.contains(mEnvironment.getModelIdFromAdapterPosition(position))) {
+        if (mSelection.contains(mAdapter.getModelId(position))) {
             mRanger = new Range(position);
         }
     }
@@ -404,7 +408,11 @@
     private void updateRange(int begin, int end, boolean selected) {
         checkState(end >= begin);
         for (int i = begin; i <= end; i++) {
-            String id = mEnvironment.getModelIdFromAdapterPosition(i);
+            String id = mAdapter.getModelId(i);
+            if (id == null) {
+                continue;
+            }
+
             if (selected) {
                 boolean canSelect = notifyBeforeItemStateChange(id, true);
                 if (canSelect) {
@@ -436,6 +444,7 @@
      * @return True if the update was applied.
      */
     private boolean attemptDeselect(String id) {
+        checkArgument(id != null);
         if (notifyBeforeItemStateChange(id, false)) {
             mSelection.remove(id);
             notifyItemStateChanged(id, false);
@@ -462,11 +471,12 @@
      * (identified by {@code position}) changes.
      */
     private void notifyItemStateChanged(String id, boolean selected) {
+        checkArgument(id != null);
         int lastListener = mCallbacks.size() - 1;
         for (int i = lastListener; i > -1; i--) {
             mCallbacks.get(i).onItemStateChanged(id, selected);
         }
-        mEnvironment.notifyItemChanged(id);
+        mAdapter.onItemSelectionChanged(id);
     }
 
     /**
@@ -613,7 +623,7 @@
          * @param id
          * @return true if the position is currently selected.
          */
-        public boolean contains(String id) {
+        public boolean contains(@Nullable String id) {
             return mTotalSelection.contains(id);
         }
 
@@ -804,11 +814,6 @@
         int getChildCount();
         int getVisibleChildCount();
         void focusItem(int position);
-        String getModelIdFromAdapterPosition(int position);
-        int getItemCount();
-        List<String> getModelIds();
-        void notifyItemChanged(String id);
-        void registerDataObserver(RecyclerView.AdapterDataObserver observer);
     }
 
     /** Recycler view facade implementation backed by good ol' RecyclerView. */
@@ -818,11 +823,9 @@
         private final Drawable mBand;
 
         private boolean mIsOverlayShown = false;
-        private DirectoryFragment.DocumentsAdapter mAdapter;
 
-        RuntimeSelectionEnvironment(RecyclerView rv) {
-            mView = rv;
-            mAdapter = (DirectoryFragment.DocumentsAdapter) rv.getAdapter();
+        RuntimeSelectionEnvironment(RecyclerView view) {
+            mView = view;
             mBand = mView.getContext().getTheme().getDrawable(R.drawable.band_select_overlay);
         }
 
@@ -841,11 +844,6 @@
         }
 
         @Override
-        public String getModelIdFromAdapterPosition(int position) {
-            return mAdapter.getModelId(position);
-        }
-
-        @Override
         public void addOnScrollListener(RecyclerView.OnScrollListener listener) {
             mView.addOnScrollListener(listener);
         }
@@ -947,40 +945,31 @@
             if (vh != null) {
                 vh.itemView.requestFocus();
             } else {
-                // Don't smooth scroll; that taxes the system unnecessarily and makes the scroll
-                // handling logic below more complicated.  See b/24865658.
-                mView.scrollToPosition(pos);
+                mView.smoothScrollToPosition(pos);
                 // Set a one-time listener to request focus when the scroll has completed.
                 mView.addOnScrollListener(
                     new RecyclerView.OnScrollListener() {
                         @Override
-                        public void onScrolled(RecyclerView view, int dx, int dy) {
-                            view.findViewHolderForAdapterPosition(pos).itemView.requestFocus();
-                            view.removeOnScrollListener(this);
+                        public void onScrollStateChanged (RecyclerView view, int newState) {
+                            if (newState == RecyclerView.SCROLL_STATE_IDLE) {
+                                // When scrolling stops, find the item and focus it.
+                                RecyclerView.ViewHolder vh =
+                                        view.findViewHolderForAdapterPosition(pos);
+                                if (vh != null) {
+                                    vh.itemView.requestFocus();
+                                } else {
+                                    // This might happen in weird corner cases, e.g. if the user is
+                                    // scrolling while a delete operation is in progress.  In that
+                                    // case, just don't attempt to focus the missing item.
+                                    Log.w(
+                                        TAG, "Unable to focus position " + pos + " after a scroll");
+                                }
+                                view.removeOnScrollListener(this);
+                            }
                         }
                     });
             }
         }
-
-        @Override
-        public void notifyItemChanged(String id) {
-            mAdapter.notifyItemChanged(id, SELECTION_CHANGED_MARKER);
-        }
-
-        @Override
-        public int getItemCount() {
-            return mAdapter.getItemCount();
-        }
-
-        @Override
-        public void registerDataObserver(RecyclerView.AdapterDataObserver observer) {
-            mAdapter.registerAdapterDataObserver(observer);
-        }
-
-        @Override
-        public List<String> getModelIds() {
-            return mAdapter.getModelIds();
-        }
     }
 
     public interface Callback {
@@ -1037,7 +1026,7 @@
             mModelBuilder = new Runnable() {
                 @Override
                 public void run() {
-                    mModel = new GridModel(mEnvironment);
+                    mModel = new GridModel(mEnvironment, mAdapter);
                     mModel.addOnSelectionChangedListener(BandController.this);
                 }
             };
@@ -1088,7 +1077,7 @@
             return !isActive()
                     && e.isMouseEvent()  // a mouse
                     && e.isActionDown()  // the initial button press
-                    && mEnvironment.getItemCount() > 0
+                    && mAdapter.getItemCount() > 0
                     && e.getItemPosition() == RecyclerView.NO_ID;  // in empty space
         }
 
@@ -1165,7 +1154,7 @@
             mModel.endSelection();
             int firstSelected = mModel.getPositionNearestOrigin();
             if (firstSelected != NOT_SET) {
-                if (mSelection.contains(mEnvironment.getModelIdFromAdapterPosition(firstSelected))) {
+                if (mSelection.contains(mAdapter.getModelId(firstSelected))) {
                     // TODO: firstSelected should really be lastSelected, we want to anchor the item
                     // where the mouse-up occurred.
                     setSelectionRangeBegin(firstSelected);
@@ -1327,6 +1316,8 @@
         private static final int LOWER_RIGHT = LOWER | RIGHT;
 
         private final SelectionEnvironment mHelper;
+        private final DocumentsAdapter mAdapter;
+
         private final List<OnSelectionChangedListener> mOnSelectionChangedListeners =
                 new ArrayList<>();
 
@@ -1364,8 +1355,9 @@
         // should expand from when Shift+click is used.
         private int mPositionNearestOrigin = NOT_SET;
 
-        GridModel(SelectionEnvironment helper) {
+        GridModel(SelectionEnvironment helper, DocumentsAdapter adapter) {
             mHelper = helper;
+            mAdapter = adapter;
             mHelper.addOnScrollListener(this);
         }
 
@@ -1568,7 +1560,7 @@
                     // position. Use a sentry value to prevent erroneously selecting item 0.
                     int position = items.get(items.keyAt(row), NOT_SET);
                     if (position != NOT_SET) {
-                        String id = mHelper.getModelIdFromAdapterPosition(position);
+                        String id = mAdapter.getModelId(position);
                         if (id != null) {
                             // The adapter inserts items for UI layout purposes that aren't associated
                             // with files.  Those will have a null model ID.  Don't select them.
@@ -1977,7 +1969,7 @@
         if (keyCode == KeyEvent.KEYCODE_MOVE_HOME) {
             position = 0;
         } else if (keyCode == KeyEvent.KEYCODE_MOVE_END) {
-            position = mEnvironment.getItemCount() - 1;
+            position = mAdapter.getItemCount() - 1;
         } else {
             // Find a navigation target based on the arrow key that the user pressed.  Ignore
             // navigation targets that aren't items in the recycler view.
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/SectionBreakDocumentsAdapterWrapper.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/SectionBreakDocumentsAdapterWrapper.java
new file mode 100644
index 0000000..b4782f0
--- /dev/null
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/SectionBreakDocumentsAdapterWrapper.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.documentsui.dirlist;
+
+import static com.android.internal.util.Preconditions.checkArgument;
+
+import android.support.v7.widget.GridLayoutManager;
+import android.support.v7.widget.RecyclerView.AdapterDataObserver;
+import android.util.SparseArray;
+import android.view.ViewGroup;
+
+import java.util.List;
+
+/**
+ * Adapter wrapper that inserts a sort of line break item between directories and regular files.
+ * Only needs to be used in GRID mode...at this time.
+ */
+final class SectionBreakDocumentsAdapterWrapper extends DocumentsAdapter {
+
+    private static final String TAG = "SectionBreakDocumentsAdapterWrapper";
+    private static final int ITEM_TYPE_SECTION_BREAK = Integer.MAX_VALUE;
+
+    private final Environment mEnv;
+    private final DocumentsAdapter mDelegate;
+
+    private int mBreakPosition = -1;
+
+    SectionBreakDocumentsAdapterWrapper(Environment environment, DocumentsAdapter delegate) {
+        mEnv = environment;
+        mDelegate = delegate;
+
+        // Relay events published by our delegate to our listeners (presumably RecyclerView)
+        // with adjusted positions.
+        mDelegate.registerAdapterDataObserver(new EventRelay());
+    }
+
+    public GridLayoutManager.SpanSizeLookup createSpanSizeLookup() {
+        return new GridLayoutManager.SpanSizeLookup() {
+            @Override
+            public int getSpanSize(int position) {
+                // Make layout whitespace span the grid. This has the effect of breaking
+                // grid rows whenever layout whitespace is encountered.
+                if (getItemViewType(position) == ITEM_TYPE_SECTION_BREAK) {
+                    return mEnv.getColumnCount();
+                } else {
+                    return 1;
+                }
+            }
+        };
+    }
+
+    @Override
+    public DocumentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+        if (viewType == ITEM_TYPE_SECTION_BREAK) {
+            return new EmptyDocumentHolder(mEnv.getContext());
+        } else {
+            return mDelegate.createViewHolder(parent, viewType);
+        }
+    }
+
+    @Override
+    public void onBindViewHolder(DocumentHolder holder, int p, List<Object> payload) {
+        if (holder.getItemViewType() != ITEM_TYPE_SECTION_BREAK) {
+            mDelegate.onBindViewHolder(holder, toDelegatePosition(p), payload);
+        }
+    }
+
+    @Override
+    public void onBindViewHolder(DocumentHolder holder, int p) {
+        if (holder.getItemViewType() != ITEM_TYPE_SECTION_BREAK) {
+            mDelegate.onBindViewHolder(holder, toDelegatePosition(p));
+        }
+    }
+
+    @Override
+    public int getItemCount() {
+        return mBreakPosition == -1
+                ? mDelegate.getItemCount()
+                : mDelegate.getItemCount() + 1;
+    }
+
+    @Override
+    public void onModelUpdate(Model model) {
+        mDelegate.onModelUpdate(model);
+        mBreakPosition = -1;
+
+        // Walk down the list of IDs till we encounter something that's not a directory, and
+        // insert a whitespace element - this introduces a visual break in the grid between
+        // folders and documents.
+        // TODO: This code makes assumptions about the model, namely, that it performs a
+        // bucketed sort where directories will always be ordered before other files. CBB.
+        List<String> modelIds = mDelegate.getModelIds();
+        for (int i = 0; i < modelIds.size(); i++) {
+            if (!isDirectory(model, i)) {
+                mBreakPosition = i;
+                break;
+            }
+        }
+    }
+
+    @Override
+    public void onModelUpdateFailed(Exception e) {
+        mDelegate.onModelUpdateFailed(e);
+    }
+
+    @Override
+    public int getItemViewType(int p) {
+        if (p == mBreakPosition) {
+            return ITEM_TYPE_SECTION_BREAK;
+        } else {
+            return mDelegate.getItemViewType(toDelegatePosition(p));
+        }
+    }
+
+    /**
+     * Returns the position of an item in the delegate, adjusting
+     * values that are greater than the break position.
+     *
+     * @param p Position within the view
+     * @return Position within the delegate
+     */
+    private int toDelegatePosition(int p) {
+        return (mBreakPosition != -1 && p > mBreakPosition) ? p - 1 : p;
+    }
+
+    /**
+     * Returns the position of an item in the view, adjusting
+     * values that are greater than the break position.
+     *
+     * @param p Position within the delegate
+     * @return Position within the view
+     */
+    private int toViewPosition(int p) {
+        // If position is greater than or equal to the break, increase by one.
+        return (mBreakPosition != -1 && p >= mBreakPosition) ? p + 1 : p;
+    }
+
+    @Override
+    public SparseArray<String> hide(String... ids) {
+        // NOTE: We hear about these changes and adjust break position
+        // in our AdapterDataObserver.
+        return mDelegate.hide(ids);
+    }
+
+    @Override
+    void unhide(SparseArray<String> ids) {
+        // NOTE: We hear about these changes and adjust break position
+        // in our AdapterDataObserver.
+        mDelegate.unhide(ids);
+    }
+
+    @Override
+    List<String> getModelIds() {
+        return mDelegate.getModelIds();
+    }
+
+    @Override
+    String getModelId(int p) {
+        return (p == mBreakPosition) ? null : mDelegate.getModelId(toDelegatePosition(p));
+    }
+
+    @Override
+    public void onItemSelectionChanged(String id) {
+        mDelegate.onItemSelectionChanged(id);
+    }
+
+    // Listener we add to our delegate. This allows us to relay events published
+    // by the delegate to our listeners (presumably RecyclerView) with adjusted positions.
+    private final class EventRelay extends AdapterDataObserver {
+        public void onChanged() {
+            throw new UnsupportedOperationException();
+        }
+
+        public void onItemRangeChanged(int positionStart, int itemCount) {
+            throw new UnsupportedOperationException();
+        }
+
+        public void onItemRangeChanged(int positionStart, int itemCount, Object payload) {
+            checkArgument(itemCount == 1);
+            notifyItemRangeChanged(toViewPosition(positionStart), itemCount, payload);
+        }
+
+        public void onItemRangeInserted(int positionStart, int itemCount) {
+            checkArgument(itemCount == 1);
+            if (positionStart < mBreakPosition) {
+                mBreakPosition++;
+            }
+            notifyItemRangeInserted(toViewPosition(positionStart), itemCount);
+        }
+
+        public void onItemRangeRemoved(int positionStart, int itemCount) {
+            checkArgument(itemCount == 1);
+            if (positionStart < mBreakPosition) {
+                mBreakPosition--;
+            }
+            notifyItemRangeRemoved(toViewPosition(positionStart), itemCount);
+        }
+
+        public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
+            throw new UnsupportedOperationException();
+        }
+    }
+}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java b/packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java
index 215c6e6..83df18c 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java
@@ -255,10 +255,6 @@
         return (flags & Document.FLAG_VIRTUAL_DOCUMENT) != 0;
     }
 
-    public boolean isTypedDocument() {
-        return (flags & Document.FLAG_SUPPORTS_TYPED_DOCUMENT) != 0;
-    }
-
     public int hashCode() {
         return derivedUri.hashCode() + mimeType.hashCode();
     }
diff --git a/packages/DocumentsUI/src/com/android/documentsui/model/RootInfo.java b/packages/DocumentsUI/src/com/android/documentsui/model/RootInfo.java
index 4caa891..12c0b8f 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/model/RootInfo.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/model/RootInfo.java
@@ -174,7 +174,7 @@
             derivedIcon = R.drawable.ic_root_home;
             derivedType = TYPE_LOCAL;
         } else if (isExternalStorage()) {
-            derivedIcon = R.drawable.ic_root_sdcard;
+            derivedIcon = R.drawable.ic_root_smartphone;
             derivedType = TYPE_LOCAL;
         } else if (isDownloads()) {
             derivedIcon = R.drawable.ic_root_download;
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/CopyServiceTest.java b/packages/DocumentsUI/tests/src/com/android/documentsui/CopyServiceTest.java
index 24a8113..4ce0185 100644
--- a/packages/DocumentsUI/tests/src/com/android/documentsui/CopyServiceTest.java
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/CopyServiceTest.java
@@ -311,10 +311,8 @@
 
     public void testCopyVirtualNonTypedFile() throws Exception {
         String srcPath = "/non-typed.sth";
-        // Empty stream types causes the FLAG_SUPPORTS_TYPED_DOCUMENT to be not set.
-        ArrayList<String> streamTypes = new ArrayList<>();
         Uri testFile = mStorage.createVirtualFile(SRC_ROOT, srcPath, "virtual/mime-type",
-                streamTypes, "I love Tokyo!".getBytes());
+                null /* streamTypes */, "I love Tokyo!".getBytes());
 
         Intent intent = createCopyIntent(Lists.newArrayList(testFile));
         startService(intent);
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/StubProvider.java b/packages/DocumentsUI/tests/src/com/android/documentsui/StubProvider.java
index 2c311a7..50f4628 100644
--- a/packages/DocumentsUI/tests/src/com/android/documentsui/StubProvider.java
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/StubProvider.java
@@ -316,12 +316,9 @@
             String documentId, String mimeTypeFilter, Bundle opts, CancellationSignal signal)
             throws FileNotFoundException {
         final StubDocument document = mStorage.get(documentId);
-        if (document == null || !document.file.isFile()) {
+        if (document == null || !document.file.isFile() || document.streamTypes == null) {
             throw new FileNotFoundException();
         }
-        if ((document.flags & Document.FLAG_SUPPORTS_TYPED_DOCUMENT) == 0) {
-            throw new IllegalStateException("Tried to open a non-typed document as typed.");
-        }
         for (final String mimeType : document.streamTypes) {
             // Strict compare won't accept wildcards, but that's OK for tests, as DocumentsUI
             // doesn't use them for getStreamTypes nor openTypedDocument.
@@ -349,13 +346,13 @@
             throw new IllegalArgumentException(
                     "The provided Uri is incorrect, or the file is gone.");
         }
-        if ((document.flags & Document.FLAG_SUPPORTS_TYPED_DOCUMENT) == 0) {
-            return null;
-        }
         if (!"*/*".equals(mimeTypeFilter)) {
             // Not used by DocumentsUI, so don't bother implementing it.
             throw new UnsupportedOperationException();
         }
+        if (document.streamTypes == null) {
+            return null;
+        }
         return document.streamTypes.toArray(new String[document.streamTypes.size()]);
     }
 
@@ -628,9 +625,6 @@
                 File file, String mimeType, List<String> streamTypes, StubDocument parent) {
             int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE
                     | Document.FLAG_VIRTUAL_DOCUMENT;
-            if (streamTypes.size() > 0) {
-                flags |= Document.FLAG_SUPPORTS_TYPED_DOCUMENT;
-            }
             return new StubDocument(file, mimeType, streamTypes, flags, parent);
         }
 
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapterTest.java b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapterTest.java
new file mode 100644
index 0000000..5ce1823
--- /dev/null
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/ModelBackedDocumentsAdapterTest.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.documentsui.dirlist;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.support.v7.widget.RecyclerView;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.util.SparseArray;
+import android.view.ViewGroup;
+
+import com.android.documentsui.State;
+
+import java.util.List;
+
+@SmallTest
+public class ModelBackedDocumentsAdapterTest extends AndroidTestCase {
+
+    private static final String AUTHORITY = "test_authority";
+    private static final String[] NAMES = new String[] {
+            "4",
+            "foo",
+            "1",
+            "bar",
+            "*(Ljifl;a",
+            "0",
+            "baz",
+            "2",
+            "3",
+            "%$%VD"
+    };
+
+    private TestModel mModel;
+    private ModelBackedDocumentsAdapter mAdapter;
+
+    public void setUp() {
+
+        final Context testContext = TestContext.createStorageTestContext(getContext(), AUTHORITY);
+        mModel = new TestModel(testContext, AUTHORITY);
+        mModel.update(NAMES);
+
+        DocumentsAdapter.Environment env = new TestEnvironment(testContext);
+
+        mAdapter = new ModelBackedDocumentsAdapter(
+                env, new IconHelper(testContext, State.MODE_GRID));
+        mAdapter.onModelUpdate(mModel);
+    }
+
+    // Tests that the item count is correct.
+    public void testItemCount() {
+        assertEquals(mModel.getItemCount(), mAdapter.getItemCount());
+    }
+
+    // Tests that the item count is correct.
+    public void testHide_ItemCount() {
+        List<String> ids = mModel.getModelIds();
+        mAdapter.hide(ids.get(0), ids.get(1));
+        assertEquals(mModel.getItemCount() - 2, mAdapter.getItemCount());
+    }
+
+    // Tests that the items can be hidden and unhidden.
+    public void testUnhide_ItemCount() {
+        List<String> ids = mModel.getModelIds();
+        SparseArray<String> hidden = mAdapter.hide(ids.toArray(new String[ids.size()]));
+        mAdapter.unhide(hidden);
+        assertEquals(mModel.getItemCount(), mAdapter.getItemCount());
+    }
+
+    // Tests that the items can be hidden and unhidden.
+    public void testUnhide_PreservesOrder() {
+        List<String> ids = mModel.getModelIds();
+        SparseArray<String> hidden = mAdapter.hide(
+                ids.get(0), ids.get(1), ids.get(5), ids.get(9));
+        mAdapter.unhide(hidden);
+
+        // Finally ensure the restored items are in the original order
+        // by checking them against the model.
+        for (int i = 0; i < mAdapter.getItemCount(); i++) {
+            assertEquals(mModel.idForPosition(i), mAdapter.getModelId(i));
+        }
+    }
+
+    private final class TestEnvironment implements DocumentsAdapter.Environment {
+        private final Context testContext;
+
+        private TestEnvironment(Context testContext) {
+            this.testContext = testContext;
+        }
+
+        @Override
+        public boolean isSelected(String id) {
+            return false;
+        }
+
+        @Override
+        public boolean isDocumentEnabled(String mimeType, int flags) {
+            return true;
+        }
+
+        @Override
+        public void initDocumentHolder(DocumentHolder holder) {}
+
+        @Override
+        public Model getModel() {
+            return mModel;
+        }
+
+        @Override
+        public State getDisplayState() {
+            return null;
+        }
+
+        @Override
+        public Context getContext() {
+            return testContext;
+        }
+
+        @Override
+        public int getColumnCount() {
+            return 4;
+        }
+
+        @Override
+        public void onBindDocumentHolder(DocumentHolder holder, Cursor cursor) {}
+    }
+
+    private static class DummyListener implements Model.UpdateListener {
+        public void onModelUpdate(Model model) {}
+        public void onModelUpdateFailed(Exception e) {}
+    }
+
+    private static class DummyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+        public int getItemCount() { return 0; }
+        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {}
+        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+            return null;
+        }
+    }
+}
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/ModelTest.java b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/ModelTest.java
index 121eb41..bed7c9c 100644
--- a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/ModelTest.java
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/ModelTest.java
@@ -21,16 +21,10 @@
 import android.content.ContextWrapper;
 import android.database.Cursor;
 import android.database.MatrixCursor;
-import android.net.Uri;
-import android.os.Bundle;
-import android.provider.DocumentsContract;
 import android.provider.DocumentsContract.Document;
-import android.support.v7.widget.RecyclerView;
 import android.test.AndroidTestCase;
-import android.test.mock.MockContentProvider;
 import android.test.mock.MockContentResolver;
 import android.test.suitebuilder.annotation.SmallTest;
-import android.view.ViewGroup;
 
 import com.android.documentsui.DirectoryResult;
 import com.android.documentsui.RootCursorWrapper;
@@ -49,6 +43,7 @@
 
     private static final int ITEM_COUNT = 10;
     private static final String AUTHORITY = "test_authority";
+
     private static final String[] COLUMNS = new String[]{
         RootCursorWrapper.COLUMN_AUTHORITY,
         Document.COLUMN_DOCUMENT_ID,
@@ -57,23 +52,24 @@
         Document.COLUMN_SIZE,
         Document.COLUMN_MIME_TYPE
     };
-    private static Cursor cursor;
 
+    private static final String[] NAMES = new String[] {
+            "4",
+            "foo",
+            "1",
+            "bar",
+            "*(Ljifl;a",
+            "0",
+            "baz",
+            "2",
+            "3",
+            "%$%VD"
+        };
+
+    private Cursor cursor;
     private Context context;
     private Model model;
     private TestContentProvider provider;
-    private static final String[] NAMES = new String[] {
-        "4",
-        "foo",
-        "1",
-        "bar",
-        "*(Ljifl;a",
-        "0",
-        "baz",
-        "2",
-        "3",
-        "%$%VD"
-    };
 
     public void setUp() {
         setupTestContext();
@@ -97,7 +93,7 @@
         r.cursor = cursor;
 
         // Instantiate the model with a dummy view adapter and listener that (for now) do nothing.
-        model = new Model(context, new DummyAdapter());
+        model = new Model(context);
         model.addUpdateListener(new DummyListener());
         model.update(r);
     }
@@ -326,32 +322,4 @@
         public void onModelUpdate(Model model) {}
         public void onModelUpdateFailed(Exception e) {}
     }
-
-    private static class DummyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
-        public int getItemCount() { return 0; }
-        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {}
-        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
-            return null;
-        }
-    }
-
-    private static class TestContentProvider extends MockContentProvider {
-        List<Uri> mDeleted = new ArrayList<>();
-
-        @Override
-        public Bundle call(String method, String arg, Bundle extras) {
-            // Intercept and log delete method calls.
-            if (DocumentsContract.METHOD_DELETE_DOCUMENT.equals(method)) {
-                final Uri documentUri = extras.getParcelable(DocumentsContract.EXTRA_URI);
-                mDeleted.add(documentUri);
-                return new Bundle();
-            } else {
-                return super.call(method, arg, extras);
-            }
-        }
-
-        public void assertWasDeleted(DocumentInfo doc) {
-            assertTrue(mDeleted.contains(doc.derivedUri));
-        }
-    }
 }
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/MultiSelectManagerTest.java b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/MultiSelectManagerTest.java
index 5989135..e06199e 100644
--- a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/MultiSelectManagerTest.java
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/MultiSelectManagerTest.java
@@ -23,6 +23,7 @@
 
 import com.android.documentsui.TestInputEvent;
 import com.android.documentsui.dirlist.MultiSelectManager.Selection;
+
 import com.google.common.collect.Lists;
 
 import java.util.ArrayList;
@@ -44,11 +45,13 @@
     private MultiSelectManager mManager;
     private TestCallback mCallback;
     private TestSelectionEnvironment mEnv;
+    private TestDocumentsAdapter mAdapter;
 
     public void setUp() throws Exception {
         mCallback = new TestCallback();
         mEnv = new TestSelectionEnvironment(items);
-        mManager = new MultiSelectManager(mEnv, MultiSelectManager.MODE_MULTIPLE);
+        mAdapter = new TestDocumentsAdapter(items);
+        mManager = new MultiSelectManager(mEnv, mAdapter, MultiSelectManager.MODE_MULTIPLE);
         mManager.addCallback(mCallback);
     }
 
@@ -164,7 +167,7 @@
     }
 
     public void testSingleSelectMode() {
-        mManager = new MultiSelectManager(mEnv, MultiSelectManager.MODE_SINGLE);
+        mManager = new MultiSelectManager(mEnv, mAdapter, MultiSelectManager.MODE_SINGLE);
         mManager.addCallback(mCallback);
         longPress(20);
         tap(13);
@@ -172,7 +175,7 @@
     }
 
     public void testSingleSelectMode_ShiftTap() {
-        mManager = new MultiSelectManager(mEnv, MultiSelectManager.MODE_SINGLE);
+        mManager = new MultiSelectManager(mEnv, mAdapter, MultiSelectManager.MODE_SINGLE);
         mManager.addCallback(mCallback);
         longPress(13);
         shiftTap(20);
@@ -180,7 +183,7 @@
     }
 
     public void testSingleSelectMode_ShiftDoesNotExtendSelection() {
-        mManager = new MultiSelectManager(mEnv, MultiSelectManager.MODE_SINGLE);
+        mManager = new MultiSelectManager(mEnv, mAdapter, MultiSelectManager.MODE_SINGLE);
         mManager.addCallback(mCallback);
         longPress(20);
         keyToPosition(22, true);
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/MultiSelectManager_GridModelTest.java b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/MultiSelectManager_GridModelTest.java
index 3d6923f..5c04db9 100644
--- a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/MultiSelectManager_GridModelTest.java
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/MultiSelectManager_GridModelTest.java
@@ -20,7 +20,6 @@
 
 import android.graphics.Point;
 import android.graphics.Rect;
-import android.support.v7.widget.RecyclerView.AdapterDataObserver;
 import android.support.v7.widget.RecyclerView.OnScrollListener;
 import android.test.AndroidTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
@@ -28,7 +27,7 @@
 
 import com.android.documentsui.dirlist.MultiSelectManager.GridModel;
 
-import java.util.List;
+import java.util.ArrayList;
 import java.util.Set;
 
 @SmallTest
@@ -38,15 +37,28 @@
     private static final int CHILD_VIEW_EDGE_PX = 100;
     private static final int VIEWPORT_HEIGHT = 500;
 
-    private static GridModel model;
-    private static TestEnvironment env;
-    private static Set<String> lastSelection;
-    private static int viewWidth;
+    private GridModel model;
+    private TestEnvironment env;
+    private TestDocumentsAdapter adapter;
+    private Set<String> lastSelection;
+    private int viewWidth;
 
-    private static void setUp(int numChildren, int numColumns) {
+    private void initData(final int numChildren, int numColumns) {
         env = new TestEnvironment(numChildren, numColumns);
+        adapter = new TestDocumentsAdapter(new ArrayList<String>()) {
+            @Override
+            public String getModelId(int position) {
+                return Integer.toString(position);
+            }
+
+            @Override
+            public int getItemCount() {
+                return numChildren;
+            }
+        };
+
         viewWidth = VIEW_PADDING_PX + numColumns * (VIEW_PADDING_PX + CHILD_VIEW_EDGE_PX);
-        model = new GridModel(env);
+        model = new GridModel(env, adapter);
         model.addOnSelectionChangedListener(
                 new GridModel.OnSelectionChangedListener() {
                     @Override
@@ -64,7 +76,7 @@
     }
 
     public void testSelectionLeftOfItems() {
-        setUp(20, 5);
+        initData(20, 5);
         model.startSelection(new Point(0, 10));
         model.resizeSelection(new Point(1, 11));
         assertSelected();
@@ -72,7 +84,7 @@
     }
 
     public void testSelectionRightOfItems() {
-        setUp(20, 4);
+        initData(20, 4);
         model.startSelection(new Point(viewWidth - 1, 10));
         model.resizeSelection(new Point(viewWidth - 2, 11));
         assertSelected();
@@ -80,7 +92,7 @@
     }
 
     public void testSelectionAboveItems() {
-        setUp(20, 4);
+        initData(20, 4);
         model.startSelection(new Point(10, 0));
         model.resizeSelection(new Point(11, 1));
         assertSelected();
@@ -88,7 +100,7 @@
     }
 
     public void testSelectionBelowItems() {
-        setUp(5, 4);
+        initData(5, 4);
         model.startSelection(new Point(10, VIEWPORT_HEIGHT - 1));
         model.resizeSelection(new Point(11, VIEWPORT_HEIGHT - 2));
         assertSelected();
@@ -96,7 +108,7 @@
     }
 
     public void testVerticalSelectionBetweenItems() {
-        setUp(20, 4);
+        initData(20, 4);
         model.startSelection(new Point(106, 0));
         model.resizeSelection(new Point(107, 200));
         assertSelected();
@@ -104,7 +116,7 @@
     }
 
     public void testHorizontalSelectionBetweenItems() {
-        setUp(20, 4);
+        initData(20, 4);
         model.startSelection(new Point(0, 105));
         model.resizeSelection(new Point(200, 106));
         assertSelected();
@@ -112,7 +124,7 @@
     }
 
     public void testGrowingAndShrinkingSelection() {
-        setUp(20, 4);
+        initData(20, 4);
         model.startSelection(new Point(0, 0));
         model.resizeSelection(new Point(5, 5));
         assertSelected(0);
@@ -142,7 +154,7 @@
     }
 
     public void testSelectionMovingAroundOrigin() {
-        setUp(16, 4);
+        initData(16, 4);
         model.startSelection(new Point(210, 210));
         model.resizeSelection(new Point(viewWidth - 1, 0));
         assertSelected(2, 3, 6, 7);
@@ -156,7 +168,7 @@
     }
 
     public void testScrollingBandSelect() {
-        setUp(40, 4);
+        initData(40, 4);
         model.startSelection(new Point(0, 0));
         model.resizeSelection(new Point(100, VIEWPORT_HEIGHT - 1));
         assertSelected(0, 4, 8, 12, 16);
@@ -173,14 +185,14 @@
         assertEquals(0, model.getPositionNearestOrigin());
     }
 
-    private static void assertSelected(int... selectedPositions) {
+    private void assertSelected(int... selectedPositions) {
         assertEquals(selectedPositions.length, lastSelection.size());
         for (int position : selectedPositions) {
             assertTrue(lastSelection.contains(Integer.toString(position)));
         }
     }
 
-    private static void scroll(int dy) {
+    private void scroll(int dy) {
         assertTrue(env.verticalOffset + VIEWPORT_HEIGHT + dy <= env.getTotalHeight());
         env.verticalOffset += dy;
         model.onScrolled(null, 0, dy);
@@ -322,30 +334,5 @@
         public void focusItem(int i) {
             throw new UnsupportedOperationException();
         }
-
-        @Override
-        public String getModelIdFromAdapterPosition(int position) {
-            return Integer.toString(position);
-        }
-
-        @Override
-        public int getItemCount() {
-            return mNumChildren;
-        }
-
-        @Override
-        public List<String> getModelIds() {
-            return null;
-        }
-
-        @Override
-        public void notifyItemChanged(String id) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public void registerDataObserver(AdapterDataObserver observer) {
-            throw new UnsupportedOperationException();
-        }
     }
 }
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestContentProvider.java b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestContentProvider.java
new file mode 100644
index 0000000..c8d424f
--- /dev/null
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestContentProvider.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.documentsui.dirlist;
+
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.DocumentsContract;
+import android.test.mock.MockContentProvider;
+
+import com.android.documentsui.model.DocumentInfo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A very simple test double for ContentProvider. Useful in this package only.
+ */
+class TestContentProvider extends MockContentProvider {
+    List<Uri> mDeleted = new ArrayList<>();
+
+    @Override
+    public Bundle call(String method, String arg, Bundle extras) {
+        // Intercept and log delete method calls.
+        if (DocumentsContract.METHOD_DELETE_DOCUMENT.equals(method)) {
+            final Uri documentUri = extras.getParcelable(DocumentsContract.EXTRA_URI);
+            mDeleted.add(documentUri);
+            return new Bundle();
+        } else {
+            return super.call(method, arg, extras);
+        }
+    }
+
+    public void assertWasDeleted(DocumentInfo doc) {
+        ModelTest.assertTrue(mDeleted.contains(doc.derivedUri));
+    }
+}
\ No newline at end of file
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestContext.java b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestContext.java
new file mode 100644
index 0000000..714062d
--- /dev/null
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestContext.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.documentsui.dirlist;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.ContextWrapper;
+import android.test.mock.MockContentResolver;
+
+public final class TestContext {
+
+    /**
+     * Returns a Context configured with test provider for authority.
+     */
+    static Context createStorageTestContext(Context context, String authority) {
+        final MockContentResolver testResolver = new MockContentResolver();
+        TestContentProvider provider = new TestContentProvider();
+        testResolver.addProvider(authority, provider);
+
+        return new ContextWrapper(context) {
+            @Override
+            public ContentResolver getContentResolver() {
+                return testResolver;
+            }
+        };
+    }
+}
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestDocumentsAdapter.java b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestDocumentsAdapter.java
new file mode 100644
index 0000000..267f47d
--- /dev/null
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestDocumentsAdapter.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.documentsui.dirlist;
+
+import android.util.SparseArray;
+import android.view.ViewGroup;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A skeletal {@link DocumentsAdapter} test double.
+ */
+public class TestDocumentsAdapter extends DocumentsAdapter {
+
+    List<String> mModelIds = new ArrayList<>();
+
+    public TestDocumentsAdapter(List<String> modelIds) {
+        mModelIds = modelIds;
+    }
+
+    @Override
+    public void onModelUpdate(Model model) {
+    }
+
+    @Override
+    public void onModelUpdateFailed(Exception e) {
+    }
+
+    @Override
+    List<String> getModelIds() {
+        return mModelIds;
+    }
+
+    @Override
+    void onItemSelectionChanged(String id) {
+    }
+
+    @Override
+    String getModelId(int position) {
+        return mModelIds.get(position);
+    }
+
+    @Override
+    public SparseArray<String> hide(String... ids) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    void unhide(SparseArray<String> ids) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public DocumentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void onBindViewHolder(DocumentHolder holder, int position) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public int getItemCount() {
+        return mModelIds.size();
+    }
+}
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestModel.java b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestModel.java
new file mode 100644
index 0000000..3a537a6
--- /dev/null
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestModel.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.documentsui.dirlist;
+
+import android.content.Context;
+import android.database.MatrixCursor;
+import android.provider.DocumentsContract.Document;
+
+import com.android.documentsui.DirectoryResult;
+import com.android.documentsui.RootCursorWrapper;
+import com.android.documentsui.dirlist.MultiSelectManager.Selection;
+
+import java.util.Random;
+import java.util.Set;
+
+public class TestModel extends Model {
+
+    private static final String[] COLUMNS = new String[]{
+        RootCursorWrapper.COLUMN_AUTHORITY,
+        Document.COLUMN_DOCUMENT_ID,
+        Document.COLUMN_FLAGS,
+        Document.COLUMN_DISPLAY_NAME,
+        Document.COLUMN_SIZE,
+        Document.COLUMN_MIME_TYPE
+    };
+
+    private final String mAuthority;
+    private Set<String> mDeleted;
+
+    /**
+     * Creates a new context. context must be configured with provider for authority.
+     * @see TestContext#createStorageTestContext(Context, String).
+     */
+    public TestModel(Context context, String authority) {
+        super(context);
+        mAuthority = authority;
+    }
+
+    void update(String... names) {
+        Random rand = new Random();
+
+        MatrixCursor c = new MatrixCursor(COLUMNS);
+        for (int i = 0; i < names.length; i++) {
+            MatrixCursor.RowBuilder row = c.newRow();
+            row.add(RootCursorWrapper.COLUMN_AUTHORITY, mAuthority);
+            row.add(Document.COLUMN_DOCUMENT_ID, Integer.toString(i));
+            row.add(Document.COLUMN_FLAGS, Document.FLAG_SUPPORTS_DELETE);
+            // Generate random document names and sizes. This forces the model's internal sort code
+            // to actually do something.
+            row.add(Document.COLUMN_DISPLAY_NAME, names[i]);
+            row.add(Document.COLUMN_SIZE, rand.nextInt());
+        }
+
+        DirectoryResult r = new DirectoryResult();
+        r.cursor = c;
+        update(r);
+    }
+
+    // Note that model id includes authority qualifier and is distinct
+    // WRT documentId because of this.
+    String idForPosition(int p) {
+        return createModelId(mAuthority, Integer.toString(p));
+    }
+
+    @Override
+    public void delete(Selection selected, DeletionListener listener) {
+        for (String id : selected.getAll()) {
+            mDeleted.add(id);
+        }
+        listener.onCompletion();
+    }
+}
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestSelectionEnvironment.java b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestSelectionEnvironment.java
index fc85f2b..c4cfd3a 100644
--- a/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestSelectionEnvironment.java
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/dirlist/TestSelectionEnvironment.java
@@ -18,7 +18,6 @@
 
 import android.graphics.Point;
 import android.graphics.Rect;
-import android.support.v7.widget.RecyclerView.AdapterDataObserver;
 import android.support.v7.widget.RecyclerView.OnScrollListener;
 import android.view.View;
 
@@ -28,10 +27,7 @@
 
 public class TestSelectionEnvironment implements SelectionEnvironment {
 
-    private List<String> mItems;
-
     public TestSelectionEnvironment(List<String> items) {
-        mItems = items;
     }
 
     @Override
@@ -114,27 +110,4 @@
     @Override
     public void focusItem(int position) {
     }
-
-    @Override
-    public String getModelIdFromAdapterPosition(int position) {
-        return mItems.get(position);
-    }
-
-    @Override
-    public int getItemCount() {
-        return mItems.size();
-    }
-
-    @Override
-    public List<String> getModelIds() {
-        return null;
-    }
-
-    @Override
-    public void notifyItemChanged(String id) {
-    }
-
-    @Override
-    public void registerDataObserver(AdapterDataObserver observer) {
-    }
 }
diff --git a/packages/MtpDocumentsProvider/jni/com_android_mtp_AppFuse.cpp b/packages/MtpDocumentsProvider/jni/com_android_mtp_AppFuse.cpp
index f592a1f..f9fb85c 100644
--- a/packages/MtpDocumentsProvider/jni/com_android_mtp_AppFuse.cpp
+++ b/packages/MtpDocumentsProvider/jni/com_android_mtp_AppFuse.cpp
@@ -30,15 +30,13 @@
 #include "jni.h"
 #include "JNIHelp.h"
 #include "android_runtime/AndroidRuntime.h"
+#include "nativehelper/ScopedPrimitiveArray.h"
 
 namespace {
 
-constexpr int min(int a, int b) {
-    return a < b ? a : b;
-}
-
 // Maximum number of bytes to write in one request.
 constexpr size_t MAX_WRITE = 256 * 1024;
+constexpr size_t NUM_MAX_HANDLES = 1024;
 
 // Largest possible request.
 // The request size is bounded by the maximum size of a FUSE_WRITE request
@@ -47,6 +45,8 @@
         sizeof(struct fuse_write_in) + MAX_WRITE;
 
 static jclass app_fuse_class;
+static jmethodID app_fuse_get_file_size;
+static jmethodID app_fuse_get_object_bytes;
 
 struct FuseRequest {
     char buffer[MAX_REQUEST_SIZE];
@@ -79,15 +79,25 @@
  * The class is used to access AppFuse class in Java from fuse handlers.
  */
 class AppFuse {
+    JNIEnv* env_;
+    jobject self_;
+
+    // Map between file handle and inode.
+    std::map<uint32_t, uint64_t> handles_;
+    uint32_t handle_counter_;
+
 public:
-    AppFuse(JNIEnv* /*env*/, jobject /*self*/) {
-    }
+    AppFuse(JNIEnv* env, jobject self) :
+        env_(env), self_(self), handle_counter_(0) {}
 
     bool handle_fuse_request(int fd, const FuseRequest& req) {
         ALOGV("Request op=%d", req.header().opcode);
         switch (req.header().opcode) {
             // TODO: Handle more operations that are enough to provide seekable
             // FD.
+            case FUSE_LOOKUP:
+                invoke_handler(fd, req, &AppFuse::handle_fuse_lookup);
+                return true;
             case FUSE_INIT:
                 invoke_handler(fd, req, &AppFuse::handle_fuse_init);
                 return true;
@@ -96,6 +106,18 @@
                 return true;
             case FUSE_FORGET:
                 return false;
+            case FUSE_OPEN:
+                invoke_handler(fd, req, &AppFuse::handle_fuse_open);
+                return true;
+            case FUSE_READ:
+                invoke_handler(fd, req, &AppFuse::handle_fuse_read, 8192);
+                return true;
+            case FUSE_RELEASE:
+                invoke_handler(fd, req, &AppFuse::handle_fuse_release, 0);
+                return true;
+            case FUSE_FLUSH:
+                invoke_handler(fd, req, &AppFuse::handle_fuse_flush, 0);
+                return true;
             default: {
                 ALOGV("NOTIMPL op=%d uniq=%" PRIx64 " nid=%" PRIx64 "\n",
                       req.header().opcode,
@@ -108,10 +130,37 @@
     }
 
 private:
+    int handle_fuse_lookup(const fuse_in_header& header,
+                           const char* name,
+                           fuse_entry_out* out,
+                           uint32_t* /*unused*/) {
+        if (header.nodeid != 1) {
+            return -ENOENT;
+        }
+
+        const int n = atoi(name);
+        if (n == 0) {
+            return -ENOENT;
+        }
+
+        int64_t size = get_file_size(n);
+        if (size < 0) {
+            return -ENOENT;
+        }
+
+        out->nodeid = n;
+        out->attr_valid = 10;
+        out->entry_valid = 10;
+        out->attr.ino = n;
+        out->attr.mode = S_IFREG | 0777;
+        out->attr.size = size;
+        return 0;
+    }
+
     int handle_fuse_init(const fuse_in_header&,
                          const fuse_init_in* in,
                          fuse_init_out* out,
-                         size_t* reply_size) {
+                         uint32_t* reply_size) {
         // Kernel 2.6.16 is the first stable kernel with struct fuse_init_out
         // defined (fuse version 7.6). The structure is the same from 7.6 through
         // 7.22. Beginning with 7.23, the structure increased in size and added
@@ -124,7 +173,7 @@
         }
 
         // We limit ourselves to 15 because we don't handle BATCH_FORGET yet
-        out->minor = min(in->minor, 15);
+        out->minor = std::min(in->minor, 15u);
 #if defined(FUSE_COMPAT_22_INIT_OUT_SIZE)
         // FUSE_KERNEL_VERSION >= 23.
 
@@ -152,7 +201,7 @@
     int handle_fuse_getattr(const fuse_in_header& header,
                             const fuse_getattr_in* /* in */,
                             fuse_attr_out* out,
-                            size_t* /*unused*/) {
+                            uint32_t* /*unused*/) {
         if (header.nodeid != 1) {
             return -ENOENT;
         }
@@ -163,14 +212,67 @@
         return 0;
     }
 
+    int handle_fuse_open(const fuse_in_header& header,
+                         const fuse_open_in* /* in */,
+                         fuse_open_out* out,
+                         uint32_t* /*unused*/) {
+        if (handles_.size() >= NUM_MAX_HANDLES) {
+            // Too many open files.
+            return -EMFILE;
+        }
+        uint32_t handle;
+        do {
+           handle = handle_counter_++;
+        } while (handles_.count(handle) != 0);
+
+        handles_.insert(std::make_pair(handle, header.nodeid));
+        out->fh = handle;
+        return 0;
+    }
+
+    int handle_fuse_read(const fuse_in_header& /* header */,
+                         const fuse_read_in* in,
+                         void* out,
+                         uint32_t* reply_size) {
+        const std::map<uint32_t, uint64_t>::iterator it = handles_.find(in->fh);
+        if (it == handles_.end()) {
+            return -EBADF;
+        }
+        const int64_t result = get_object_bytes(
+                it->second,
+                in->offset,
+                in->size,
+                out);
+        if (result < 0) {
+            return -EIO;
+        }
+        *reply_size = static_cast<size_t>(result);
+        return 0;
+    }
+
+    int handle_fuse_release(const fuse_in_header& /* header */,
+                            const fuse_release_in* in,
+                            void* /* out */,
+                            uint32_t* /* reply_size */) {
+        handles_.erase(in->fh);
+        return 0;
+    }
+
+    int handle_fuse_flush(const fuse_in_header& /* header */,
+                          const void* /* in */,
+                          void* /* out */,
+                          uint32_t* /* reply_size */) {
+        return 0;
+    }
+
     template <typename T, typename S>
     void invoke_handler(int fd,
                         const FuseRequest& request,
                         int (AppFuse::*handler)(const fuse_in_header&,
                                                 const T*,
                                                 S*,
-                                                size_t*),
-                        size_t reply_size = sizeof(S)) {
+                                                uint32_t*),
+                        uint32_t reply_size = sizeof(S)) {
         char reply_data[reply_size];
         memset(reply_data, 0, reply_size);
         const int reply_code = (this->*handler)(
@@ -186,6 +288,39 @@
                 reply_size);
     }
 
+    int64_t get_file_size(int inode) {
+        return static_cast<int64_t>(env_->CallLongMethod(
+                self_,
+                app_fuse_get_file_size,
+                static_cast<int>(inode)));
+    }
+
+    int64_t get_object_bytes(
+            int inode,
+            uint64_t offset,
+            uint32_t size,
+            void* buf) {
+        const uint32_t read_size = static_cast<uint32_t>(std::min(
+                static_cast<uint64_t>(size),
+                get_file_size(inode) - offset));
+        const jbyteArray array = (jbyteArray) env_->CallObjectMethod(
+                self_,
+                app_fuse_get_object_bytes,
+                inode,
+                offset,
+                read_size);
+        if (array == nullptr) {
+            return -1;
+        }
+        ScopedByteArrayRO bytes(env_, array);
+        if (bytes.size() != read_size || bytes.get() == nullptr) {
+            return -1;
+        }
+
+        memcpy(buf, bytes.get(), read_size);
+        return read_size;
+    }
+
     static void fuse_reply(int fd, int unique, int reply_code, void* reply_data,
                            size_t reply_size) {
         // Don't send any data for error case.
@@ -219,6 +354,7 @@
     ALOGD("Start fuse loop.");
     while (true) {
         FuseRequest request;
+
         const ssize_t result = TEMP_FAILURE_RETRY(
                 read(fd, request.buffer, sizeof(request.buffer)));
         if (result < 0) {
@@ -272,12 +408,27 @@
         ALOGE("Can't find com/android/mtp/AppFuse");
         return -1;
     }
+
     app_fuse_class = static_cast<jclass>(env->NewGlobalRef(clazz));
     if (app_fuse_class == nullptr) {
         ALOGE("Can't obtain global reference for com/android/mtp/AppFuse");
         return -1;
     }
 
+    app_fuse_get_file_size = env->GetMethodID(
+            app_fuse_class, "getFileSize", "(I)J");
+    if (app_fuse_get_file_size == nullptr) {
+        ALOGE("Can't find getFileSize");
+        return -1;
+    }
+
+    app_fuse_get_object_bytes = env->GetMethodID(
+            app_fuse_class, "getObjectBytes", "(IJI)[B");
+    if (app_fuse_get_object_bytes == nullptr) {
+        ALOGE("Can't find getObjectBytes");
+        return -1;
+    }
+
     const int result = android::AndroidRuntime::registerNativeMethods(
             env, "com/android/mtp/AppFuse", gMethods, NELEM(gMethods));
     if (result < 0) {
diff --git a/packages/MtpDocumentsProvider/src/com/android/mtp/AppFuse.java b/packages/MtpDocumentsProvider/src/com/android/mtp/AppFuse.java
index 2c09ad1..5ffd7cf 100644
--- a/packages/MtpDocumentsProvider/src/com/android/mtp/AppFuse.java
+++ b/packages/MtpDocumentsProvider/src/com/android/mtp/AppFuse.java
@@ -17,16 +17,14 @@
 package com.android.mtp;
 
 import android.os.ParcelFileDescriptor;
+import android.os.Process;
 import android.os.storage.StorageManager;
 import android.util.Log;
-
 import com.android.internal.annotations.VisibleForTesting;
-
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 
-import android.os.Process;
-
 /**
  * TODO: Remove VisibleForTesting class.
  */
@@ -37,12 +35,14 @@
     }
 
     private final String mName;
+    private final Callback mCallback;
     private final Thread mMessageThread;
     private ParcelFileDescriptor mDeviceFd;
 
     @VisibleForTesting
-    AppFuse(String name) {
+    AppFuse(String name, Callback callback) {
         mName = name;
+        mCallback = callback;
         mMessageThread = new Thread(new Runnable() {
             @Override
             public void run() {
@@ -72,10 +72,45 @@
         }
     }
 
+    /**
+     * @param i
+     * @throws FileNotFoundException
+     */
+    @VisibleForTesting
+    public ParcelFileDescriptor openFile(int i) throws FileNotFoundException {
+        return ParcelFileDescriptor.open(new File(
+                getMountPoint(),
+                Integer.toString(i)),
+                ParcelFileDescriptor.MODE_READ_ONLY);
+    }
+
     @VisibleForTesting
     File getMountPoint() {
         return new File("/mnt/appfuse/" + Process.myUid() + "_" + mName);
     }
 
+    static interface Callback {
+        long getFileSize(int inode) throws FileNotFoundException;
+        byte[] getObjectBytes(int inode, long offset, int size) throws IOException;
+    }
+
+    @VisibleForTesting
+    private long getFileSize(int inode) {
+        try {
+            return mCallback.getFileSize(inode);
+        } catch (IOException e) {
+            return -1;
+        }
+    }
+
+    @VisibleForTesting
+    private byte[] getObjectBytes(int inode, long offset, int size) {
+        try {
+            return mCallback.getObjectBytes(inode, offset, size);
+        } catch (IOException e) {
+            return null;
+        }
+    }
+
     private native boolean native_start_app_fuse_loop(int fd);
 }
diff --git a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/AppFuseTest.java b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/AppFuseTest.java
index b66d8eb..76bd2b5 100644
--- a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/AppFuseTest.java
+++ b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/AppFuseTest.java
@@ -16,24 +16,27 @@
 
 package com.android.mtp;
 
+import android.os.ParcelFileDescriptor;
 import android.os.storage.StorageManager;
 import android.system.ErrnoException;
 import android.system.Os;
 import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.test.suitebuilder.annotation.MediumTest;
 
 import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Arrays;
 
-@SmallTest
+/**
+ * TODO: Enable this test after adding SELinux policies for appfuse.
+ */
+@MediumTest
 public class AppFuseTest extends AndroidTestCase {
-    /**
-     * TODO: Enable this test after adding SELinux policies for appfuse.
-     * @throws ErrnoException
-     * @throws InterruptedException
-     */
-    public void disabled_testBasic() throws ErrnoException, InterruptedException {
+
+    public void disabled_testMount() throws ErrnoException, InterruptedException {
         final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
-        final AppFuse appFuse = new AppFuse("test");
+        final AppFuse appFuse = new AppFuse("test", new TestCallback());
         appFuse.mount(storageManager);
         final File file = appFuse.getMountPoint();
         assertTrue(file.isDirectory());
@@ -41,4 +44,86 @@
         appFuse.close();
         assertTrue(1 != Os.stat(file.getPath()).st_ino);
     }
+
+    public void disabled_testOpenFile() throws IOException {
+        final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
+        final int INODE = 10;
+        final AppFuse appFuse = new AppFuse(
+                "test",
+                new TestCallback() {
+                    @Override
+                    public long getFileSize(int inode) throws FileNotFoundException {
+                        if (INODE == inode) {
+                            return 1024;
+                        }
+                        throw new FileNotFoundException();
+                    }
+                });
+        appFuse.mount(storageManager);
+        final ParcelFileDescriptor fd = appFuse.openFile(INODE);
+        fd.close();
+        appFuse.close();
+    }
+
+    public void disabled_testOpenFile_error() {
+        final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
+        final int INODE = 10;
+        final AppFuse appFuse = new AppFuse("test", new TestCallback());
+        appFuse.mount(storageManager);
+        try {
+            appFuse.openFile(INODE);
+            fail();
+        } catch (Throwable t) {
+            assertTrue(t instanceof FileNotFoundException);
+        }
+        appFuse.close();
+    }
+
+    public void disabled_testReadFile() throws IOException {
+        final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
+        final int INODE = 10;
+        final byte[] BYTES = new byte[] { 'a', 'b', 'c', 'd', 'e' };
+        final AppFuse appFuse = new AppFuse(
+                "test",
+                new TestCallback() {
+                    @Override
+                    public long getFileSize(int inode) throws FileNotFoundException {
+                        if (inode == INODE) {
+                            return BYTES.length;
+                        }
+                        return super.getFileSize(inode);
+                    }
+
+                    @Override
+                    public byte[] getObjectBytes(int inode, long offset, int size)
+                            throws IOException {
+                        if (inode == INODE) {
+                            return Arrays.copyOfRange(BYTES, (int) offset, (int) offset + size);
+                        }
+                        return super.getObjectBytes(inode, offset, size);
+                    }
+                });
+        appFuse.mount(storageManager);
+        final ParcelFileDescriptor fd = appFuse.openFile(INODE);
+        try (final ParcelFileDescriptor.AutoCloseInputStream stream =
+                new ParcelFileDescriptor.AutoCloseInputStream(fd)) {
+            final byte[] buffer = new byte[1024];
+            final int size = stream.read(buffer, 0, buffer.length);
+            assertEquals(5, size);
+        }
+        appFuse.close();
+    }
+
+    private static class TestCallback implements AppFuse.Callback {
+        @Override
+        public long getFileSize(int inode) throws FileNotFoundException {
+            throw new FileNotFoundException();
+        }
+
+        @Override
+        public byte[] getObjectBytes(int inode, long offset, int size)
+                throws IOException {
+            throw new IOException();
+        }
+    }
 }
diff --git a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestMtpManager.java b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestMtpManager.java
index bbd0a30..9a97659 100644
--- a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestMtpManager.java
+++ b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestMtpManager.java
@@ -203,4 +203,9 @@
         }
         return Arrays.copyOf(result, count);
     }
+
+    @Override
+    byte[] getObject(int deviceId, int objectHandle, int expectedSize) throws IOException {
+        return mImportFileBytes.get(pack(deviceId, objectHandle));
+    }
 }
diff --git a/packages/PrintSpooler/res/values/strings.xml b/packages/PrintSpooler/res/values/strings.xml
index 97a7bff..b662c58 100644
--- a/packages/PrintSpooler/res/values/strings.xml
+++ b/packages/PrintSpooler/res/values/strings.xml
@@ -178,12 +178,6 @@
     <!-- Template for the notification label for a blocked print job. [CHAR LIMIT=25] -->
     <string name="blocked_notification_title_template">Printer blocked <xliff:g id="print_job_name" example="foo.jpg">%1$s</xliff:g></string>
 
-    <!-- Template for the notification label for a composite (multiple items) print jobs notification. [CHAR LIMIT=25] -->
-    <plurals name="composite_notification_title_template">
-        <item quantity="one"><xliff:g id="print_job_name" example="foo.jpg">%1$d</xliff:g> print job</item>
-        <item quantity="other"><xliff:g id="print_job_name" example="foo.jpg">%1$d</xliff:g> print jobs</item>
-    </plurals>
-
     <!-- Label for the notification button for cancelling a print job. [CHAR LIMIT=25] -->
     <string name="cancel">Cancel</string>
 
diff --git a/packages/PrintSpooler/src/com/android/printspooler/model/NotificationController.java b/packages/PrintSpooler/src/com/android/printspooler/model/NotificationController.java
index 82fd512..0210693 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/model/NotificationController.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/model/NotificationController.java
@@ -40,6 +40,7 @@
 import android.print.PrintJobInfo;
 import android.print.PrintManager;
 import android.provider.Settings;
+import android.util.ArraySet;
 import android.util.Log;
 
 import com.android.printspooler.R;
@@ -61,13 +62,22 @@
 
     private static final String EXTRA_PRINT_JOB_ID = "EXTRA_PRINT_JOB_ID";
 
+    private static final String PRINT_JOB_NOTIFICATION_GROUP_KEY = "PRINT_JOB_NOTIFICATIONS";
+    private static final String PRINT_JOB_NOTIFICATION_SUMMARY = "PRINT_JOB_NOTIFICATIONS_SUMMARY";
+
     private final Context mContext;
     private final NotificationManager mNotificationManager;
 
+    /**
+     * Mapping from printJobIds to their notification Ids.
+     */
+    private final ArraySet<PrintJobId> mNotifications;
+
     public NotificationController(Context context) {
         mContext = context;
         mNotificationManager = (NotificationManager)
                 mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+        mNotifications = new ArraySet<>(0);
     }
 
     public void onUpdateNotifications(List<PrintJobInfo> printJobs) {
@@ -81,16 +91,44 @@
             }
         }
 
-        updateNotification(notifyPrintJobs);
+        updateNotifications(notifyPrintJobs);
     }
 
-    private void updateNotification(List<PrintJobInfo> printJobs) {
-        if (printJobs.size() <= 0) {
-            removeNotification();
-        } else if (printJobs.size() == 1) {
-            createSimpleNotification(printJobs.get(0));
-        } else {
+    /**
+     * Update notifications for the given print jobs, remove all other notifications.
+     *
+     * @param printJobs The print job that we want to create notifications for.
+     */
+    private void updateNotifications(List<PrintJobInfo> printJobs) {
+        ArraySet<PrintJobId> removedPrintJobs = new ArraySet<>(mNotifications);
+
+        final int numPrintJobs = printJobs.size();
+
+        // Create summary notification
+        if (numPrintJobs > 1) {
             createStackedNotification(printJobs);
+        } else {
+            mNotificationManager.cancel(PRINT_JOB_NOTIFICATION_SUMMARY, 0);
+        }
+
+        // Create per print job notification
+        for (int i = 0; i < numPrintJobs; i++) {
+            PrintJobInfo printJob = printJobs.get(i);
+            PrintJobId printJobId = printJob.getId();
+
+            removedPrintJobs.remove(printJobId);
+            mNotifications.add(printJobId);
+
+            createSimpleNotification(printJob);
+        }
+
+        // Remove notifications for print jobs that do not exist anymore
+        final int numRemovedPrintJobs = removedPrintJobs.size();
+        for (int i = 0; i < numRemovedPrintJobs; i++) {
+            PrintJobId removedPrintJob = removedPrintJobs.valueAt(i);
+
+            mNotificationManager.cancel(removedPrintJob.flattenToString(), 0);
+            mNotifications.remove(removedPrintJob);
         }
     }
 
@@ -148,7 +186,8 @@
                 .setOngoing(true)
                 .setShowWhen(true)
                 .setColor(mContext.getColor(
-                        com.android.internal.R.color.system_notification_accent_color));
+                        com.android.internal.R.color.system_notification_accent_color))
+                .setGroup(PRINT_JOB_NOTIFICATION_GROUP_KEY);
 
         if (firstAction != null) {
             builder.addAction(firstAction);
@@ -158,11 +197,14 @@
             builder.addAction(secondAction);
         }
 
-        if (printJob.getState() == PrintJobInfo.STATE_STARTED) {
+        if (printJob.getState() == PrintJobInfo.STATE_STARTED
+                || printJob.getState() == PrintJobInfo.STATE_QUEUED) {
             float progress = printJob.getProgress();
             if (progress >= 0) {
-                builder.setProgress(Integer.MAX_VALUE, (int)(Integer.MAX_VALUE * progress),
+                builder.setProgress(Integer.MAX_VALUE, (int) (Integer.MAX_VALUE * progress),
                         false);
+            } else {
+                builder.setProgress(Integer.MAX_VALUE, 0, true);
             }
         }
 
@@ -173,7 +215,7 @@
             builder.setContentText(printJob.getPrinterName());
         }
 
-        mNotificationManager.notify(0, builder.build());
+        mNotificationManager.notify(printJob.getId().flattenToString(), 0, builder.build());
     }
 
     private void createPrintingNotification(PrintJobInfo printJob) {
@@ -201,33 +243,36 @@
                 .setContentIntent(createContentIntent(null))
                 .setWhen(System.currentTimeMillis())
                 .setOngoing(true)
-                .setShowWhen(true);
+                .setShowWhen(true)
+                .setGroup(PRINT_JOB_NOTIFICATION_GROUP_KEY)
+                .setGroupSummary(true);
 
         final int printJobCount = printJobs.size();
 
         InboxStyle inboxStyle = new InboxStyle();
-        inboxStyle.setBigContentTitle(String.format(mContext.getResources().getQuantityText(
-                R.plurals.composite_notification_title_template,
-                printJobCount).toString(), printJobCount));
 
+        int icon = com.android.internal.R.drawable.ic_print;
         for (int i = printJobCount - 1; i>= 0; i--) {
             PrintJobInfo printJob = printJobs.get(i);
-            if (i == printJobCount - 1) {
-                builder.setLargeIcon(((BitmapDrawable) mContext.getResources().getDrawable(
-                        computeNotificationIcon(printJob), null)).getBitmap());
-                builder.setSmallIcon(computeNotificationIcon(printJob));
-                builder.setContentTitle(computeNotificationTitle(printJob));
-                builder.setContentText(printJob.getPrinterName());
-            }
+
             inboxStyle.addLine(computeNotificationTitle(printJob));
+
+            // if any print job is in an error state show an error icon for the summary
+            if (printJob.getState() == PrintJobInfo.STATE_FAILED
+                    || printJob.getState() == PrintJobInfo.STATE_BLOCKED) {
+                icon = com.android.internal.R.drawable.ic_print_error;
+            }
         }
 
+        builder.setSmallIcon(icon);
+        builder.setLargeIcon(
+                ((BitmapDrawable) mContext.getResources().getDrawable(icon, null)).getBitmap());
         builder.setNumber(printJobCount);
         builder.setStyle(inboxStyle);
         builder.setColor(mContext.getColor(
                 com.android.internal.R.color.system_notification_accent_color));
 
-        mNotificationManager.notify(0, builder.build());
+        mNotificationManager.notify(PRINT_JOB_NOTIFICATION_SUMMARY, 0, builder.build());
     }
 
     private String computeNotificationTitle(PrintJobInfo printJob) {
@@ -261,10 +306,6 @@
         }
     }
 
-    private void removeNotification() {
-        mNotificationManager.cancel(0);
-    }
-
     private PendingIntent createContentIntent(PrintJobId printJobId) {
         Intent intent = new Intent(Settings.ACTION_PRINT_SETTINGS);
         if (printJobId != null) {
diff --git a/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java b/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java
index 496a0b0..18160ff 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java
@@ -1416,9 +1416,9 @@
         }
 
         @Override
-        public void removeApprovedPrintService(ComponentName serviceToRemove) {
+        public void pruneApprovedPrintServices(List<ComponentName> servicesToKeep) {
             (new ApprovedPrintServices(PrintSpoolerService.this))
-                    .removeApprovedService(serviceToRemove);
+                    .pruneApprovedServices(servicesToKeep);
         }
 
         @Override
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/SelectPrinterActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/SelectPrinterActivity.java
index cdfc7ee..81727ab 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/ui/SelectPrinterActivity.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/ui/SelectPrinterActivity.java
@@ -66,6 +66,7 @@
 import android.widget.SearchView;
 import android.widget.TextView;
 
+import com.android.internal.content.PackageMonitor;
 import com.android.printspooler.R;
 
 import java.util.ArrayList;
@@ -101,7 +102,8 @@
     private AnnounceFilterResult mAnnounceFilterResult;
 
     /** Monitor if new print services get enabled or disabled */
-    private ContentObserver mPrintServicesObserver;
+    private ContentObserver mPrintServicesDisabledObserver;
+    private PackageMonitor mPackageObserver;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -245,28 +247,45 @@
      * Register listener for changes to the enabled print services.
      */
     private void registerServiceMonitor() {
-        mPrintServicesObserver = new ContentObserver(new Handler()) {
+        // Listen for services getting disabled
+        mPrintServicesDisabledObserver = new ContentObserver(new Handler()) {
             @Override
             public void onChange(boolean selfChange) {
                 onPrintServicesUpdate();
             }
         };
 
+        // Listen for services getting installed or uninstalled
+        mPackageObserver = new PackageMonitor() {
+            @Override
+            public void onPackageModified(String packageName) {
+                onPrintServicesUpdate();
+            }
+
+            @Override
+            public void onPackageRemoved(String packageName, int uid) {
+                onPrintServicesUpdate();
+            }
+
+            @Override
+            public void onPackageAdded(String packageName, int uid) {
+                onPrintServicesUpdate();
+            }
+        };
+
         getContentResolver().registerContentObserver(
-                Settings.Secure.getUriFor(Settings.Secure.ENABLED_PRINT_SERVICES), false,
-                mPrintServicesObserver);
+                Settings.Secure.getUriFor(Settings.Secure.DISABLED_PRINT_SERVICES), false,
+                mPrintServicesDisabledObserver);
+
+        mPackageObserver.register(this, getMainLooper(), false);
     }
 
     /**
-     * Unregister {@link #mPrintServicesObserver listener for changes to the enabled print services}
-     * or nothing if the listener is not registered.
+     * Unregister the listeners for changes to the enabled print services.
      */
     private void unregisterServiceMonitorIfNeeded() {
-        if (mPrintServicesObserver != null) {
-            getContentResolver().unregisterContentObserver(mPrintServicesObserver);
-
-            mPrintServicesObserver = null;
-        }
+        getContentResolver().unregisterContentObserver(mPrintServicesDisabledObserver);
+        mPackageObserver.unregister();
     }
 
     @Override
diff --git a/packages/PrintSpooler/src/com/android/printspooler/util/ApprovedPrintServices.java b/packages/PrintSpooler/src/com/android/printspooler/util/ApprovedPrintServices.java
index dd10567..a1e3ef4 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/util/ApprovedPrintServices.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/util/ApprovedPrintServices.java
@@ -23,6 +23,7 @@
 import android.printservice.PrintService;
 import android.util.ArraySet;
 
+import java.util.List;
 import java.util.Set;
 
 /**
@@ -126,29 +127,27 @@
     }
 
     /**
-     * If a {@link PrintService} is approved, remove it from the list of approved services.
+     * Remove all approved {@link PrintService print services} that are not in the given set.
      *
-     * @param serviceToRemove The {@link ComponentName} of the {@link PrintService} to be removed
+     * @param serviceNamesToKeep The {@link ComponentName names } of the services to keep
      */
-    public void removeApprovedService(ComponentName serviceToRemove) {
+    public void pruneApprovedServices(List<ComponentName> serviceNamesToKeep) {
         synchronized (sLock) {
-            if (isApprovedService(serviceToRemove)) {
-                // Copy approved services.
-                ArraySet<String> approvedServices = new ArraySet<String>(
-                        mPreferences.getStringSet(APPROVED_SERVICES_PREFERENCE, null));
+            Set<String> approvedServices = getApprovedServices();
+            Set<String> newApprovedServices = new ArraySet<>(approvedServices.size());
 
+            final int numServiceNamesToKeep = serviceNamesToKeep.size();
+            for(int i = 0; i < numServiceNamesToKeep; i++) {
+                String serviceToKeep = serviceNamesToKeep.get(i).flattenToShortString();
+                if (approvedServices.contains(serviceToKeep)) {
+                    newApprovedServices.add(serviceToKeep);
+                }
+            }
+
+            if (approvedServices.size() != newApprovedServices.size()) {
                 SharedPreferences.Editor editor = mPreferences.edit();
 
-                final int numApprovedServices = approvedServices.size();
-                for (int i = 0; i < numApprovedServices; i++) {
-                    if (approvedServices.valueAt(i)
-                            .equals(serviceToRemove.flattenToShortString())) {
-                        approvedServices.removeAt(i);
-                        break;
-                    }
-                }
-
-                editor.putStringSet(APPROVED_SERVICES_PREFERENCE, approvedServices);
+                editor.putStringSet(APPROVED_SERVICES_PREFERENCE, newApprovedServices);
                 editor.apply();
             }
         }
diff --git a/packages/SettingsLib/res/values-af/strings.xml b/packages/SettingsLib/res/values-af/strings.xml
index 0d9d79c..ebe8752 100644
--- a/packages/SettingsLib/res/values-af/strings.xml
+++ b/packages/SettingsLib/res/values-af/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Laat enige program na ekstern geskryf word, ongeag manifeswaardes"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Verplig verstelbare groottes vir aktiwiteite"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Maak grootte van alle aktiwiteite verstelbaar vir veelvuldige vensters, ongeag manifeswaardes."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Aktiveer vormvrye vensters"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Aktiveer steun vir eksperimentele vormvrye vensters."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Werkskerm-rugsteunwagwoord"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Volle rekenaarrugsteune word nie tans beskerm nie"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Raak om die wagwoord vir volledige rekenaarrugsteune te verander of te verwyder"</string>
diff --git a/packages/SettingsLib/res/values-am/strings.xml b/packages/SettingsLib/res/values-am/strings.xml
index 1c9b0a9..e33d0fa 100644
--- a/packages/SettingsLib/res/values-am/strings.xml
+++ b/packages/SettingsLib/res/values-am/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"አንጸባራቂ እሴቶች ግምት ውስጥ ሳይገቡ ማንኛውም መተግበሪያ ወደ ውጫዊ ማከማቻ ለመጻፍ ብቁ ያደርጋል።"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"እንቅስቃሴዎች ዳግመኛ እንዲመጣጠኑ አስገድድ"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"የዝርዝር ሰነድ እሴቶች ምንም ይሁኑ ምን ለበርካታ መስኮቶች ሁሉንም እንቅስቃሴዎች ዳግም የሚመጣጠኑ እንዲሆኑ ያደርጋቸዋል።"</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"የነጻ ቅርጽ መስኮቶችን ያንቁ"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"የሙከራ ነጻ ቅርጽ መስኮቶች ድጋፍን ያነቃል።"</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"የዴስክቶፕ መጠባበቂያ ይለፍ ቃል"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"ዴስክቶፕ ሙሉ ምትኬዎች በአሁኑ ሰዓት አልተጠበቁም"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"ለዴስክቶፕ ሙሉ ምትኬዎች የይለፍ ቃል ለመለወጥ ወይም ለማስወገድ ንካ"</string>
diff --git a/packages/SettingsLib/res/values-ar/strings.xml b/packages/SettingsLib/res/values-ar/strings.xml
index fc11a6b..71761b9 100644
--- a/packages/SettingsLib/res/values-ar/strings.xml
+++ b/packages/SettingsLib/res/values-ar/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"تأهيل أي تطبيق بحيث تتم كتابته على سعة تخزين خارجية، بغض النظر عن قيم البيان"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"فرض إمكانية تغيير على الأنشطة"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"لتمكين تغيير حجم جميع الأنشطة لتناسب تعدد النوافذ، بغض النظر عن قيم البيان."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"تمكين النوافذ الحرة"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"لتمكين إتاحة استخدام النوافذ الحرة التجريبية."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"كلمة مرور احتياطية للكمبيوتر"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"النسخ الاحتياطية الكاملة لسطح المكتب غير محمية في الوقت الحالي"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"المس لتغيير كلمة مرور النسخ الاحتياطية الكاملة لسطح المكتب أو إزالتها"</string>
diff --git a/packages/SettingsLib/res/values-az-rAZ/strings.xml b/packages/SettingsLib/res/values-az-rAZ/strings.xml
index 4a5ea37..b5a7181 100644
--- a/packages/SettingsLib/res/values-az-rAZ/strings.xml
+++ b/packages/SettingsLib/res/values-az-rAZ/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Seçilmiş hər hansı tətbiqi bəyannamə dəyərlərindən aslı olmayaraq xarici yaddaşa yazılabilən edir."</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Ölçü dəyişdirmək üçün məcburi fəaliyyətlər"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Bəyannamə dəyərlərindən aslı olmayaraq bütün fəaliyyətləri çoxsaylı pəncərə üçün dəyişkən ölçülü edir."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Freeform windows aktiv edin"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Sınaq üçün freeform windows aktiv edir"</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Masaüstü rezerv parolu"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Masaüstü tam rezervlər hazırda qorunmayıblar."</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Masaüstünün tam rezevr kopyalanması üçün parolu dəyişmək və ya silmək üçün toxunun"</string>
diff --git a/packages/SettingsLib/res/values-b+sr+Latn/strings.xml b/packages/SettingsLib/res/values-b+sr+Latn/strings.xml
index 676c618..54d2dfa 100644
--- a/packages/SettingsLib/res/values-b+sr+Latn/strings.xml
+++ b/packages/SettingsLib/res/values-b+sr+Latn/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Omogućava upisivanje svih aplikacija u spoljnu memoriju, bez obzira na vrednosti manifesta"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Prinudno omogući promenu veličine aktivnosti"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Omogućava promenu veličine svih aktivnosti za režim sa više prozora, bez obzira na vrednosti manifesta."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Lozinka rezervne kopije za računar"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Rezervne kopije čitavog sistema trenutno nisu zaštićene"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Dodirnite da biste promenili ili uklonili lozinku za pravljenje rezervnih kopija čitavog sistema na računaru"</string>
diff --git a/packages/SettingsLib/res/values-bg/strings.xml b/packages/SettingsLib/res/values-bg/strings.xml
index 8180261..95badc5 100644
--- a/packages/SettingsLib/res/values-bg/strings.xml
+++ b/packages/SettingsLib/res/values-bg/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Позволява прилож. да се записват във външ. хранил. независимо от стойностите в манифеста"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Възможност за преоразмеряване на активностите"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Дава възможност за преоразмеряване на всички активности в режима за няколко прозореца независимо от стойностите в манифеста."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Наст. комп.: Парола"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Понастоящем пълните резервни копия за настолен компютър не са защитени"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Докоснете, за да промените или премахнете паролата за пълни резервни копия на настолния компютър"</string>
diff --git a/packages/SettingsLib/res/values-bn-rBD/strings.xml b/packages/SettingsLib/res/values-bn-rBD/strings.xml
index a5787f5..e4d97d7 100644
--- a/packages/SettingsLib/res/values-bn-rBD/strings.xml
+++ b/packages/SettingsLib/res/values-bn-rBD/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"ম্যানিফেস্ট মানগুলি নির্বিশেষে যেকোনো অ্যাপ্লিকেশানকে বাহ্যিক সঞ্চয়স্থানে লেখার উপযুক্ত বানায়"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"আকার পরিবর্তনযোগ্য করার জন্য ক্রিয়াকলাপগুলিকে জোর করুন"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"ম্যানিফেস্ট মানগুলির নির্বিশেষে মাল্টি-উইন্ডোর জন্য সমস্ত ক্রিয়াকলাপগুলিকে আকার পরিবর্তনযোগ্য করে তোলে৷"</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"ডেস্কটপ ব্যাকআপ পাসওয়ার্ড"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"ডেস্কটপ পূর্ণ ব্যাকআপ বর্তমানে সুরক্ষিত নয়"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"ডেস্কটপ পুরো ব্যাকআপের জন্য পাসওয়ার্ড পরিবর্তন বা মুছে ফেলার জন্য স্পর্শ করুন"</string>
diff --git a/packages/SettingsLib/res/values-ca/strings.xml b/packages/SettingsLib/res/values-ca/strings.xml
index 8553ed9..93b6438 100644
--- a/packages/SettingsLib/res/values-ca/strings.xml
+++ b/packages/SettingsLib/res/values-ca/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Permet que les aplicacions es puguin escriure en un dispositiu d’emmagatzematge extern, independentment dels valors definits"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Força l\'ajust de la mida de les activitats"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Permet ajustar la mida de totes les activitats per al mode multifinestra, independentment dels valors definits."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Contrasenya per a còpies d\'ordinador"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Les còpies de seguretat d\'ordinador completes no estan protegides"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Toca per canviar o eliminar la contrasenya per a còpies de seguretat d\'ordinador completes"</string>
diff --git a/packages/SettingsLib/res/values-cs/strings.xml b/packages/SettingsLib/res/values-cs/strings.xml
index 495f10f..beb8f94 100644
--- a/packages/SettingsLib/res/values-cs/strings.xml
+++ b/packages/SettingsLib/res/values-cs/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Každou aplikaci bude možné zapsat do externího úložiště, bez ohledu na hodnoty manifestu"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Vynutit možnost změny velikosti aktivit"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Velikost všech aktivit bude možné změnit na několik oken (bez ohledu na hodnoty manifestu)."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Aktivovat okna s volným tvarem"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Aktivuje podporu experimentálních oken s volným tvarem."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Heslo pro zálohy v počítači"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Úplné zálohy v počítači nejsou v současné době chráněny"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Tuto možnost vyberte, chcete-li změnit nebo odebrat heslo pro úplné zálohy v počítači"</string>
diff --git a/packages/SettingsLib/res/values-da/strings.xml b/packages/SettingsLib/res/values-da/strings.xml
index 82654bc..3923dbd 100644
--- a/packages/SettingsLib/res/values-da/strings.xml
+++ b/packages/SettingsLib/res/values-da/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Gør det muligt at overføre enhver app til et eksternt lager uafhængigt af manifestværdier"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Tving aktiviteter til at kunne tilpasses"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Sørger for, at alle aktiviteter kan tilpasses flere vinduer uafhængigt af manifestværdier."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Aktivér vinduer i frit format"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Aktiverer understøttelse af eksperimentelle vinduer i frit format."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Kode til lokal sikkerhedskopi"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Lokale fuldstændige sikkerhedskopieringer er i øjeblikket ikke beskyttet"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Tryk for at skifte eller fjerne adgangskoden til fuld lokal sikkerhedskopiering"</string>
diff --git a/packages/SettingsLib/res/values-de/strings.xml b/packages/SettingsLib/res/values-de/strings.xml
index a2f750b..0b1238b 100644
--- a/packages/SettingsLib/res/values-de/strings.xml
+++ b/packages/SettingsLib/res/values-de/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Ermöglicht es jeder qualifizierten App, Daten auf externen Speicher zu schreiben, unabhängig von den Manifestwerten"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Anpassen der Größe von Aktivitäten erzwingen"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Ermöglicht es, die Größe aller Aktivitäten an den Mehrfenstermodus anzupassen, unabhängig von den Manifestwerten."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Desktop-Sicherungspasswort"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Vollständige Desktop-Sicherungen sind momentan nicht passwortgeschützt."</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Zum Ändern oder Entfernen des Passworts für vollständige Desktop-Sicherungen berühren"</string>
diff --git a/packages/SettingsLib/res/values-el/strings.xml b/packages/SettingsLib/res/values-el/strings.xml
index d426616..c3acca7 100644
--- a/packages/SettingsLib/res/values-el/strings.xml
+++ b/packages/SettingsLib/res/values-el/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Κάνει κάθε εφαρμογή κατάλληλη για εγγραφή σε εξωτερικό χώρο αποθήκευσης, ανεξάρτητα από τις τιμές του μανιφέστου"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Αναγκαστική δυνατότητα αλλαγής μεγέθους δραστηριοτήτων"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Να έχουν όλες οι δραστηριότητες δυνατότητα αλλαγής μεγέθους για την προβολή πολλαπλών παραθύρων, ανεξάρτητα από τις τιμές του μανιφέστου."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Ενεργοποίηση παραθύρων ελεύθερης μορφής"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Ενεργοποιεί την υποστήριξη για πειραματικά παράθυρα ελεύθερης μορφής."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Εφ/κός κωδικός desktop"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Τα πλήρη αντίγραφα ασφαλείας επιφάνειας εργασίας δεν προστατεύονται αυτήν τη στιγμή"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Αγγίξτε για αλλαγή ή κατάργηση του κωδικού πρόσβασης για τα πλήρη αντίγραφα ασφαλείας επιφάνειας εργασίας"</string>
diff --git a/packages/SettingsLib/res/values-en-rAU/strings.xml b/packages/SettingsLib/res/values-en-rAU/strings.xml
index b8c8521..dae40d9 100644
--- a/packages/SettingsLib/res/values-en-rAU/strings.xml
+++ b/packages/SettingsLib/res/values-en-rAU/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Makes any app eligible to be written to external storage, regardless of manifest values"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Force activities to be re-sizable"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Makes all activities re-sizable for multi-window, regardless of manifest values."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Desktop backup password"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Desktop full backups aren\'t currently protected"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Touch to change or remove the password for desktop full backups"</string>
diff --git a/packages/SettingsLib/res/values-en-rGB/strings.xml b/packages/SettingsLib/res/values-en-rGB/strings.xml
index b8c8521..dae40d9 100644
--- a/packages/SettingsLib/res/values-en-rGB/strings.xml
+++ b/packages/SettingsLib/res/values-en-rGB/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Makes any app eligible to be written to external storage, regardless of manifest values"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Force activities to be re-sizable"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Makes all activities re-sizable for multi-window, regardless of manifest values."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Desktop backup password"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Desktop full backups aren\'t currently protected"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Touch to change or remove the password for desktop full backups"</string>
diff --git a/packages/SettingsLib/res/values-en-rIN/strings.xml b/packages/SettingsLib/res/values-en-rIN/strings.xml
index b8c8521..dae40d9 100644
--- a/packages/SettingsLib/res/values-en-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-en-rIN/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Makes any app eligible to be written to external storage, regardless of manifest values"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Force activities to be re-sizable"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Makes all activities re-sizable for multi-window, regardless of manifest values."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Desktop backup password"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Desktop full backups aren\'t currently protected"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Touch to change or remove the password for desktop full backups"</string>
diff --git a/packages/SettingsLib/res/values-es-rUS/strings.xml b/packages/SettingsLib/res/values-es-rUS/strings.xml
index 34ebef4..855b72c 100644
--- a/packages/SettingsLib/res/values-es-rUS/strings.xml
+++ b/packages/SettingsLib/res/values-es-rUS/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Cualquier aplicación puede escribirse en una memoria externa, independientemente de los valores del manifiesto."</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Forzar actividades para que cambien de tamaño"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Permite que todas las actividades puedan cambiar de tamaño para el modo multiventana, sin importar los valores del manifiesto."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Contraseñas"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Tus copias de seguridad de escritorio no están protegidas por contraseña."</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Toca para cambiar o eliminar la contraseña de las copias de seguridad completas de tu escritorio."</string>
diff --git a/packages/SettingsLib/res/values-es/strings.xml b/packages/SettingsLib/res/values-es/strings.xml
index cedd582..858c1b6 100644
--- a/packages/SettingsLib/res/values-es/strings.xml
+++ b/packages/SettingsLib/res/values-es/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Hace que cualquier aplicación se pueda escribir en un dispositivo de almacenamiento externo, independientemente de los valores definidos"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Forzar el ajuste de tamaño de las actividades"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Permite que se pueda ajustar el tamaño de todas las actividades para el modo multiventana, independientemente de los valores establecidos."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Habilitar ventanas de forma libre"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Permite utilizar ventanas de forma libre experimentales."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Contraseña para copias de ordenador"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Las copias de seguridad completas de ordenador no están protegidas"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Tocar para cambiar o quitar la contraseña para las copias de seguridad completas de ordenador"</string>
diff --git a/packages/SettingsLib/res/values-et-rEE/strings.xml b/packages/SettingsLib/res/values-et-rEE/strings.xml
index 714004e..7f1056c 100644
--- a/packages/SettingsLib/res/values-et-rEE/strings.xml
+++ b/packages/SettingsLib/res/values-et-rEE/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Lubab rakendusi kirjutada välisesse salvestusruumi olenemata manifesti väärtustest"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Muuda tegevuste suurused muudetavaks"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Muudab kõigi tegevuste suurused mitme aknaga vaates olenemata manifesti väärtustest muudetavaks."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Luba vabas vormis aknad"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Lubatakse katseliste vabas vormis akende tugi."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Arvutivarunduse parool"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Täielikud arvutivarundused pole praegu kaitstud"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Puudutage, et muuta või eemaldada täielike arvutivarunduste parool"</string>
diff --git a/packages/SettingsLib/res/values-eu-rES/strings.xml b/packages/SettingsLib/res/values-eu-rES/strings.xml
index 7f47bf3..fe5fc29 100644
--- a/packages/SettingsLib/res/values-eu-rES/strings.xml
+++ b/packages/SettingsLib/res/values-eu-rES/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Aplikazioek kanpoko memorian idatz dezakete, manifestuaren balioak kontuan izan gabe"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Behartu jardueren tamaina doitu ahal izatea"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Manifestuan jartzen duena jartzen duela ere, jarduera guztien tamaina doitzeko aukera ematen du, hainbat leihotan erabili ahal izan daitezen."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Tokiko babeskop. pasahitza"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Une honetan, ordenagailuko babeskopia osoak ez daude babestuta."</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Ukitu ordenagailuko babeskopia osoak egiteko pasahitza aldatzeko edo kentzeko"</string>
diff --git a/packages/SettingsLib/res/values-fa/strings.xml b/packages/SettingsLib/res/values-fa/strings.xml
index 1f8b575..e1a35f7 100644
--- a/packages/SettingsLib/res/values-fa/strings.xml
+++ b/packages/SettingsLib/res/values-fa/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"بدون توجه به مقادیر مانیفست، هر برنامه‌ای را برای نوشتن در حافظه خارجی واجد شرایط می‌کند"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"اجبار فعالیت‌ها به قابل تغییر اندازه بودن"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"بدون درنظر گرفتن مقادیر مانیفست، همه فعالیت‌ها را برای چندپنجره قابل تغییر اندازه می‌کند."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"گذرواژه پشتیبان‌گیری محلی"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"پشتیبان‌گیری کامل رایانه درحال حاضر محافظت نمی‌شود"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"برای تغییر یا حذف گذرواژه برای نسخه‌های پشتیبان کامل دسک‌تاپ لمس کنید"</string>
diff --git a/packages/SettingsLib/res/values-fi/strings.xml b/packages/SettingsLib/res/values-fi/strings.xml
index e4b4b93..498f204 100644
--- a/packages/SettingsLib/res/values-fi/strings.xml
+++ b/packages/SettingsLib/res/values-fi/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Mahdollistaa sovellusten tallentamisen ulkoiseen tall.tilaan luettelosta riippumatta"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Pakota kaikki toiminnot hyväksymään koon muutos"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Pakottaa kaikki toiminnot hyväksymään koon muuttamisen rinnakkaisnäkymään luettelon arvoista riippumatta."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Varmuuskop. salasana"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Tietokoneen kaikkien tietojen varmuuskopiointia ei ole tällä hetkellä suojattu"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Muuta tai vaihda tietokoneen kaikkien tietojen varmuuskopioinnin salasana koskettamalla"</string>
diff --git a/packages/SettingsLib/res/values-fr-rCA/strings.xml b/packages/SettingsLib/res/values-fr-rCA/strings.xml
index 66c54a1..b32bfb7 100644
--- a/packages/SettingsLib/res/values-fr-rCA/strings.xml
+++ b/packages/SettingsLib/res/values-fr-rCA/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Permet enreg. d\'applis sur espace stockage externe"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Forcer les activités à être redimensionnables"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Permet de redimensionner toutes les activités pour le mode multifenêtre, indépendamment des valeurs du fichier manifeste."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Mot de passe sauvegarde PC"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Les sauvegardes complètes sur PC ne sont pas protégées actuellement."</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Appuyez pour modifier ou supprimer le mot de passe utilisé pour les sauvegardes complètes sur PC."</string>
diff --git a/packages/SettingsLib/res/values-fr/strings.xml b/packages/SettingsLib/res/values-fr/strings.xml
index e56940a..0190454 100644
--- a/packages/SettingsLib/res/values-fr/strings.xml
+++ b/packages/SettingsLib/res/values-fr/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Rend possible enregistrement de toute appli sur espace stockage externe, indépendamment valeurs fichier manifeste."</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Forcer possibilité de redimensionner les activités"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Permet de redimensionner toutes les activités pour le mode multifenêtre, indépendamment des valeurs du fichier manifeste."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Mot de passe sauvegarde PC"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Les sauvegardes complètes sur PC ne sont pas protégées actuellement."</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Appuyez pour modifier ou supprimer le mot de passe utilisé pour les sauvegardes complètes sur PC."</string>
diff --git a/packages/SettingsLib/res/values-gl-rES/strings.xml b/packages/SettingsLib/res/values-gl-rES/strings.xml
index 9bcf770..0efe805 100644
--- a/packages/SettingsLib/res/values-gl-rES/strings.xml
+++ b/packages/SettingsLib/res/values-gl-rES/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Fai que calquera aplicación se poida escribir nun almacenamento externo, independentemente dos valores expresados"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Forzar o axuste do tamaño das actividades"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Permite axustar o tamaño de todas as actividades para o modo de varias ventás, independentemente dos valores definidos."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Activar ventás de forma libre"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Activa a compatibilidade con ventás de forma libre experimentais."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Contrasinal para copias"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"As copias de seguridade de ordenador completas non están protexidas"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Toca para cambiar ou eliminar o contrasinal para as copias de seguranza completas do escritorio"</string>
diff --git a/packages/SettingsLib/res/values-gu-rIN/strings.xml b/packages/SettingsLib/res/values-gu-rIN/strings.xml
index 6dff8fa..4b72648 100644
--- a/packages/SettingsLib/res/values-gu-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-gu-rIN/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"મેનિફેસ્ટ મૂલ્યોને ધ્યાનમાં લીધા સિવાય, કોઈપણ એપ્લિકેશનને બાહ્ય સ્ટોરેજ પર લખાવા માટે લાયક બનાવે છે"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"પ્રવૃત્તિઓને ફરીથી કદ યોગ્ય થવા માટે ફરજ પાડો"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"તમામ પ્રવૃત્તિઓને મલ્ટી-વિંડો માટે ફરીથી કદ બદલી શકે તેવી બનાવે છે, મેનીફેસ્ટ મુલ્યોને ધ્યાનમાં લીધા સિવાય."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"મુક્તાકાર વિંડોઝ સક્ષમ કરો"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"પ્રાયોગિક મુક્તાકાર વિંડોઝ માટે સમર્થનને સક્ષમ કરે છે."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"ડેસ્કટૉપ બેકઅપ પાસવર્ડ"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"ડેસ્કટૉપ સંપૂર્ણ બેકઅપ હાલમાં સુરક્ષિત નથી"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"ડેસ્કટૉપ સંપૂર્ણ બેકઅપ્સ માટેનો પાસવર્ડ બદલવા અથવા દૂર કરવા માટે ટચ કરો"</string>
diff --git a/packages/SettingsLib/res/values-hi/strings.xml b/packages/SettingsLib/res/values-hi/strings.xml
index 9ce83fa..5224c38 100644
--- a/packages/SettingsLib/res/values-hi/strings.xml
+++ b/packages/SettingsLib/res/values-hi/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"इससे कोई भी ऐप मेनिफेस्‍ट मान अनदेखा करके, बाहरी मेमोरी पर लिखने योग्‍य बन जाता है"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"आकार बदले जाने के लिए गतिविधियों को बाध्य करें"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"एकाधिक-विंडो के लिए सभी गतिविधियों के आकार को बदले जाने योग्य बनाता है, चाहे मेनिफेस्ट मान कुछ भी हों."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"फ़्रीफ़ॉर्म विंडो सक्षम करें"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"प्रयोगात्मक फ़्रीफ़ॉर्म विंडो का समर्थन सक्षम करती है."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"डेस्‍कटॉप बैकअप पासवर्ड"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"डेस्‍कटॉप पूर्ण बैकअप वर्तमान में सुरक्षित नहीं हैं"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"डेस्कटॉप के पूर्ण बैकअप के पासवर्ड को बदलने या निकालने के लिए स्‍पर्श करें."</string>
diff --git a/packages/SettingsLib/res/values-hr/strings.xml b/packages/SettingsLib/res/values-hr/strings.xml
index dd02171..5cde233 100644
--- a/packages/SettingsLib/res/values-hr/strings.xml
+++ b/packages/SettingsLib/res/values-hr/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Aplikacije se mogu zapisivati u vanjsku pohranu neovisno o manifestu"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Nametni mogućnost promjene veličine za aktivnosti"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Veličina svih aktivnosti može se mijenjati za više prozora, neovisno o vrijednostima manifesta."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Zaporka sigurnosne kopije"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Potpune sigurnosne kopije na stolnom računalu trenutačno nisu zaštićene"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Odaberite za promjenu ili uklanjanje zaporke u potpunim sigurnosnim kopijama na stolnom računalu"</string>
diff --git a/packages/SettingsLib/res/values-hu/strings.xml b/packages/SettingsLib/res/values-hu/strings.xml
index 9b3a386..3559f1e 100644
--- a/packages/SettingsLib/res/values-hu/strings.xml
+++ b/packages/SettingsLib/res/values-hu/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Lehetővé teszi, hogy külső tárhelyre lehessen írni"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Tevékenységek átméretezésének kényszerítése"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Lehetővé teszi, hogy az összes tevékenység átméretezhető legyen a többablakos megjelenítés érdekében a jegyzékértékektől függetlenül."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Szabad formájú ablakok engedélyezése"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Engedélyezi a kísérleti jellegű, szabad formájú ablakok támogatását."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Asztali mentés jelszava"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Az asztali teljes biztonsági mentések jelenleg nem védettek."</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Érintse meg, ha módosítaná vagy eltávolítaná a jelszót az asztali teljes mentésekhez"</string>
diff --git a/packages/SettingsLib/res/values-hy-rAM/strings.xml b/packages/SettingsLib/res/values-hy-rAM/strings.xml
index 27db9fe..42c9a05 100644
--- a/packages/SettingsLib/res/values-hy-rAM/strings.xml
+++ b/packages/SettingsLib/res/values-hy-rAM/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Թույլ է տալիս պահել հավելվածը արտաքին սարքում՝ մանիֆեստի արժեքներից անկախ"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Ստիպել, որ ակտիվությունների չափերը լինեն փոփոխելի"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Բոլոր ակտիվությունների չափերը բազմապատուհան ռեժիմի համար դարձնել փոփոխելի՝ մանիֆեստի արժեքներից անկախ:"</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Աշխատասեղանի պահուստավորման գաղտնաբառ"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Աշխատասեղանի ամբողջական պահուստավորումները այժմ պաշտպանված չեն"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Աշխատասեղանի ամբողջական պահուստավորման համար ընտրել փոխել կամ հեռացնել գաղտնաբառը"</string>
diff --git a/packages/SettingsLib/res/values-in/strings.xml b/packages/SettingsLib/res/values-in/strings.xml
index 0cea206..6988a73 100644
--- a/packages/SettingsLib/res/values-in/strings.xml
+++ b/packages/SettingsLib/res/values-in/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Membuat semua aplikasi dapat ditulis ke penyimpanan eksterna"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Paksa aktivitas agar ukurannya dapat diubah"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Membuat semua aktivitas dapat diubah ukurannya untuk banyak jendela, terlepas dari nilai manifes."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Sandi cadangan desktop"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Saat ini cadangan desktop penuh tidak dilindungi"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Sentuh guna mengubah atau menghapus sandi untuk cadangan lengkap desktop"</string>
diff --git a/packages/SettingsLib/res/values-is-rIS/strings.xml b/packages/SettingsLib/res/values-is-rIS/strings.xml
index b3509ca..8d912e9 100644
--- a/packages/SettingsLib/res/values-is-rIS/strings.xml
+++ b/packages/SettingsLib/res/values-is-rIS/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Gerir hvaða forriti sem er kleift að skrifa í ytri geymslu, burtséð frá gildum í upplýsingaskrá"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Þvinga breytanlega stærð virkni"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Gerir stærð allrar virkni breytanlega svo að hún henti fyrir marga glugga, óháð gildum í upplýsingaskrá."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Aðgangsorð tölvuafritunar"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Heildarafritun á tölvu er ekki varin sem stendur."</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Snertu til að breyta eða fjarlægja aðgangsorðið fyrir heildarafritun á tölvu"</string>
diff --git a/packages/SettingsLib/res/values-it/strings.xml b/packages/SettingsLib/res/values-it/strings.xml
index 9f897f7..2d98a74 100644
--- a/packages/SettingsLib/res/values-it/strings.xml
+++ b/packages/SettingsLib/res/values-it/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Rende l\'app idonea all\'installaz. su mem. esterna, senza considerare i valori manifest"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Imponi formato modificabile alle attività"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Rende il formato di tutte le attività modificabile per la modalità multi-finestra, indipendentemente dai valori manifest."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Attiva finestre a forma libera"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Attiva il supporto per le finestre a forma libera sperimentali."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Password di backup desktop"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"I backup desktop completi non sono attualmente protetti."</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Tocca per modificare o rimuovere la password per i backup desktop completi"</string>
diff --git a/packages/SettingsLib/res/values-iw/strings.xml b/packages/SettingsLib/res/values-iw/strings.xml
index 2d44612..e175208 100644
--- a/packages/SettingsLib/res/values-iw/strings.xml
+++ b/packages/SettingsLib/res/values-iw/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"מאפשר כתיבה של כל אפליקציה באחסון חיצוני, ללא התחשבות בערכי המניפסט"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"אלץ יכולת קביעת גודל של הפעילויות"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"מאפשר יכולת קביעת גודל של כל הפעילויות לריבוי חלונות, ללא קשר לערך המניפסט."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"סיסמת גיבוי מקומי"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"גיבויים מלאים בשולחן העבודה אינם מוגנים כעת"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"גע כדי לשנות או להסיר את הסיסמה עבור גיבויים מלאים בשולחן העבודה"</string>
diff --git a/packages/SettingsLib/res/values-ja/strings.xml b/packages/SettingsLib/res/values-ja/strings.xml
index 81a5eaf..bf9bf8a 100644
--- a/packages/SettingsLib/res/values-ja/strings.xml
+++ b/packages/SettingsLib/res/values-ja/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"マニフェストの値に関係なく、すべてのアプリを外部ストレージに書き込めるようになります"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"アクティビティをサイズ変更可能にする"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"マニフェストの値に関係なく、マルチウィンドウですべてのアクティビティのサイズを変更できるようになります。"</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"PCバックアップパスワード"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"デスクトップのフルバックアップは現在保護されていません"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"デスクトップのフルバックアップ用のパスワードを変更または削除する場合にタップします"</string>
@@ -263,9 +267,9 @@
     <item msgid="8280754435979370728">"目に自然な色"</item>
     <item msgid="5363960654009010371">"デジタルコンテンツに最適な色"</item>
   </string-array>
-    <string name="inactive_apps_title" msgid="1317817863508274533">"無効なアプリ"</string>
-    <string name="inactive_app_inactive_summary" msgid="6768756967594202411">"無効。タップすると切り替わります。"</string>
-    <string name="inactive_app_active_summary" msgid="4512911571954375968">"有効。タップすると切り替わります。"</string>
+    <string name="inactive_apps_title" msgid="1317817863508274533">"休止中のアプリ"</string>
+    <string name="inactive_app_inactive_summary" msgid="6768756967594202411">"休止中。タップすると切り替わります。"</string>
+    <string name="inactive_app_active_summary" msgid="4512911571954375968">"実行中。タップすると切り替わります。"</string>
     <string name="runningservices_settings_title" msgid="8097287939865165213">"実行中のサービス"</string>
     <string name="runningservices_settings_summary" msgid="854608995821032748">"現在実行中のサービスを表示して制御する"</string>
     <string name="night_mode_title" msgid="2594133148531256513">"夜間モード"</string>
diff --git a/packages/SettingsLib/res/values-ka-rGE/strings.xml b/packages/SettingsLib/res/values-ka-rGE/strings.xml
index e2dfd7e..da9d204 100644
--- a/packages/SettingsLib/res/values-ka-rGE/strings.xml
+++ b/packages/SettingsLib/res/values-ka-rGE/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"აპები ჩაიწერ. გარე მეხს.-ზე აღწ. ფაილის მნიშვნ. მიუხედ."</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"ზომაცვლადი აქტივობების იძულება"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"მანიფესტის მნიშვნელობების მიუხედავად, ყველა აქტივობას მრავალი ფანჯრის რეჟიმისთვის ზომაცვლადად აქცევს."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"დესკტოპის სარეზერვო ასლის პაროლი"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"დესკტოპის სრული სარეზერვო ასლები ამჟამად დაცული არ არის"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"შეეხეთ დესკტოპის სრული სარეზერვო ასლების პაროლის შესაცვლელად ან წასაშლელად"</string>
diff --git a/packages/SettingsLib/res/values-kk-rKZ/strings.xml b/packages/SettingsLib/res/values-kk-rKZ/strings.xml
index 1b8e176..549711c 100644
--- a/packages/SettingsLib/res/values-kk-rKZ/strings.xml
+++ b/packages/SettingsLib/res/values-kk-rKZ/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Манифест мәндеріне қарамастан кез келген қолданбаны сыртқы жадқа жазуға жарамды етеді"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Әрекеттерді өлшемін өзгертуге болатын етуге мәжбүрлеу"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Манифест мәндеріне қарамастан барлық әрекеттерді бірнеше терезе үшін өлшемін өзгертуге болатын етеді."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Компьютер үстелінің сақтық көшірмесі"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Жұмыс үстелінің сақтық көшірмелері қазір қорғалмаған"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Жұмыс үстелінің толық сақтық көшірмесінің кілтсөзін өзгерту немесе жою үшін түртіңіз"</string>
diff --git a/packages/SettingsLib/res/values-km-rKH/strings.xml b/packages/SettingsLib/res/values-km-rKH/strings.xml
index 0186a68..aed4365 100644
--- a/packages/SettingsLib/res/values-km-rKH/strings.xml
+++ b/packages/SettingsLib/res/values-km-rKH/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"ធ្វើឲ្យកម្មវិធីទាំងឡាយមានសិទ្ធិសរសេរទៅកាន់ឧបករណ៍ផ្ទុកខាងក្រៅ ដោយមិនគិតពីតម្លៃជាក់លាក់"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"បង្ខំឲ្យសកម្មភាពអាចប្តូរទំហំបាន"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"កំណត់ឲ្យសកម្មភាពទាំងអស់អាចប្តូរទំហំបានសម្រាប់ពហុផ្ទាំងវិនដូ ដោយមិនគិតពីតម្លៃមេនីហ្វេសឡើយ។"</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"ពាក្យ​សម្ងាត់​បម្រុង​ទុក​លើ​ផ្ទៃតុ"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"ការ​បម្រុង​ទុក​ពេញលេញ​លើ​ផ្ទៃតុ​បច្ចុប្បន្ន​មិន​ត្រូវ​បាន​ការពារ​ទេ។"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"ប៉ះ ដើម្បី​ប្ដូរ ឬ​លុប​ពាក្យ​សម្ងាត់​សម្រាប់​ការ​បម្រុងទុក​ពេញលេញ​លើ​ផ្ទៃតុ"</string>
diff --git a/packages/SettingsLib/res/values-kn-rIN/strings.xml b/packages/SettingsLib/res/values-kn-rIN/strings.xml
index 56f4006..50e5955 100644
--- a/packages/SettingsLib/res/values-kn-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-kn-rIN/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"ಮ್ಯಾನಿಫೆಸ್ಟ್ ಮೌಲ್ಯಗಳನ್ನು ಪರಿಗಣಿಸದೇ, ಯಾವುದೇ ಅಪ್ಲಿಕೇಶನ್‌ಗೆ ಬಾಹ್ಯ ಸಂಗ್ರಹಣೆಗೆ ಬರೆಯಲು ಅರ್ಹಗೊಳಿಸುತ್ತದೆ"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"ಚಟುವಟಿಕೆಗಳನ್ನು ಮರುಗಾತ್ರಗೊಳಿಸುವಂತೆ ಒತ್ತಾಯ ಮಾಡಿ"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"ಮ್ಯಾನಿಫೆಸ್ಟ್ ಮೌಲ್ಯಗಳನ್ನು ಪರಿಗಣಿಸದೇ, ಬಹು-ವಿಂಡೊಗೆ ಎಲ್ಲಾ ಚಟುವಟಿಕೆಗಳನ್ನು ಮರುಗಾತ್ರಗೊಳಿಸುವಂತೆ ಮಾಡುತ್ತದೆ."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"ಮುಕ್ತಸ್ವರೂಪದ ವಿಂಡೊಗಳನ್ನು ಸಕ್ರಿಯಗೊಳಿಸಿ"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"ಪ್ರಾಯೋಗಿಕ ಮುಕ್ತಸ್ವರೂಪದ ವಿಂಡೊಗಳಿಗೆ ಬೆಂಬಲವನ್ನು ಸಕ್ರಿಯಗೊಳಿಸುತ್ತದೆ."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"ಡೆಸ್ಕ್‌ಟಾಪ್ ಬ್ಯಾಕಪ್ ಪಾಸ್‌ವರ್ಡ್"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"ಡೆಸ್ಕ್‌ಟಾಪ್‌‌ನ ಪೂರ್ಣ ಬ್ಯಾಕಪ್‌‌ಗಳನ್ನು ಪ್ರಸ್ತುತ ರಕ್ಷಿಸಲಾಗಿಲ್ಲ"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"ಡೆಸ್ಕ್‌ಟಾಪ್‌ನ ಪೂರ್ಣ ಬ್ಯಾಕಪ್‌ಗಳಿಗೆ ಪಾಸ್‌ವರ್ಡ್‌ ಅನ್ನು ಬದಲಾಯಿಸಲು ಅಥವಾ ತೆಗೆದುಹಾಕಲು ಸ್ಪರ್ಶಿಸಿ"</string>
diff --git a/packages/SettingsLib/res/values-ko/strings.xml b/packages/SettingsLib/res/values-ko/strings.xml
index 6ad3efd..ea5dc00 100644
--- a/packages/SettingsLib/res/values-ko/strings.xml
+++ b/packages/SettingsLib/res/values-ko/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"매니페스트 값에 관계없이 앱을 외부 저장소에 작성"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"활동의 크기가 조정 가능하도록 설정"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"모든 활동을 매니페스트 값에 관계없이 멀티 윈도우용으로 크기 조정 가능하도록 설정"</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"데스크톱 백업 비밀번호"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"데스크톱 전체 백업에 비밀번호가 설정되어 있지 않음"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"데스크톱 전체 백업에 대한 비밀번호를 변경하거나 삭제하려면 터치하세요."</string>
diff --git a/packages/SettingsLib/res/values-ky-rKG/strings.xml b/packages/SettingsLib/res/values-ky-rKG/strings.xml
index bf37ac4..6a47406 100644
--- a/packages/SettingsLib/res/values-ky-rKG/strings.xml
+++ b/packages/SettingsLib/res/values-ky-rKG/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Манифест маанилерине карабастан бардык колдонмолорду тышкы сактагычка сактоого уруксат берет"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Аракеттердин өлчөмүн өзгөртүүнү мажбурлоо"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Манифест маанилерине карабастан бардык аракеттерди мульти-терезеге өлчөмү өзгөртүлгүдөй кылат."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Компүтердеги бэкаптын сырсөзү"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Компүтердеги толук бэкап учурда корголгон эмес"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Тийип, компүтердеги толук бэкаптын сырсөзүн өзгөртүңүз же жок кылыңыз"</string>
diff --git a/packages/SettingsLib/res/values-lo-rLA/strings.xml b/packages/SettingsLib/res/values-lo-rLA/strings.xml
index 9e6a4b7..538a38c 100644
--- a/packages/SettingsLib/res/values-lo-rLA/strings.xml
+++ b/packages/SettingsLib/res/values-lo-rLA/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"ເຮັດ​ໃຫ້ທຸກແອັບ​ມີ​ສິດ​ໄດ້ຮັບການຂຽນ​ໃສ່​ບ່ອນ​ຈັດ​ເກັບ​ພາຍນອກ, ໂດຍ​ບໍ່​ຄຳ​ນຶງ​ເຖິງ​ຄ່າ​ທີ່​ຈະ​ແຈ້ງ"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"ບັງ​ຄັງ​ໃຫ້​ກິດ​ຈະ​ກຳ​ປ່ຽນ​ຂະ​ໜາດ​ໄດ້"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"ເຮັດ​ໃຫ້​ທຸກ​ກິດ​ຈະ​ກຳ​ປ່ຽນ​ຂະ​ໜາດ​ໄດ້​ສຳ​ລັບ​ຫຼາຍ​ໜ້າ​ຕ່າງ, ໂດຍ​ບໍ່​ຄຳ​ນຶງ​ເຖິງ​ຄ່າ​ທີ່​ຈະ​ແຈ້ງ."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"ລະຫັດຜ່ານການສຳຮອງຂໍ້ມູນເດັກສະທັອບ"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"ການ​ສຳຮອງ​ຂໍ້ມູນ​ເຕັມຮູບແບບ​ໃນ​ເດັກສະທັອບ​ຍັງ​ບໍ່​ໄດ້​ຮັບ​ການ​ປ້ອງກັນ​ໃນ​ເວລາ​ນີ້"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"ແຕະເພື່ອປ່ຽນ ຫຼືລຶບລະຫັດຂອງການສຳຮອງຂໍ້ມູນເຕັມຮູບແບບໃນເດັກສະທັອບ"</string>
diff --git a/packages/SettingsLib/res/values-lt/strings.xml b/packages/SettingsLib/res/values-lt/strings.xml
index 2019646..014a6fb 100644
--- a/packages/SettingsLib/res/values-lt/strings.xml
+++ b/packages/SettingsLib/res/values-lt/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Vis. pr. gal. įr. į vid. saug. nepais. apr. vert."</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Priv. nust., kad veiksm. b. g. atl. kelių d. lang."</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Nustatoma, kad visus veiksmus būtų galima atlikti kelių dydžių languose, nepaisant aprašo verčių."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Viet. atsrg. kop. slapt."</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Šiuo metu visos vietinės atsarginės kopijos neapsaugotos"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Jei norite pakeisti ar pašalinti visų vietinių atsarginių kopijų slaptažodį, palieskite"</string>
diff --git a/packages/SettingsLib/res/values-lv/strings.xml b/packages/SettingsLib/res/values-lv/strings.xml
index 2f9a83b..87da105 100644
--- a/packages/SettingsLib/res/values-lv/strings.xml
+++ b/packages/SettingsLib/res/values-lv/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Ļauj jebkuru lietotni ierakstīt ārējā krātuvē neatkarīgi no manifesta vērtības."</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Pielāgot darbības"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Pielāgo visas darbības vairāku logu režīmam neatkarīgi no vērtībām manifestā."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Datora dublējuma parole"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Darbvirsmas pilnie dublējumi pašlaik nav aizsargāti."</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Pieskarieties, lai mainītu vai noņemtu paroli pilniem darbvirsmas dublējumiem."</string>
diff --git a/packages/SettingsLib/res/values-mk-rMK/strings.xml b/packages/SettingsLib/res/values-mk-rMK/strings.xml
index 51c2568..b588c2c 100644
--- a/packages/SettingsLib/res/values-mk-rMK/strings.xml
+++ b/packages/SettingsLib/res/values-mk-rMK/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Запишува апл. во надв.меморија, незав. од манифест"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Принуди ги активностите да ја менуваат големината"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Ги прави сите активности да бидат со променлива големина за мултипрозорец, без разлика на вредностите на манифестот."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Овозможи прозорци со слободна форма"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Овозможува поддршка за експериментални прозорци со слободна форма."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Резервна лозинка за работна површина"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Целосни резервни копии на работната површина кои во моментов не се заштитени"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Допрете за да се промени или отстрани лозинката за целосна резервна копија на работната површина"</string>
diff --git a/packages/SettingsLib/res/values-ml-rIN/strings.xml b/packages/SettingsLib/res/values-ml-rIN/strings.xml
index f00103f..d76e87f 100644
--- a/packages/SettingsLib/res/values-ml-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-ml-rIN/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"മാനിഫെസ്റ്റ് മൂല്യങ്ങൾ പരിഗണിക്കാതെ, ബാഹ്യ സ്റ്റോറേജിലേക്ക് എഴുതപ്പെടുന്നതിന് ഏതൊരു ആപ്പിനെയും യോഗ്യമാക്കുന്നു"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"വലിപ്പം മാറ്റാൻ പ്രവർത്തനങ്ങളെ നിർബന്ധിക്കുക"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"മാനിഫെസ്റ്റ് മൂല്യങ്ങൾ പരിഗണിക്കാതെ, എല്ലാ പ്രവർത്തനങ്ങളെയും മൾട്ടി-വിൻഡോയ്ക്കായി വലിപ്പം മാറ്റുന്നു."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"ഡെ‌സ്‌ക്ടോപ്പ് ബാക്കപ്പ് പാസ്‌വേഡ്"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"ഡെസ്‌ക്‌ടോപ്പ് പൂർണ്ണ ബാക്കപ്പുകൾ നിലവിൽ പരിരക്ഷിച്ചിട്ടില്ല"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"ഡെസ്‌ക്‌ടോപ്പ് പൂർണ്ണ ബാക്കപ്പുകൾക്കായി പാസ്‌വേഡുകൾ മാറ്റാനോ നീക്കംചെയ്യാനോ സ്‌പർശിക്കുക"</string>
diff --git a/packages/SettingsLib/res/values-mn-rMN/strings.xml b/packages/SettingsLib/res/values-mn-rMN/strings.xml
index cc0e7cb..4aea631 100644
--- a/packages/SettingsLib/res/values-mn-rMN/strings.xml
+++ b/packages/SettingsLib/res/values-mn-rMN/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Манифест утгыг нь үл хамааран дурын апп-ыг гадаад санах ойд бичих боломжтой болгодог"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Үйл ажиллагааны хэмжээг өөрчилж болохуйц болгох"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Тодорхойлогч файлын утгыг үл хамааран, бүх үйл ажиллагааг олон цонхонд хэмжээг нь өөрчилж болохуйц болгох."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Десктоп нөөшлөлтийн нууц үг"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Десктоп бүрэн нөөцлөлт одоогоор хамгаалалтгүй байна"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Десктоп дээрх бүрэн нөөшлөлтийн нууц үгийг өөрчлөх буюу арилгахын тулд хүрнэ үү"</string>
diff --git a/packages/SettingsLib/res/values-mr-rIN/strings.xml b/packages/SettingsLib/res/values-mr-rIN/strings.xml
index b939ca0..ed57fb7 100644
--- a/packages/SettingsLib/res/values-mr-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-mr-rIN/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"मॅनिफेस्ट मूल्यांकडे दुर्लक्ष करून, कोणत्याही अॅपला बाह्य संचयनावर लेखन केले जाण्‍यासाठी पात्र बनविते"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"क्र‍ियाकलापाचा आकार बदलण्यायोग्य होण्याची सक्ती करा"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"मॅनिफेस्ट मूल्यांकडे दुर्लक्ष करून, एकाधिक-विंडोसाठी सर्व क्रियाकलापांचा आकार बदलण्यायोग्य करा"</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"freeform विंडो सक्षम करा"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"प्रायोगिक मुक्तस्वरूपाच्या विंडोसाठी समर्थन सक्षम करते."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"डेस्कटॉप बॅकअप संकेतशब्द"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"डेस्कटॉप पूर्ण बॅक अप सध्या संरक्षित नाहीत"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"डेस्कटॉपच्या पूर्ण बॅकअपसाठी असलेला संकेतशब्द बदलण्यासाठी किंवा काढून टाकण्यासाठी स्पर्श करा"</string>
diff --git a/packages/SettingsLib/res/values-ms-rMY/strings.xml b/packages/SettingsLib/res/values-ms-rMY/strings.xml
index 2e67752..1f72d04 100644
--- a/packages/SettingsLib/res/values-ms-rMY/strings.xml
+++ b/packages/SettingsLib/res/values-ms-rMY/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Menjadikan sebarang apl layak ditulis ke storan luaran, walau apa juga nilai manifesnya"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Paksa aktiviti supaya boleh diubah saiz"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Menjadikan semua aktiviti boleh diubah saiz untuk berbilang tetingkap, tanpa mengambil kira nilai manifes."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Kata laluan sandaran komputer meja"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Sandaran penuh komputer meja tidak dilindungi pada masa ini"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Sentuh untuk menukar atau mengalih keluar kata laluan untuk sandaran penuh komputer meja"</string>
diff --git a/packages/SettingsLib/res/values-my-rMM/strings.xml b/packages/SettingsLib/res/values-my-rMM/strings.xml
index 002aed1..cd4812f 100644
--- a/packages/SettingsLib/res/values-my-rMM/strings.xml
+++ b/packages/SettingsLib/res/values-my-rMM/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"ပြနေတဲ့ တန်ဖိုး ဘယ်လိုပဲရှိနေနေ၊ ဘယ် appကို မဆို အပြင် သိုလှောင်ခန်းသို့ ရေးသားခွင့် ပေးတယ်"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"လုပ်ဆောင်ချက်များ ဆိုက်ညှိရနိုင်ရန် လုပ်ခိုင်းပါ"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"မန်နီးဖက်စ် တန်ဖိုးမရွေး၊ လုပ်ဆောင်ချက် အားလုံး ဆိုက်ညှိရနိုင်အောင် လုပ်ပေးပါ။"</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Desktop အရန်စကားဝှက်"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"အလုပ်ခုံတွင် အရန်သိမ်းဆည်းခြင်းများကို လောလောဆယ် မကာကွယ်နိုင်ပါ။"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"အလုပ်ခုံ တွင် အရန်သိမ်းဆည်းခြင်းအပြည့်လုပ်ရန် အတွက် စကားဝှက်ဖယ်ရန် သို့ ပြောင်းရန် တို့ထိပါ။"</string>
diff --git a/packages/SettingsLib/res/values-nb/strings.xml b/packages/SettingsLib/res/values-nb/strings.xml
index a496a21..ae0b15d 100644
--- a/packages/SettingsLib/res/values-nb/strings.xml
+++ b/packages/SettingsLib/res/values-nb/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Gjør at apper kan skrives til ekstern lagring, uavhengig av manifestverdier"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Tving aktiviteter til å kunne endre størrelse"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Dette gjør at alle aktivitene kan endre størrelse for flervindusmodus, uavhengig av manifestverdier."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Passord for sikkerhetskopiering på datamaskin"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Fullstendig sikkerhetskopiering på datamaskin beskyttes ikke for øyeblikket."</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Trykk for å endre eller fjerne passordet for fullstendige sikkerhetskopier på datamaskinen"</string>
diff --git a/packages/SettingsLib/res/values-ne-rNP/strings.xml b/packages/SettingsLib/res/values-ne-rNP/strings.xml
index 5c85c25..5885513 100644
--- a/packages/SettingsLib/res/values-ne-rNP/strings.xml
+++ b/packages/SettingsLib/res/values-ne-rNP/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"म्यानिफेेस्टको उपेक्षा गरी, कुनै पनि अनुप्रयोगलाई बाह्य भण्डारणमा लेख्न योग्य बनाउँछ"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"गतिविधिहरू रिसाइज गर्नको लागि बाध्य गर्नुहोस्"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"म्यानिफेेस्ट मानहरूको ख्याल नगरी, बहु-विन्डोको लागि सबै रिसाइज गर्न सकिने गतिविधिहरू बनाउँछ।"</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"फ्रीफर्म विन्डोहरू सक्रिय गर्नुहोस्"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"प्रयोगात्मक फ्रीफर्म विन्डोहरूका लागि समर्थनलाई सक्रिय गर्छ।"</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"डेस्कटप ब्याकअप पासवर्ड"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"डेस्कटप पूर्ण जगेडाहरू हाललाई सुरक्षित छैनन्"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"डेस्कटप पूर्ण ब्याकअपको लागि पासवर्ड बदल्न वा हटाउन छुनुहोस्"</string>
diff --git a/packages/SettingsLib/res/values-nl/strings.xml b/packages/SettingsLib/res/values-nl/strings.xml
index 1afa444..1dd477d 100644
--- a/packages/SettingsLib/res/values-nl/strings.xml
+++ b/packages/SettingsLib/res/values-nl/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Hierdoor komt een app in aanmerking om te worden geschreven naar externe opslag, ongeacht de manifestwaarden"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Formaat activiteiten geforceerd aanpasbaar maken"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Hiermee wordt het formaat van alle activiteiten aanpasbaar gemaakt, ongeacht de manifestwaarden."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Vensters met vrije vorm inschakelen"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Schakelt ondersteuning in voor vensters met experimentele vrije vorm."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Wachtwoord desktopback-up"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Volledige back-ups naar desktops zijn momenteel niet beveiligd"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Raak dit aan om het wachtwoord voor volledige back-ups naar desktops te wijzigen of te verwijderen"</string>
diff --git a/packages/SettingsLib/res/values-pa-rIN/strings.xml b/packages/SettingsLib/res/values-pa-rIN/strings.xml
index ad3d3ed..85f9ffb 100644
--- a/packages/SettingsLib/res/values-pa-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-pa-rIN/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"ਇੱਕ ਐਪ ਨੂੰ ਬਾਹਰਲੀ ਸਟੋਰੇਜ ਤੇ ਲਿਖਣ ਦੇ ਯੋਗ ਬਣਾਉਂਦਾ ਹੈ, ਮੈਨੀਫੈਸਟ ਵੈਲਯੂਜ ਤੇ ਵਿਚਾਰ ਕੀਤੇ ਬਿਨਾਂ"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"ਮੁੜ-ਆਕਾਰ ਬਦਲਣ ਲਈ ਸਰਗਰਮੀਆਂ \'ਤੇ ਜ਼ੋਰ ਦਿਓ"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"ਮਲਟੀ-ਵਿੰਡੋ ਲਈ ਸਾਰੀਆਂ ਸਰਗਰਮੀਆਂ ਨੂੰ ਮੁੜ-ਆਕਾਰ ਵਿੱਚ ਲਿਆਉਂਦੀ ਹੈ, ਚਾਹੇ ਮੈਨੀਫੈਸਟ ਵੈਲਯੂਜ਼ ਕੁਝ ਵੀ ਹੋਣ।"</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"freeform windows ਨੂੰ ਯੋਗ ਬਣਾਓ"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"ਪ੍ਰਯੋਗਾਤਮਕ freeform windows ਲਈ ਸਮਰਥਨ ਨੂੰ ਯੋਗ ਬਣਾਉਂਦੀ ਹੈ।"</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"ਡੈਸਕਟੌਪ ਬੈਕਅਪ ਪਾਸਵਰਡ"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"ਡੈਸਕਟੌਪ ਪੂਰੇ ਬੈਕਅਪਸ ਇਸ ਵੇਲੇ ਸੁਰੱਖਿਅਤ ਨਹੀਂ ਹਨ"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"ਡੈਸਕਟੌਪ ਪੂਰੇ ਬੈਕਅਪਸ ਲਈ ਪਾਸਵਰਡ ਬਦਲਣ ਜਾਂ ਹਟਾਉਣ ਲਈ ਛੋਹਵੋ"</string>
diff --git a/packages/SettingsLib/res/values-pl/strings.xml b/packages/SettingsLib/res/values-pl/strings.xml
index d58070e..9f7c022 100644
--- a/packages/SettingsLib/res/values-pl/strings.xml
+++ b/packages/SettingsLib/res/values-pl/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Pozwala na zapis aplikacji w pamięci zewn. niezależnie od wartości w pliku manifestu"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Wymuś zmianę rozmiaru okien aktywności"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Umożliwia zmianę rozmiaru wszystkich okien aktywności w trybie wielu okien niezależnie od ustawień w pliku manifestu."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Włącz dowolny rozmiar okien"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Włącza obsługę eksperymentalnej funkcji dowolnego rozmiaru okien."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Hasło kopii zapasowej"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Pełne kopie zapasowe na komputerze nie są obecnie chronione"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Wybierz, aby zmienić lub usunąć hasło pełnych kopii zapasowych na komputerze stacjonarnym."</string>
diff --git a/packages/SettingsLib/res/values-pt-rBR/strings.xml b/packages/SettingsLib/res/values-pt-rBR/strings.xml
index 3b28043..dd4b58d 100644
--- a/packages/SettingsLib/res/values-pt-rBR/strings.xml
+++ b/packages/SettingsLib/res/values-pt-rBR/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Qualifica apps p/ gravação em armazenamento externo, independentemente de valores de manifestos"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Forçar atividades a serem redimensionáveis"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Torna todas as atividades redimensionáveis para várias janelas, independentemente dos valores do manifesto."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Senha do backup local"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Os backups completos do computador não estão protegidos no momento"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Toque para alterar ou remover a senha de backups completos do desktop"</string>
diff --git a/packages/SettingsLib/res/values-pt-rPT/strings.xml b/packages/SettingsLib/res/values-pt-rPT/strings.xml
index c5f94cb..0cbe5e4 100644
--- a/packages/SettingsLib/res/values-pt-rPT/strings.xml
+++ b/packages/SettingsLib/res/values-pt-rPT/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Qualquer aplic. pode ser gravada no arm. ext., independ. dos valores do manif."</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Forçar as atividades a serem redimensionáveis"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Torna todas as atividades redimensionáveis para várias janelas, independentemente dos valores do manifesto."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Ativar janelas de forma livre"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Ativa a compatibilidade com janelas de forma livre experimentais."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Palavra-passe cópia do comp."</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"As cópias de segurança completas no ambiente de trabalho não estão atualmente protegidas"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Toque para alterar ou remover a palavra-passe para cópias de segurança completas no ambiente de trabalho"</string>
diff --git a/packages/SettingsLib/res/values-pt/strings.xml b/packages/SettingsLib/res/values-pt/strings.xml
index 3b28043..dd4b58d 100644
--- a/packages/SettingsLib/res/values-pt/strings.xml
+++ b/packages/SettingsLib/res/values-pt/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Qualifica apps p/ gravação em armazenamento externo, independentemente de valores de manifestos"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Forçar atividades a serem redimensionáveis"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Torna todas as atividades redimensionáveis para várias janelas, independentemente dos valores do manifesto."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Senha do backup local"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Os backups completos do computador não estão protegidos no momento"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Toque para alterar ou remover a senha de backups completos do desktop"</string>
diff --git a/packages/SettingsLib/res/values-ro/strings.xml b/packages/SettingsLib/res/values-ro/strings.xml
index c76faf0..a666da0 100644
--- a/packages/SettingsLib/res/values-ro/strings.xml
+++ b/packages/SettingsLib/res/values-ro/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Face orice aplicație eligibilă să fie scrisă în stocarea externă, indiferent de valorile manifestului"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Forțați redimensionarea activităților"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Permite redimensionarea tuturor activităților pentru modul cu ferestre multiple, indiferent de valorile manifestului."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Parolă copie rez. desktop"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"În prezent, copiile de rezervă complete pe desktop nu sunt protejate"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Atingeţi pentru a modifica sau pentru a elimina parola pentru copiile de rezervă complete pe desktop"</string>
diff --git a/packages/SettingsLib/res/values-ru/strings.xml b/packages/SettingsLib/res/values-ru/strings.xml
index f1cd182..e93bae1 100644
--- a/packages/SettingsLib/res/values-ru/strings.xml
+++ b/packages/SettingsLib/res/values-ru/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Разрешает сохранение приложений на внешние накопители независимо от значения манифеста"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Изменение размера в многооконном режиме"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Позволяет менять размер в многооконном режиме (независимо от значений манифеста)"</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Пароль для резервного копирования"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Полные резервные копии в настоящее время не защищены"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Изменить или удалить пароль для резервного копирования"</string>
diff --git a/packages/SettingsLib/res/values-si-rLK/strings.xml b/packages/SettingsLib/res/values-si-rLK/strings.xml
index eb13ce4..6753624 100644
--- a/packages/SettingsLib/res/values-si-rLK/strings.xml
+++ b/packages/SettingsLib/res/values-si-rLK/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"මැනිෆෙස්ට් අගයන් නොසලකා, ඕනෑම යෙදුමක් අභ්‍යන්තර ගබඩාවට ලිවීමට සුදුසුකම් ලබා දෙයි"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"ක්‍රියාකාරකම් ප්‍රතිප්‍රමාණ කළ හැකි බවට බල කරන්න"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"මැනිෆෙස්ට් අගයන් නොසලකා, සියලු ක්‍රියාකාරකම් බහු-කවුළු සඳහා ප්‍රතිප්‍රමාණ කළ හැකි බවට පත් කරයි."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"ඩෙස්ක්ටොප් උපස්ථ මුරපදය"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"ඩෙස්ක්ටොප් සම්පූර්ණ උපස්ථ දැනට ආරක්ෂා කර නොමැත"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"ඩෙස්ක්ටොප් සම්පූර්ණ උපස්ථ සඳහා මුරපදය වෙනස් කිරීමට හෝ ඉවත් කිරීමට ස්පර්ශ කරන්න"</string>
diff --git a/packages/SettingsLib/res/values-sk/strings.xml b/packages/SettingsLib/res/values-sk/strings.xml
index b5b6d2a..7db7835 100644
--- a/packages/SettingsLib/res/values-sk/strings.xml
+++ b/packages/SettingsLib/res/values-sk/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Umožňuje zapísať akúkoľvek aplikáciu do externého úložiska bez ohľadu na hodnoty v manifeste"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Vynútiť možnosť zmeny veľkosti aktivít"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Veľkosti všetkých aktivít bude možné zmeniť na niekoľko okien (bez ohľadu na hodnoty manifestu)."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Heslo pre zálohy v počítači"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Úplné zálohy na počítači nie sú momentálne chránené"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Dotykom zmeníte alebo odstránite heslo pre úplné zálohy do počítača"</string>
diff --git a/packages/SettingsLib/res/values-sl/strings.xml b/packages/SettingsLib/res/values-sl/strings.xml
index cb107d7..ed37933 100644
--- a/packages/SettingsLib/res/values-sl/strings.xml
+++ b/packages/SettingsLib/res/values-sl/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Poskrbi, da je ne glede na vrednosti v manifestu mogoče vsako aplikacijo zapisati v zunanjo shrambo"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Vsili povečanje velikosti za aktivnosti"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Poskrbi, da je ne glede na vrednosti v manifestu mogoče vsem aktivnostim povečati velikost za način z več okni."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Geslo za varn. kop. rač."</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Popolne varnostne kopije namizja trenutno niso zaščitene"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Dotaknite se, če želite spremeniti ali odstraniti geslo za popolno varnostno kopiranje namizja."</string>
diff --git a/packages/SettingsLib/res/values-sq-rAL/strings.xml b/packages/SettingsLib/res/values-sq-rAL/strings.xml
index c176f18..7f4d6a8 100644
--- a/packages/SettingsLib/res/values-sq-rAL/strings.xml
+++ b/packages/SettingsLib/res/values-sq-rAL/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Bën që çdo aplikacion të jetë i përshtatshëm për t\'u shkruar në hapësirën ruajtëse të jashtme, pavarësisht nga vlerat e manifestit"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Detyro madhësinë e ndryshueshme për aktivitetet"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Bën që të gjitha aktivitetet të kenë madhësi të ndryshueshme për përdorimin me shumë dritare, pavarësisht vlerave të manifestit."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Aktivizo dritaret me formë të lirë"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Aktivizon mbështetjen për dritaret eksperimentale me formë të lirë."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Fjalëkalimi rezervë i kompjuterit"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Rezervimet e plota në kompjuter nuk janë të mbrojtura aktualisht"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Prek për të ndryshuar ose hequr fjalëkalimin për rezervime të plota të desktopit"</string>
diff --git a/packages/SettingsLib/res/values-sr/strings.xml b/packages/SettingsLib/res/values-sr/strings.xml
index 6b66094..9596ce5 100644
--- a/packages/SettingsLib/res/values-sr/strings.xml
+++ b/packages/SettingsLib/res/values-sr/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Омогућава уписивање свих апликација у спољну меморију, без обзира на вредности манифеста"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Принудно омогући промену величине активности"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Омогућава промену величине свих активности за режим са више прозора, без обзира на вредности манифеста."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Лозинка резервне копије за рачунар"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Резервне копије читавог система тренутно нису заштићене"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Додирните да бисте променили или уклонили лозинку за прављење резервних копија читавог система на рачунару"</string>
diff --git a/packages/SettingsLib/res/values-sv/strings.xml b/packages/SettingsLib/res/values-sv/strings.xml
index 40e1593..7d0d0a0 100644
--- a/packages/SettingsLib/res/values-sv/strings.xml
+++ b/packages/SettingsLib/res/values-sv/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Appen kan skrivas till extern lagring, oavsett manifestvärden"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Framtvinga storleksanpassning för aktiviteter"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Detta gör det möjligt att ändra storleken på alla aktiviteter i flerfönsterläge, oavsett manifestvärden."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Lösenord för säkerhetskopia av datorn"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"De fullständiga säkerhetskopiorna av datorn är för närvarande inte skyddade"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Tryck om du vill ändra eller ta bort lösenordet för fullständig säkerhetskopiering av datorn"</string>
diff --git a/packages/SettingsLib/res/values-sw/strings.xml b/packages/SettingsLib/res/values-sw/strings.xml
index a014e1d..d1041da 100644
--- a/packages/SettingsLib/res/values-sw/strings.xml
+++ b/packages/SettingsLib/res/values-sw/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Huweka programu kwenye hifadhi ya nje, bila kujali maelezo"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Lazimisha shughuli ziweze kubadilishwa ukubwa"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Fanya shughuli zote ziweze kubadilishwa ukubwa kwa ajili ya dirisha nyingi, bila kujali thamani za faili ya maelezo."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Nenosiri la hifadhi rudufu ya eneo kazi"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Hifadhi rudufu kamili za eneo kazi hazijalindwa kwa sasa"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Gusa ili ubadilishe au uondoe nenosiri la hifadhi rudufu kamili za eneo kazi"</string>
diff --git a/packages/SettingsLib/res/values-ta-rIN/strings.xml b/packages/SettingsLib/res/values-ta-rIN/strings.xml
index 4f6ea57..e66f073 100644
--- a/packages/SettingsLib/res/values-ta-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-ta-rIN/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"மேனிஃபெஸ்ட் மதிப்புகளை பொருட்படுத்தாமல், எந்தப் பயன்பாட்டையும் வெளிப்புற சேமிப்பிடத்தில் எழுத அனுமதிக்கும்"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"செயல்பாடுகளை அளவுமாறக்கூடியதாக அமை"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"மேனிஃபெஸ்ட் மதிப்புகளைப் பொருட்படுத்தாமல், பல சாளரத்திற்கு எல்லா செயல்பாடுகளையும் அளவுமாறக்கூடியதாக அமைக்கும்."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"டெஸ்க்டாப் காப்புப்பிரதி கடவுச்சொல்"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"டெஸ்க்டாப்பின் முழு காப்புப்பிரதிகள் தற்போது பாதுகாக்கப்படவில்லை"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"டெஸ்க்டாப்பின் முழுமையான காப்புப்பிரதிகளுக்கான கடவுச்சொல்லை மாற்றுவதற்கு அல்லது அகற்றுவதற்குத் தொடவும்"</string>
diff --git a/packages/SettingsLib/res/values-te-rIN/strings.xml b/packages/SettingsLib/res/values-te-rIN/strings.xml
index a6d2140..80b84f0 100644
--- a/packages/SettingsLib/res/values-te-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-te-rIN/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"ఏ అనువర్తనాన్ని అయినా మానిఫెస్ట్ విలువలతో సంబంధం లేకుండా బాహ్య నిల్వలో వ్రాయగలిగేలా అనుమతిస్తుంది"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"కార్యాచరణలను పరిమాణం మార్చగలిగేలా నిర్బంధించు"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"మానిఫెస్ట్ విలువలతో సంబంధం లేకుండా అన్ని కార్యాచరణలను బహుళ విండోల్లో సరిపోయేటట్లు పరిమాణం మార్చగలిగేలా చేస్తుంది."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"స్వతంత్ర రూప విండోలను ప్రారంభించండి"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"ప్రయోగాత్మక స్వతంత్ర రూప విండోలకు మద్దతును ప్రారంభిస్తుంది."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"డెస్క్‌టాప్ బ్యాకప్ పాస్‌వర్డ్"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"డెస్క్‌టాప్ పూర్తి బ్యాకప్‌లు ప్రస్తుతం రక్షించబడలేదు"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"డెస్క్‌టాప్ పూర్తి బ్యాకప్‌ల కోసం పాస్‌వర్డ్‌ను మార్చడానికి లేదా తీసివేయడానికి తాకండి"</string>
diff --git a/packages/SettingsLib/res/values-th/strings.xml b/packages/SettingsLib/res/values-th/strings.xml
index de2f33d..6826419 100644
--- a/packages/SettingsLib/res/values-th/strings.xml
+++ b/packages/SettingsLib/res/values-th/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"ให้สามารถเขียนแอปต่างๆ ไปยังที่เก็บภายนอกได้ โดยไม่คำนึงถึงค่าในไฟล์ Manifest"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"บังคับให้กิจกรรมปรับขนาดได้"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"ทำให้กิจกรรมทั้งหมดปรับขนาดได้สำหรับหน้าต่างหลายบาน โดยไม่คำนึงถึงค่าในไฟล์ Manifest"</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"รหัสผ่านการสำรองข้อมูลในเดสก์ท็อป"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"การสำรองข้อมูลเต็มรูปแบบในเดสก์ท็อป ไม่ได้รับการป้องกันในขณะนี้"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"แตะเพื่อเปลี่ยนหรือลบรหัสผ่านสำหรับการสำรองข้อมูลเต็มรูปแบบในเดสก์ท็อป"</string>
diff --git a/packages/SettingsLib/res/values-tl/strings.xml b/packages/SettingsLib/res/values-tl/strings.xml
index 231079b..8f62326 100644
--- a/packages/SettingsLib/res/values-tl/strings.xml
+++ b/packages/SettingsLib/res/values-tl/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Mara-write na sa external storage ang anumang app, anuman ang manifest value"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Sapilitang gawing resizable ang mga aktibidad"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Gawing resizable para sa multi-window ang lahat ng aktibidad, anuman ang mga manifest value."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Password ng pag-backup ng desktop"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Kasalukuyang hindi pinoprotektahan ang mga buong pag-backup ng desktop"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Pindutin upang baguhin o alisin ang password para sa mga buong pag-backup ng desktop"</string>
diff --git a/packages/SettingsLib/res/values-tr/strings.xml b/packages/SettingsLib/res/values-tr/strings.xml
index c44d7f8..5e0839a 100644
--- a/packages/SettingsLib/res/values-tr/strings.xml
+++ b/packages/SettingsLib/res/values-tr/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Bildirilen değerlerden bağımsız olarak uygulamaları harici depolamaya yazmak için uygun hale getirir"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Etkinlikleri yeniden boyutlandırılabilmeye zorla"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Manifest değerlerinden bağımsız olarak, tüm etkinlikleri birden fazla pencerede yeniden boyutlandırılabilir hale getirir."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Masaüstü yedekleme şifresi"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Masaüstü tam yedeklemeleri şu an korunmuyor"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Masaüstü tam yedeklemelerinin şifresini değiştirmek veya kaldırmak için dokunun"</string>
diff --git a/packages/SettingsLib/res/values-uk/strings.xml b/packages/SettingsLib/res/values-uk/strings.xml
index d5dbe90..2448b23 100644
--- a/packages/SettingsLib/res/values-uk/strings.xml
+++ b/packages/SettingsLib/res/values-uk/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Додатки можна записувати на зовнішню пам’ять незалежно від значень маніфесту"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Примусово масштабувати активність"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Активність масштабуватиметься на кілька вікон, незалежно від значень у файлі маніфесту."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Увімкнути вікна довільного формату"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Увімкнуться експериментальні вікна довільного формату."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Пароль резерв.копії на ПК"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Повні резервні копії на комп’ютері наразі не захищені"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Торкніться, щоб змінити чи видалити пароль для повного резервного копіювання на комп’ютер"</string>
diff --git a/packages/SettingsLib/res/values-ur-rPK/strings.xml b/packages/SettingsLib/res/values-ur-rPK/strings.xml
index 4c9c178..0834303 100644
--- a/packages/SettingsLib/res/values-ur-rPK/strings.xml
+++ b/packages/SettingsLib/res/values-ur-rPK/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"‏manifest اقدار سے قطع نظر، کسی بھی ایپ کو بیرونی اسٹوریج پر لکھے جانے کا اہل بناتا ہے"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"سرگرمیوں کو ری سائز ایبل بنائیں"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"‏manifest اقدار سے قطع نظر، ملٹی ونڈو کیلئے تمام سرگرمیوں کو ری سائز ایبل بناتا ہے۔"</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"ڈیسک ٹاپ کا بیک اپ پاس ورڈ"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"ڈیسک ٹاپ کے مکمل بیک اپس فی الحال محفوظ کیے ہوئے نہیں ہیں"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"ڈیسک ٹاپ کے مکمل بیک اپس کیلئے پاس ورڈ کو تبدیل کرنے یا ہٹانے کیلئے ٹچ کریں"</string>
diff --git a/packages/SettingsLib/res/values-uz-rUZ/strings.xml b/packages/SettingsLib/res/values-uz-rUZ/strings.xml
index d138a28..d2d8b76 100644
--- a/packages/SettingsLib/res/values-uz-rUZ/strings.xml
+++ b/packages/SettingsLib/res/values-uz-rUZ/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Manifest qiymatidan qat’i nazar istalgan ilovani tashqi xotiraga saqlash imkonini beradi"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Harakatlarni moslashuvchan o‘lchamga keltirish"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Manifest qiymatidan qat’i nazar barcha harakatlarni ko‘p oynali rejimga moslashtiradi."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Zaxira nusxa uchun parol"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Kompyuterdagi zaxira nusxalar hozirgi vaqtda himoyalanmagan"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Ish stoli to\'liq zaxira nusxalari parolini o‘zgartirish yoki o‘chirish uchun bu yerni bosing."</string>
diff --git a/packages/SettingsLib/res/values-vi/strings.xml b/packages/SettingsLib/res/values-vi/strings.xml
index 7ab8b02..178e301 100644
--- a/packages/SettingsLib/res/values-vi/strings.xml
+++ b/packages/SettingsLib/res/values-vi/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Giúp ứng dụng bất kỳ đủ điều kiện được ghi vào bộ nhớ ngoài bất kể giá trị tệp kê khai là gì"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Buộc các hoạt động có thể thay đổi kích thước"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Giúp tất cả hoạt động có thể thay đổi kích thước cho nhiều cửa sổ bất kể giá trị tệp kê khai là gì."</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"Mật khẩu sao lưu của máy tính"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Sao lưu toàn bộ máy tính hiện không được bảo vệ"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Chạm để thay đổi hoặc xóa mật khẩu dành cho bộ sao lưu toàn bộ tới máy tính"</string>
diff --git a/packages/SettingsLib/res/values-zh-rCN/strings.xml b/packages/SettingsLib/res/values-zh-rCN/strings.xml
index 509ff88..5b96383 100644
--- a/packages/SettingsLib/res/values-zh-rCN/strings.xml
+++ b/packages/SettingsLib/res/values-zh-rCN/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"允许将任何应用写入外部存储设备(无论清单值是什么)"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"强制将活动设为可调整大小"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"将所有活动设为可配合多窗口环境调整大小(无论清单值是什么)。"</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"桌面备份密码"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"桌面完整备份当前未设置密码保护"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"触摸可更改或删除用于桌面完整备份的密码"</string>
diff --git a/packages/SettingsLib/res/values-zh-rHK/strings.xml b/packages/SettingsLib/res/values-zh-rHK/strings.xml
index f323667..db5f09b 100644
--- a/packages/SettingsLib/res/values-zh-rHK/strings.xml
+++ b/packages/SettingsLib/res/values-zh-rHK/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"允許將所有應用程式寫入到外部儲存完間 (所有資訊清單值)"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"強制可變更活動尺寸"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"在任何資訊清單值下,允許為多個視窗變更所有活動的尺寸。"</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"桌面電腦備份密碼"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"桌上電腦的完整備份目前未受保護"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"輕觸即可更改或移除桌上電腦完整備份的密碼"</string>
diff --git a/packages/SettingsLib/res/values-zh-rTW/strings.xml b/packages/SettingsLib/res/values-zh-rTW/strings.xml
index c6ad832..787a442 100644
--- a/packages/SettingsLib/res/values-zh-rTW/strings.xml
+++ b/packages/SettingsLib/res/values-zh-rTW/strings.xml
@@ -247,6 +247,10 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"允許將任何應用程式寫入外部儲存空間 (無論資訊清單值為何)"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"將活動強制設為可調整大小"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"將所有活動設為可配合多重視窗環境調整大小 (無論資訊清單值為何)。"</string>
+    <!-- no translation found for enable_freeform_support (1461893351278940416) -->
+    <skip />
+    <!-- no translation found for enable_freeform_support_summary (2252563497485436534) -->
+    <skip />
     <string name="local_backup_password_title" msgid="3860471654439418822">"電腦備份密碼"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"電腦完整備份目前未受保護"</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"輕觸即可變更或移除電腦完整備份的密碼"</string>
diff --git a/packages/SettingsLib/res/values-zu/strings.xml b/packages/SettingsLib/res/values-zu/strings.xml
index cb3670f..bf3addf 100644
--- a/packages/SettingsLib/res/values-zu/strings.xml
+++ b/packages/SettingsLib/res/values-zu/strings.xml
@@ -247,6 +247,8 @@
     <string name="force_allow_on_external_summary" msgid="3191952505860343233">"Yenza noma uluphi uhlelo lokusebenza lifaneleke ukuthi libhalwe kusitoreji sangaphandle, ngaphandle kwamavelu we-manifest"</string>
     <string name="force_resizable_activities" msgid="8615764378147824985">"Imisebenzi yamandla izonikezwa usayizi omusha"</string>
     <string name="force_resizable_activities_summary" msgid="4508217476997182216">"Yenza yonke imisebenzi ibe nosayizi abasha kuwindi lokuningi, ngokunganaki amanani we-manifest."</string>
+    <string name="enable_freeform_support" msgid="1461893351278940416">"Nika amandla amawindi e-freeform"</string>
+    <string name="enable_freeform_support_summary" msgid="2252563497485436534">"Inika amandla usekelo lwamawindi okuhlola e-freeform."</string>
     <string name="local_backup_password_title" msgid="3860471654439418822">"Iphasiwedi yokusekela ngokulondoloza ye-Desktop"</string>
     <string name="local_backup_password_summary_none" msgid="6951095485537767956">"Ukusekela ngokulondoloza okugcwele kwe-Desktop akuvikelekile okwamanje."</string>
     <string name="local_backup_password_summary_change" msgid="2731163425081172638">"Khetha ukushintsha noma ukususa iphasiwedi yokwenziwa kwezipele ngokugcwele kwideskithophu"</string>
diff --git a/packages/SettingsLib/res/values/arrays.xml b/packages/SettingsLib/res/values/arrays.xml
index 2a4efbd..1bce7f9 100644
--- a/packages/SettingsLib/res/values/arrays.xml
+++ b/packages/SettingsLib/res/values/arrays.xml
@@ -128,7 +128,7 @@
         <item>16777216</item>
     </string-array>
 
-    <!-- Summaries for logd limit size selection preference. [CHAR LIMIT=30]-->
+    <!-- Summaries for logd limit size selection preference. [CHAR LIMIT=50]-->
     <string-array name="select_logd_size_summaries" >
         <item>Off</item>
         <item>64K per log buffer</item>
diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml
index 7e22881..f7e25db 100644
--- a/packages/SettingsLib/res/values/strings.xml
+++ b/packages/SettingsLib/res/values/strings.xml
@@ -624,6 +624,11 @@
     <!-- UI debug setting: force allow on external summary [CHAR LIMIT=150] -->
     <string name="force_resizable_activities_summary">Makes all activities resizable for multi-window, regardless of manifest values.</string>
 
+    <!-- UI debug setting: enable freeform window support [CHAR LIMIT=50] -->
+    <string name="enable_freeform_support">Enable freeform windows</string>
+    <!-- UI debug setting: enable freeform window support summary [CHAR LIMIT=150] -->
+    <string name="enable_freeform_support_summary">Enables support for experimental freeform windows.</string>
+
     <!-- Local (desktop) backup password menu title [CHAR LIMIT=25] -->
     <string name="local_backup_password_title">Desktop backup password</string>
     <!-- Summary text of the "local backup password" setting when the user has not supplied a password -->
diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java b/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java
index 344bf62..f6d9134 100644
--- a/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java
@@ -38,7 +38,7 @@
         String packageName = appEntry.info.packageName;
         boolean hasPreferred = hasPreferredActivities(pm, packageName)
                 || hasUsbDefaults(usbManager, packageName);
-        int status = pm.getIntentVerificationStatus(packageName, UserHandle.myUserId());
+        int status = pm.getIntentVerificationStatusAsUser(packageName, UserHandle.myUserId());
         // consider a visible current link-handling state to be any explicitly designated behavior
         boolean hasDomainURLsPreference =
                 status != PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java
index e6fe447..d353f31 100644
--- a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java
+++ b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java
@@ -316,7 +316,7 @@
         synchronized (mEntriesMap) {
             AppEntry entry = mEntriesMap.get(userId).get(packageName);
             if (entry != null) {
-                mPm.getPackageSizeInfo(packageName, userId, mBackgroundHandler.mStatsObserver);
+                mPm.getPackageSizeInfoAsUser(packageName, userId, mBackgroundHandler.mStatsObserver);
             }
             if (DEBUG_LOCKING) Log.v(TAG, "...requestSize releasing lock");
         }
@@ -906,7 +906,7 @@
                                     entry.sizeLoadStart = now;
                                     mCurComputingSizePkg = entry.info.packageName;
                                     mCurComputingSizeUserId = UserHandle.getUserId(entry.info.uid);
-                                    mPm.getPackageSizeInfo(mCurComputingSizePkg,
+                                    mPm.getPackageSizeInfoAsUser(mCurComputingSizePkg,
                                             mCurComputingSizeUserId, mStatsObserver);
                                 }
                                 if (DEBUG_LOCKING) Log.v(TAG, "MSG_LOAD_SIZES releasing: now computing");
diff --git a/packages/SettingsLib/src/com/android/settingslib/deviceinfo/StorageMeasurement.java b/packages/SettingsLib/src/com/android/settingslib/deviceinfo/StorageMeasurement.java
index 9790e64..3b818c8 100644
--- a/packages/SettingsLib/src/com/android/settingslib/deviceinfo/StorageMeasurement.java
+++ b/packages/SettingsLib/src/com/android/settingslib/deviceinfo/StorageMeasurement.java
@@ -422,7 +422,7 @@
                     ActivityManager.getCurrentUser(), currentProfiles, finished, count);
             for (UserInfo user : users) {
                 for (ApplicationInfo app : volumeApps) {
-                    packageManager.getPackageSizeInfo(app.packageName, user.id, observer);
+                    packageManager.getPackageSizeInfoAsUser(app.packageName, user.id, observer);
                 }
             }
 
diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml
index c6d9e98..7416fb5 100644
--- a/packages/Shell/AndroidManifest.xml
+++ b/packages/Shell/AndroidManifest.xml
@@ -151,6 +151,14 @@
             </intent-filter>
         </receiver>
 
+        <receiver
+            android:name=".RemoteBugreportReceiver"
+            android:permission="android.permission.DUMP">
+            <intent-filter>
+                <action android:name="android.intent.action.REMOTE_BUGREPORT_FINISHED" />
+            </intent-filter>
+        </receiver>
+
         <service
             android:name=".BugreportProgressService"
             android:exported="false"/>
diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java
index d31088c..5c807e1 100644
--- a/packages/Shell/src/com/android/shell/BugreportProgressService.java
+++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java
@@ -21,6 +21,7 @@
 import static com.android.shell.BugreportPrefs.getWarningState;
 
 import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileDescriptor;
 import java.io.FileInputStream;
@@ -28,10 +29,13 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
 import java.text.NumberFormat;
 import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.List;
 import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
 import java.util.zip.ZipOutputStream;
 
 import libcore.io.Streams;
@@ -112,6 +116,10 @@
     // External intents sent by dumpstate.
     static final String INTENT_BUGREPORT_STARTED = "android.intent.action.BUGREPORT_STARTED";
     static final String INTENT_BUGREPORT_FINISHED = "android.intent.action.BUGREPORT_FINISHED";
+    static final String INTENT_REMOTE_BUGREPORT_FINISHED =
+            "android.intent.action.REMOTE_BUGREPORT_FINISHED";
+    static final String INTENT_REMOTE_BUGREPORT_DISPATCH =
+            "android.intent.action.REMOTE_BUGREPORT_DISPATCH";
 
     // Internal intents used on notification actions.
     static final String INTENT_BUGREPORT_CANCEL = "android.intent.action.BUGREPORT_CANCEL";
@@ -449,6 +457,11 @@
                 .addAction(cancelAction)
                 .build();
 
+        if (info.finished) {
+            Log.w(TAG, "Not sending progress notification because bugreport has finished already ("
+                    + info + ")");
+            return;
+        }
         NotificationManager.from(mContext).notify(TAG, info.pid, notification);
     }
 
@@ -628,7 +641,12 @@
         synchronized (BugreportProgressService.this) {
             mTakingScreenshot = flag;
             for (int i = 0; i < mProcesses.size(); i++) {
-                updateProgress(mProcesses.valueAt(i));
+                final BugreportInfo info = mProcesses.valueAt(i);
+                if (info.finished) {
+                    Log.d(TAG, "Not updating progress because share notification was already sent");
+                    continue;
+                }
+                updateProgress(info);
             }
         }
     }
@@ -803,6 +821,9 @@
             Log.e(TAG, "INTERNAL ERROR: no info for PID " + pid + ": " + mProcesses);
             return;
         }
+
+        addDetailsToZipFile(info);
+
         final Intent sendIntent = buildSendIntent(mContext, info);
         final Intent notifIntent;
 
@@ -858,7 +879,7 @@
         new AsyncTask<Void, Void, Void>() {
             @Override
             protected Void doInBackground(Void... params) {
-                info.bugreportFile = zipBugreport(info.bugreportFile);
+                zipBugreport(info);
                 sendBugreportNotification(context, info);
                 return null;
             }
@@ -869,35 +890,92 @@
      * Zips a bugreport file, returning the path to the new file (or to the
      * original in case of failure).
      */
-    private static File zipBugreport(File bugreportFile) {
-        String bugreportPath = bugreportFile.getAbsolutePath();
-        String zippedPath = bugreportPath.replace(".txt", ".zip");
+    private static void zipBugreport(BugreportInfo info) {
+        final String bugreportPath = info.bugreportFile.getAbsolutePath();
+        final String zippedPath = bugreportPath.replace(".txt", ".zip");
         Log.v(TAG, "zipping " + bugreportPath + " as " + zippedPath);
-        File bugreportZippedFile = new File(zippedPath);
-        try (InputStream is = new FileInputStream(bugreportFile);
+        final File bugreportZippedFile = new File(zippedPath);
+        try (InputStream is = new FileInputStream(info.bugreportFile);
                 ZipOutputStream zos = new ZipOutputStream(
                         new BufferedOutputStream(new FileOutputStream(bugreportZippedFile)))) {
-            ZipEntry entry = new ZipEntry(bugreportFile.getName());
-            entry.setTime(bugreportFile.lastModified());
-            zos.putNextEntry(entry);
-            int totalBytes = Streams.copy(is, zos);
-            Log.v(TAG, "size of original bugreport: " + totalBytes + " bytes");
-            zos.closeEntry();
-            // Delete old file;
-            boolean deleted = bugreportFile.delete();
+            addEntry(zos, info.bugreportFile.getName(), is);
+            // Delete old file
+            final boolean deleted = info.bugreportFile.delete();
             if (deleted) {
                 Log.v(TAG, "deleted original bugreport (" + bugreportPath + ")");
             } else {
                 Log.e(TAG, "could not delete original bugreport (" + bugreportPath + ")");
             }
-            return bugreportZippedFile;
+            info.bugreportFile = bugreportZippedFile;
         } catch (IOException e) {
             Log.e(TAG, "exception zipping file " + zippedPath, e);
-            return bugreportFile; // Return original.
         }
     }
 
     /**
+     * Adds the user-provided info into the bugreport zip file.
+     * <p>
+     * If user provided a title, it will be saved into a {@code title.txt} entry; similarly, the
+     * description will be saved on {@code description.txt}.
+     */
+    private void addDetailsToZipFile(BugreportInfo info) {
+        // It's not possible to add a new entry into an existing file, so we need to create a new
+        // zip, copy all entries, then rename it.
+        final File dir = info.bugreportFile.getParentFile();
+        final File tmpZip = new File(dir, "tmp-" + info.bugreportFile.getName());
+        Log.d(TAG, "Writing temporary zip file (" + tmpZip + ")");
+        try (ZipFile oldZip = new ZipFile(info.bugreportFile);
+                ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tmpZip))) {
+
+            // First copy contents from original zip.
+            Enumeration<? extends ZipEntry> entries = oldZip.entries();
+            while (entries.hasMoreElements()) {
+                final ZipEntry entry = entries.nextElement();
+                final String entryName = entry.getName();
+                if (!entry.isDirectory()) {
+                    addEntry(zos, entryName, entry.getTime(), oldZip.getInputStream(entry));
+                } else {
+                    Log.w(TAG, "skipping directory entry: " + entryName);
+                }
+            }
+
+            // Then add the user-provided info.
+            addEntry(zos, "title.txt", info.title);
+            addEntry(zos, "description.txt", info.description);
+        } catch (IOException e) {
+            Log.e(TAG, "exception zipping file " + tmpZip, e);
+            return;
+        }
+
+        if (!tmpZip.renameTo(info.bugreportFile)) {
+            Log.e(TAG, "Could not rename " + tmpZip + " to " + info.bugreportFile);
+        }
+    }
+
+    private static void addEntry(ZipOutputStream zos, String entry, String text)
+            throws IOException {
+        if (DEBUG) Log.v(TAG, "adding entry '" + entry + "': " + text);
+        if (!TextUtils.isEmpty(text)) {
+            addEntry(zos, entry, new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)));
+        }
+    }
+
+    private static void addEntry(ZipOutputStream zos, String entryName, InputStream is)
+            throws IOException {
+        addEntry(zos, entryName, System.currentTimeMillis(), is);
+    }
+
+    private static void addEntry(ZipOutputStream zos, String entryName, long timestamp,
+            InputStream is) throws IOException {
+        final ZipEntry entry = new ZipEntry(entryName);
+        entry.setTime(timestamp);
+        zos.putNextEntry(entry);
+        final int totalBytes = Streams.copy(is, zos);
+        if (DEBUG) Log.v(TAG, "size of '" + entryName + "' entry: " + totalBytes + " bytes");
+        zos.closeEntry();
+    }
+
+    /**
      * Find the best matching {@link Account} based on build properties.
      */
     private static Account findSendToAccount(Context context) {
@@ -931,7 +1009,7 @@
         return foundAccount;
     }
 
-    private static Uri getUri(Context context, File file) {
+    static Uri getUri(Context context, File file) {
         return file != null ? FileProvider.getUriForFile(context, AUTHORITY, file) : null;
     }
 
diff --git a/packages/Shell/src/com/android/shell/BugreportReceiver.java b/packages/Shell/src/com/android/shell/BugreportReceiver.java
index b818343..c8898b9 100644
--- a/packages/Shell/src/com/android/shell/BugreportReceiver.java
+++ b/packages/Shell/src/com/android/shell/BugreportReceiver.java
@@ -52,7 +52,7 @@
     @Override
     public void onReceive(Context context, Intent intent) {
         // Clean up older bugreports in background
-        cleanupOldFiles(intent);
+        cleanupOldFiles(this, intent, INTENT_BUGREPORT_FINISHED, MIN_KEEP_COUNT, MIN_KEEP_AGE);
 
         // Delegate intent handling to service.
         Intent serviceIntent = new Intent(context, BugreportProgressService.class);
@@ -60,8 +60,9 @@
         context.startService(serviceIntent);
     }
 
-    private void cleanupOldFiles(Intent intent) {
-        if (!INTENT_BUGREPORT_FINISHED.equals(intent.getAction())) {
+    static void cleanupOldFiles(BroadcastReceiver br, Intent intent, String expectedAction,
+            final int minCount, final long minAge) {
+        if (!expectedAction.equals(intent.getAction())) {
             return;
         }
         final File bugreportFile = getFileExtra(intent, EXTRA_BUGREPORT);
@@ -69,12 +70,11 @@
             Log.e(TAG, "Not deleting old files because file " + bugreportFile + " doesn't exist");
             return;
         }
-        final PendingResult result = goAsync();
+        final PendingResult result = br.goAsync();
         new AsyncTask<Void, Void, Void>() {
             @Override
             protected Void doInBackground(Void... params) {
-                FileUtils.deleteOlderFiles(
-                        bugreportFile.getParentFile(), MIN_KEEP_COUNT, MIN_KEEP_AGE);
+                FileUtils.deleteOlderFiles(bugreportFile.getParentFile(), minCount, minAge);
                 result.finish();
                 return null;
             }
diff --git a/packages/Shell/src/com/android/shell/RemoteBugreportReceiver.java b/packages/Shell/src/com/android/shell/RemoteBugreportReceiver.java
new file mode 100644
index 0000000..6f783a1
--- /dev/null
+++ b/packages/Shell/src/com/android/shell/RemoteBugreportReceiver.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.shell;
+
+import static com.android.shell.BugreportProgressService.EXTRA_BUGREPORT;
+import static com.android.shell.BugreportProgressService.INTENT_REMOTE_BUGREPORT_FINISHED;
+import static com.android.shell.BugreportProgressService.INTENT_REMOTE_BUGREPORT_DISPATCH;
+import static com.android.shell.BugreportProgressService.getFileExtra;
+import static com.android.shell.BugreportProgressService.getUri;
+import static com.android.shell.BugreportReceiver.cleanupOldFiles;
+
+import java.io.File;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.UserHandle;
+
+/**
+ * Receiver that handles finished remote bugreports, by re-sending
+ * the intent with appended bugreport zip file URI.
+ *
+ * <p> Remote bugreport never contains a screenshot.
+ */
+public class RemoteBugreportReceiver extends BroadcastReceiver {
+
+    private static final String BUGREPORT_MIMETYPE = "application/vnd.android.bugreport";
+    private static final String EXTRA_REMOTE_BUGREPORT_HASH =
+            "android.intent.extra.REMOTE_BUGREPORT_HASH";
+
+    /** Always keep just the last remote bugreport zip file */
+    private static final int MIN_KEEP_COUNT = 1;
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        cleanupOldFiles(this, intent, INTENT_REMOTE_BUGREPORT_FINISHED, MIN_KEEP_COUNT, 0);
+
+        final File bugreportFile = getFileExtra(intent, EXTRA_BUGREPORT);
+        final Uri bugreportUri = getUri(context, bugreportFile);
+        final String bugreportHash = intent.getStringExtra(EXTRA_REMOTE_BUGREPORT_HASH);
+
+        final Intent newIntent = new Intent(INTENT_REMOTE_BUGREPORT_DISPATCH);
+        newIntent.setDataAndType(bugreportUri, BUGREPORT_MIMETYPE);
+        newIntent.putExtra(EXTRA_REMOTE_BUGREPORT_HASH, bugreportHash);
+        context.sendBroadcastAsUser(newIntent, UserHandle.SYSTEM,
+                android.Manifest.permission.DUMP);
+    }
+}
diff --git a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java
index 6bee767..d1a07ea 100644
--- a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java
+++ b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java
@@ -60,6 +60,7 @@
 import android.support.test.uiautomator.UiObject;
 import android.test.InstrumentationTestCase;
 import android.test.suitebuilder.annotation.LargeTest;
+import android.text.TextUtils;
 import android.text.format.DateUtils;
 import android.util.Log;
 
@@ -103,6 +104,12 @@
     private static final String NAME = "BUG, Y U NO REPORT?";
     private static final String NEW_NAME = "Bug_Forrest_Bug";
     private static final String TITLE = "Wimbugdom Champion 2015";
+
+    private static final String NO_DESCRIPTION = null;
+    private static final String NO_NAME = null;
+    private static final String NO_SCREENSHOT = null;
+    private static final String NO_TITLE = null;
+
     private String mDescription;
 
     private String mPlainTextPath;
@@ -142,6 +149,7 @@
     public void testProgress() throws Exception {
         resetProperties();
         sendBugreportStarted(1000);
+        waitForScreenshotButtonEnabled(true);
 
         assertProgressNotification(NAME, "0.00%");
 
@@ -156,8 +164,8 @@
 
         Bundle extras =
                 sendBugreportFinishedAndGetSharedIntent(PID, mPlainTextPath, mScreenshotPath);
-        assertActionSendMultiple(extras, BUGREPORT_FILE, BUGREPORT_CONTENT, PID, NAME, ZIP_FILE,
-                null, 1);
+        assertActionSendMultiple(extras, BUGREPORT_FILE, BUGREPORT_CONTENT, PID, ZIP_FILE,
+                NAME, NO_TITLE, NO_DESCRIPTION, 1, true);
 
         assertServiceNotRunning();
     }
@@ -173,15 +181,17 @@
 
         Bundle extras =
                 sendBugreportFinishedAndGetSharedIntent(PID, mPlainTextPath, mScreenshotPath);
-        assertActionSendMultiple(extras, BUGREPORT_FILE, BUGREPORT_CONTENT, PID, NAME, ZIP_FILE,
-                null, 2);
+        assertActionSendMultiple(extras, BUGREPORT_FILE, BUGREPORT_CONTENT, PID, ZIP_FILE,
+                NAME, NO_TITLE, NO_DESCRIPTION, 2, true);
 
         assertServiceNotRunning();
     }
 
-    public void testProgress_changeDetails() throws Exception {
+    public void testProgress_changeDetailsInvalidInput() throws Exception {
+
         resetProperties();
         sendBugreportStarted(1000);
+        waitForScreenshotButtonEnabled(true);
 
         DetailsUi detailsUi = new DetailsUi(mUiBot);
 
@@ -217,15 +227,73 @@
 
         Bundle extras = sendBugreportFinishedAndGetSharedIntent(PID, mPlainTextPath,
                 mScreenshotPath);
-        assertActionSendMultiple(extras, BUGREPORT_FILE, BUGREPORT_CONTENT, PID, NEW_NAME, TITLE,
-                mDescription, 1);
+        assertActionSendMultiple(extras, BUGREPORT_FILE, BUGREPORT_CONTENT, PID, TITLE,
+                NEW_NAME, TITLE, mDescription, 1, true);
 
         assertServiceNotRunning();
     }
 
-    public void testProgress_bugreportFinishedWhileChangingDetails() throws Exception {
+    public void testProgress_changeDetailsPlainBugreport() throws Exception {
+        changeDetailsTest(true);
+    }
+
+    public void testProgress_changeDetailsZippedBugreport() throws Exception {
+        changeDetailsTest(false);
+    }
+
+    public void changeDetailsTest(boolean plainText) throws Exception {
+
         resetProperties();
         sendBugreportStarted(1000);
+        waitForScreenshotButtonEnabled(true);
+
+        DetailsUi detailsUi = new DetailsUi(mUiBot);
+
+        // Check initial name.
+        String actualName = detailsUi.nameField.getText().toString();
+        assertEquals("Wrong value on field 'name'", NAME, actualName);
+
+        // Change fields.
+        detailsUi.reOpen();
+        detailsUi.nameField.setText(NEW_NAME);
+        detailsUi.titleField.setText(TITLE);
+        detailsUi.descField.setText(mDescription);
+
+        detailsUi.clickOk();
+
+        assertPropertyValue(NAME_PROPERTY, NEW_NAME);
+        assertProgressNotification(NEW_NAME, "0.00%");
+
+        Bundle extras = sendBugreportFinishedAndGetSharedIntent(PID,
+                plainText? mPlainTextPath : mZipPath, mScreenshotPath);
+        assertActionSendMultiple(extras, BUGREPORT_FILE, BUGREPORT_CONTENT, PID, TITLE,
+                NEW_NAME, TITLE, mDescription, 1, true);
+
+        assertServiceNotRunning();
+    }
+
+    /**
+     * Tests the scenario where the initial screenshot and dumpstate are finished while the user
+     * is changing the info in the details screen.
+     */
+    public void testProgress_bugreportAndScreenshotFinishedWhileChangingDetails() throws Exception {
+        bugreportFinishedWhileChangingDetailsTest(false);
+    }
+
+    /**
+     * Tests the scenario where dumpstate is finished while the user is changing the info in the
+     * details screen, but the initial screenshot finishes afterwards.
+     */
+    public void testProgress_bugreportFinishedWhileChangingDetails() throws Exception {
+        bugreportFinishedWhileChangingDetailsTest(true);
+    }
+
+    private void bugreportFinishedWhileChangingDetailsTest(boolean waitScreenshot) throws Exception {
+        resetProperties();
+        sendBugreportStarted(1000);
+        if (waitScreenshot) {
+            waitForScreenshotButtonEnabled(true);
+        }
 
         DetailsUi detailsUi = new DetailsUi(mUiBot);
 
@@ -233,7 +301,7 @@
         detailsUi.nameField.setText(NEW_NAME);
         sendBugreportFinished(PID, mPlainTextPath, mScreenshotPath);
 
-        // Wait until the share notifcation is received...
+        // Wait until the share notification is received...
         mUiBot.getNotification(mContext.getString(R.string.bugreport_finished_title));
         // ...then close notification bar.
         mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
@@ -249,8 +317,8 @@
 
         // Finally, share bugreport.
         Bundle extras = acceptBugreportAndGetSharedIntent();
-        assertActionSendMultiple(extras, BUGREPORT_FILE, BUGREPORT_CONTENT, PID, NAME, TITLE,
-                mDescription, 1);
+        assertActionSendMultiple(extras, BUGREPORT_FILE, BUGREPORT_CONTENT, PID, TITLE,
+                NAME, TITLE, mDescription, 1, waitScreenshot);
 
         assertServiceNotRunning();
     }
@@ -275,7 +343,7 @@
         // Share the bugreport.
         mUiBot.chooseActivity(UI_NAME);
         Bundle extras = mListener.getExtras();
-        assertActionSendMultiple(extras, BUGREPORT_CONTENT, null);
+        assertActionSendMultiple(extras, BUGREPORT_CONTENT, NO_SCREENSHOT);
 
         // Make sure it's hidden now.
         int newState = BugreportPrefs.getWarningState(mContext, BugreportPrefs.STATE_UNKNOWN);
@@ -293,13 +361,13 @@
     }
 
     public void testBugreportFinished_plainBugreportAndNoScreenshot() throws Exception {
-        Bundle extras = sendBugreportFinishedAndGetSharedIntent(mPlainTextPath, null);
-        assertActionSendMultiple(extras, BUGREPORT_CONTENT, null);
+        Bundle extras = sendBugreportFinishedAndGetSharedIntent(mPlainTextPath, NO_SCREENSHOT);
+        assertActionSendMultiple(extras, BUGREPORT_CONTENT, NO_SCREENSHOT);
     }
 
     public void testBugreportFinished_zippedBugreportAndNoScreenshot() throws Exception {
-        Bundle extras = sendBugreportFinishedAndGetSharedIntent(mZipPath, null);
-        assertActionSendMultiple(extras, BUGREPORT_CONTENT, null);
+        Bundle extras = sendBugreportFinishedAndGetSharedIntent(mZipPath, NO_SCREENSHOT);
+        assertActionSendMultiple(extras, BUGREPORT_CONTENT, NO_SCREENSHOT);
     }
 
     private void cancelExistingNotifications() {
@@ -405,8 +473,8 @@
      */
     private void assertActionSendMultiple(Bundle extras, String bugreportContent,
             String screenshotContent) throws IOException {
-        assertActionSendMultiple(extras, bugreportContent, screenshotContent, PID, null, ZIP_FILE,
-                null, 0);
+        assertActionSendMultiple(extras, bugreportContent, screenshotContent, PID, ZIP_FILE,
+                NO_NAME, NO_TITLE, NO_DESCRIPTION, 0, false);
     }
 
     /**
@@ -416,14 +484,17 @@
      * @param bugreportContent expected content in the bugreport file
      * @param screenshotContent expected content in the screenshot file (sent by dumpstate), if any
      * @param pid emulated dumpstate pid
-     * @param name bugreport name as provided by the user
-     * @param title bugreport name as provided by the user (or received by dumpstate)
+     * @param name expected subject
+     * @param name bugreport name as provided by the user (or received by dumpstate)
+     * @param title bugreport name as provided by the user
      * @param description bugreport description as provided by the user
      * @param numberScreenshots expected number of screenshots taken by Shell.
+     * @param renamedScreenshots whether the screenshots are expected to be renamed
      */
     private void assertActionSendMultiple(Bundle extras, String bugreportContent,
-            String screenshotContent, int pid, String name, String title, String description,
-            int numberScreenshots) throws IOException {
+            String screenshotContent, int pid, String subject,
+            String name, String title, String description,
+            int numberScreenshots, boolean renamedScreenshots) throws IOException {
         String body = extras.getString(Intent.EXTRA_TEXT);
         assertContainsRegex("missing build info",
                 SystemProperties.get("ro.build.description"), body);
@@ -433,7 +504,7 @@
             assertContainsRegex("missing description", description, body);
         }
 
-        assertEquals("wrong subject", title, extras.getString(Intent.EXTRA_SUBJECT));
+        assertEquals("wrong subject", subject, extras.getString(Intent.EXTRA_SUBJECT));
 
         List<Uri> attachments = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
         int expectedNumberScreenshots = numberScreenshots;
@@ -456,6 +527,12 @@
         }
         assertNotNull("did not get .zip attachment", zipUri);
         assertZipContent(zipUri, BUGREPORT_FILE, BUGREPORT_CONTENT);
+        if (!TextUtils.isEmpty(title)) {
+            assertZipContent(zipUri, "title.txt", title);
+        }
+        if (!TextUtils.isEmpty(description)) {
+            assertZipContent(zipUri, "description.txt", description);
+        }
 
         // URI of the screenshot taken by dumpstate.
         Uri externalScreenshotUri = null;
@@ -480,7 +557,7 @@
         // Check internal screenshots.
         SortedSet<String> expectedNames = new TreeSet<>();
         for (int i = 1 ; i <= numberScreenshots; i++) {
-            String prefix = name != null ? name : Integer.toString(pid);
+            String prefix = renamedScreenshots  ? name : Integer.toString(pid);
             String expectedName = "screenshot-" + prefix + "-" + i + ".png";
             expectedNames.add(expectedName);
         }
@@ -592,7 +669,7 @@
 
     private UiObject waitForScreenshotButtonEnabled(boolean expectedEnabled) throws Exception {
         UiObject screenshotButton = getScreenshotButton();
-        int maxAttempts = SCREENSHOT_DELAY_SECONDS + 2;
+        int maxAttempts = SCREENSHOT_DELAY_SECONDS + 5;
         int i = 0;
         do {
             boolean enabled = screenshotButton.isEnabled();
diff --git a/packages/SystemUI/proguard.flags b/packages/SystemUI/proguard.flags
index 6a10c2c..bc18221 100644
--- a/packages/SystemUI/proguard.flags
+++ b/packages/SystemUI/proguard.flags
@@ -10,6 +10,7 @@
   public void setGlowScale(float);
 }
 
+-keep class com.android.systemui.statusbar.car.CarStatusBar
 -keep class com.android.systemui.statusbar.phone.PhoneStatusBar
 -keep class com.android.systemui.statusbar.tv.TvStatusBar
 
diff --git a/packages/SystemUI/res/drawable-hdpi/ic_sysbar_back_carmode.png b/packages/SystemUI/res/drawable-hdpi/ic_sysbar_back_carmode.png
new file mode 100644
index 0000000..6242084
--- /dev/null
+++ b/packages/SystemUI/res/drawable-hdpi/ic_sysbar_back_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-hdpi/ic_sysbar_back_ime_carmode.png b/packages/SystemUI/res/drawable-hdpi/ic_sysbar_back_ime_carmode.png
new file mode 100644
index 0000000..1b37a47
--- /dev/null
+++ b/packages/SystemUI/res/drawable-hdpi/ic_sysbar_back_ime_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-hdpi/ic_sysbar_home_carmode.png b/packages/SystemUI/res/drawable-hdpi/ic_sysbar_home_carmode.png
new file mode 100644
index 0000000..9e05758
--- /dev/null
+++ b/packages/SystemUI/res/drawable-hdpi/ic_sysbar_home_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-ldrtl-hdpi/ic_sysbar_back_carmode.png b/packages/SystemUI/res/drawable-ldrtl-hdpi/ic_sysbar_back_carmode.png
new file mode 100644
index 0000000..2fcfdde
--- /dev/null
+++ b/packages/SystemUI/res/drawable-ldrtl-hdpi/ic_sysbar_back_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-ldrtl-mdpi/ic_sysbar_back_carmode.png b/packages/SystemUI/res/drawable-ldrtl-mdpi/ic_sysbar_back_carmode.png
new file mode 100644
index 0000000..48708a5
--- /dev/null
+++ b/packages/SystemUI/res/drawable-ldrtl-mdpi/ic_sysbar_back_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-ldrtl-xhdpi/ic_sysbar_back_carmode.png b/packages/SystemUI/res/drawable-ldrtl-xhdpi/ic_sysbar_back_carmode.png
new file mode 100644
index 0000000..3d73184
--- /dev/null
+++ b/packages/SystemUI/res/drawable-ldrtl-xhdpi/ic_sysbar_back_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-ldrtl-xxhdpi/ic_sysbar_back_carmode.png b/packages/SystemUI/res/drawable-ldrtl-xxhdpi/ic_sysbar_back_carmode.png
new file mode 100644
index 0000000..786935d
--- /dev/null
+++ b/packages/SystemUI/res/drawable-ldrtl-xxhdpi/ic_sysbar_back_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/ic_sysbar_back_carmode.png b/packages/SystemUI/res/drawable-mdpi/ic_sysbar_back_carmode.png
new file mode 100644
index 0000000..e4bd4bc
--- /dev/null
+++ b/packages/SystemUI/res/drawable-mdpi/ic_sysbar_back_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/ic_sysbar_back_ime_carmode.png b/packages/SystemUI/res/drawable-mdpi/ic_sysbar_back_ime_carmode.png
new file mode 100644
index 0000000..94ccf79
--- /dev/null
+++ b/packages/SystemUI/res/drawable-mdpi/ic_sysbar_back_ime_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/ic_sysbar_home_carmode.png b/packages/SystemUI/res/drawable-mdpi/ic_sysbar_home_carmode.png
new file mode 100644
index 0000000..980bbbc
--- /dev/null
+++ b/packages/SystemUI/res/drawable-mdpi/ic_sysbar_home_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_back_carmode.png b/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_back_carmode.png
new file mode 100644
index 0000000..201be3b
--- /dev/null
+++ b/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_back_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_back_ime_carmode.png b/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_back_ime_carmode.png
new file mode 100644
index 0000000..2770d62
--- /dev/null
+++ b/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_back_ime_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_home_carmode.png b/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_home_carmode.png
new file mode 100644
index 0000000..8ac6493
--- /dev/null
+++ b/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_home_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xxhdpi/ic_sysbar_back_carmode.png b/packages/SystemUI/res/drawable-xxhdpi/ic_sysbar_back_carmode.png
new file mode 100644
index 0000000..8e3678b
--- /dev/null
+++ b/packages/SystemUI/res/drawable-xxhdpi/ic_sysbar_back_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xxhdpi/ic_sysbar_back_ime_carmode.png b/packages/SystemUI/res/drawable-xxhdpi/ic_sysbar_back_ime_carmode.png
new file mode 100644
index 0000000..6c7cb05
--- /dev/null
+++ b/packages/SystemUI/res/drawable-xxhdpi/ic_sysbar_back_ime_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xxhdpi/ic_sysbar_home_carmode.png b/packages/SystemUI/res/drawable-xxhdpi/ic_sysbar_home_carmode.png
new file mode 100644
index 0000000..ea2b108
--- /dev/null
+++ b/packages/SystemUI/res/drawable-xxhdpi/ic_sysbar_home_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xxxhdpi/ic_sysbar_back_carmode.png b/packages/SystemUI/res/drawable-xxxhdpi/ic_sysbar_back_carmode.png
new file mode 100644
index 0000000..3e11023
--- /dev/null
+++ b/packages/SystemUI/res/drawable-xxxhdpi/ic_sysbar_back_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xxxhdpi/ic_sysbar_back_ime_carmode.png b/packages/SystemUI/res/drawable-xxxhdpi/ic_sysbar_back_ime_carmode.png
new file mode 100644
index 0000000..fe8213d
--- /dev/null
+++ b/packages/SystemUI/res/drawable-xxxhdpi/ic_sysbar_back_ime_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xxxhdpi/ic_sysbar_docked.png b/packages/SystemUI/res/drawable-xxxhdpi/ic_sysbar_docked.png
new file mode 100644
index 0000000..f3be2ee
--- /dev/null
+++ b/packages/SystemUI/res/drawable-xxxhdpi/ic_sysbar_docked.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-xxxhdpi/ic_sysbar_home_carmode.png b/packages/SystemUI/res/drawable-xxxhdpi/ic_sysbar_home_carmode.png
new file mode 100644
index 0000000..c117efd
--- /dev/null
+++ b/packages/SystemUI/res/drawable-xxxhdpi/ic_sysbar_home_carmode.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable/docked_divider_handle.xml b/packages/SystemUI/res/drawable/docked_divider_handle.xml
deleted file mode 100644
index 84c0343..0000000
--- a/packages/SystemUI/res/drawable/docked_divider_handle.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<!--
-Copyright (C) 2015 The Android Open Source Project
-
-   Licensed under the Apache License, Version 2 (the "License");
-    you may not use this file except in compliance with the License.
-    You may obtain a copy of the License at
-
-         http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
--->
-<shape xmlns:android="http://schemas.android.com/apk/res/android"
-        android:shape="rectangle">
-    <size android:height="@dimen/docked_divider_handle_height"
-        android:width="@dimen/docked_divider_handle_width" />
-    <corners android:radius="1dp" />
-    <solid android:color="@color/docked_divider_handle" />
-</shape>
\ No newline at end of file
diff --git a/packages/SystemUI/res/layout/car_navigation_bar.xml b/packages/SystemUI/res/layout/car_navigation_bar.xml
new file mode 100644
index 0000000..f7f673d
--- /dev/null
+++ b/packages/SystemUI/res/layout/car_navigation_bar.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 2016, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<com.android.systemui.statusbar.car.CarNavigationBarView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_height="match_parent"
+    android:layout_width="match_parent"
+    android:background="@drawable/system_bar_background">
+
+    <!-- phone.NavigationBarView has rot0 and rot90 but we expect the car head unit to have a fixed
+         rotation so skip this level of the heirarchy.
+    -->
+    <LinearLayout
+        android:layout_height="match_parent"
+        android:layout_width="match_parent"
+        android:orientation="horizontal"
+        android:clipChildren="false"
+        android:clipToPadding="false"
+        android:id="@+id/nav_buttons"
+        android:animateLayoutChanges="true">
+
+        <!-- Buttons get populated here from a car_arrays.xml. -->
+    </LinearLayout>
+
+    <!-- lights out layout to match exactly -->
+    <LinearLayout
+        android:layout_height="match_parent"
+        android:layout_width="match_parent"
+        android:orientation="horizontal"
+        android:id="@+id/lights_out"
+        android:visibility="gone">
+        <!-- Must match nav_buttons. -->
+    </LinearLayout>
+
+</com.android.systemui.statusbar.car.CarNavigationBarView>
diff --git a/packages/SystemUI/res/layout/docked_stack_divider.xml b/packages/SystemUI/res/layout/docked_stack_divider.xml
index 22ed216..7ea5027 100644
--- a/packages/SystemUI/res/layout/docked_stack_divider.xml
+++ b/packages/SystemUI/res/layout/docked_stack_divider.xml
@@ -24,10 +24,9 @@
         android:id="@+id/docked_divider_background"
         android:background="@color/docked_divider_background"/>
 
-    <ImageButton
+    <com.android.systemui.stackdivider.DividerHandleView
         style="@style/DockedDividerHandle"
         android:id="@+id/docked_divider_handle"
-        android:background="@null"
-        android:src="@drawable/docked_divider_handle"/>
+        android:background="@null"/>
 
 </com.android.systemui.stackdivider.DividerView>
diff --git a/packages/SystemUI/res/layout/keyboard_shortcuts_view.xml b/packages/SystemUI/res/layout/keyboard_shortcuts_view.xml
new file mode 100644
index 0000000..460433e
--- /dev/null
+++ b/packages/SystemUI/res/layout/keyboard_shortcuts_view.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License
+  -->
+<RelativeLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/keyboard_shortcuts_wrapper"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:layout_marginTop="40dp"
+    android:focusable="true">
+</RelativeLayout>
diff --git a/packages/SystemUI/res/layout/notification_guts.xml b/packages/SystemUI/res/layout/notification_guts.xml
index 3cdee64..071b7c8 100644
--- a/packages/SystemUI/res/layout/notification_guts.xml
+++ b/packages/SystemUI/res/layout/notification_guts.xml
@@ -29,25 +29,22 @@
         android:background="@color/notification_guts_text_color" >
 
     <!-- header -->
-    <FrameLayout
+    <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:paddingBottom="8dp" >
+            android:paddingBottom="8dp"
+            android:paddingTop="8dp"
+            android:id="@+id/notification_guts_header"
+            android:orientation="horizontal"
+            android:layout_gravity="center_vertical|start">
 
-        <LinearLayout
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:id="@+id/notification_guts_header"
-                android:orientation="horizontal"
-                android:layout_gravity="center_vertical|start"
-                android:layout_marginEnd="52dp">
-                    <ImageView
-                            android:id="@android:id/icon"
-                            android:layout_width="18dp"
-                            android:layout_height="18dp"
-                            android:layout_marginEnd="3dp"
-                            android:src="@android:drawable/arrow_down_float" />
-                    <TextView
+        <ImageView
+                android:id="@android:id/icon"
+                android:layout_width="18dp"
+                android:layout_height="18dp"
+                android:layout_marginEnd="3dp"
+                android:src="@android:drawable/arrow_down_float" />
+        <TextView
                             android:id="@+id/pkgname"
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
@@ -55,7 +52,7 @@
                             android:layout_marginStart="3dp"
                             android:layout_marginEnd="4dp"
                             android:textColor="@color/notification_guts_title_color" />
-                    <TextView
+        <TextView
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:id="@+id/debug_info"
@@ -64,18 +61,7 @@
                             android:layout_gravity="bottom|start"
                             android:visibility="gone"
                             android:textColor="#ffffff" />
-        </LinearLayout>
-
-        <ImageButton style="@android:style/Widget.Material.Light.Button.Borderless.Small"
-                android:id="@+id/notification_inspect_item"
-                android:layout_width="52dp"
-                android:layout_height="wrap_content"
-                android:layout_weight="0"
-                android:gravity="center"
-                android:layout_gravity="center_vertical|end"
-                android:contentDescription="@string/status_bar_notification_inspect_item_title"
-                android:src="@drawable/ic_settings" />
-    </FrameLayout>
+    </LinearLayout>
     <!-- Importance slider -->
     <LinearLayout
             android:layout_width="match_parent"
@@ -157,4 +143,34 @@
                          android:visibility="gone"/>
         </RadioGroup>
     </LinearLayout>
+    <!-- buttons -->
+    <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:gravity="end"
+            android:paddingTop="8dp"
+            android:paddingBottom="16dp" >
+
+        <TextView
+            android:id="@+id/more_settings"
+            android:text="@string/notification_more_settings"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAppearance="@style/TextAppearance.NotificationGuts"
+            android:background="@drawable/btn_borderless_rect"
+            android:gravity="center"
+            android:paddingEnd="24dp"
+            android:paddingStart="12dp"
+            android:focusable="true" />
+
+        <TextView
+            android:id="@+id/done"
+            android:text="@string/notification_done"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textAppearance="@style/TextAppearance.NotificationGuts"
+            android:background="@drawable/btn_borderless_rect"
+            android:gravity="center"
+            android:focusable="true"/>
+    </LinearLayout>
 </com.android.systemui.statusbar.NotificationGuts>
diff --git a/packages/SystemUI/res/layout/recents_task_view.xml b/packages/SystemUI/res/layout/recents_task_view.xml
index 2b82b05..5b44c17 100644
--- a/packages/SystemUI/res/layout/recents_task_view.xml
+++ b/packages/SystemUI/res/layout/recents_task_view.xml
@@ -34,9 +34,10 @@
             android:layout_gravity="bottom|right"
             android:layout_marginRight="15dp"
             android:layout_marginBottom="15dp"
-            android:translationZ="2dp"
+            android:translationZ="4dp"
             android:contentDescription="@string/recents_lock_to_app_button_label"
-            android:background="@drawable/recents_lock_to_task_button_bg">
+            android:background="@drawable/recents_lock_to_task_button_bg"
+            android:visibility="invisible">
             <ImageView
                 android:layout_width="@dimen/recents_lock_to_app_icon_size"
                 android:layout_height="@dimen/recents_lock_to_app_icon_size"
diff --git a/packages/SystemUI/res/values-af/strings.xml b/packages/SystemUI/res/values-af/strings.xml
index f81bf23..0187993 100644
--- a/packages/SystemUI/res/values-af/strings.xml
+++ b/packages/SystemUI/res/values-af/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Wys hierdie kennisgewings sonder geluide"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Wys boaan die kennisgewinglys en maak \'n geluid"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Verskyn vlugtig op die skerm en maak \'n geluid"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Meer instellings"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Klaar"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Normale kleure"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Aandkleure"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Gepasmaakte kleure"</string>
diff --git a/packages/SystemUI/res/values-am/strings.xml b/packages/SystemUI/res/values-am/strings.xml
index d96e790..503a767 100644
--- a/packages/SystemUI/res/values-am/strings.xml
+++ b/packages/SystemUI/res/values-am/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"እነዚህን ማሳወቂያዎች በጸጥታ አሳይ"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"በማሳወቂያዎች ዝርዝር ላይኛው ክፍል ላይ አሳይና ድምፅ አሰማ"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"ወደ ገጸ ማያው ይመልከቱና ድምፅ ይቅረጹ"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"ተጨማሪ ቅንብሮች"</string>
+    <string name="notification_done" msgid="5279426047273930175">"ተከናውኗል"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"መደበኛ ቀለሞች"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"የለሊት ቀለሞች"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"ብጁ ቀለሞች"</string>
diff --git a/packages/SystemUI/res/values-ar/strings.xml b/packages/SystemUI/res/values-ar/strings.xml
index b3e494c..d89d036 100644
--- a/packages/SystemUI/res/values-ar/strings.xml
+++ b/packages/SystemUI/res/values-ar/strings.xml
@@ -464,6 +464,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"عرض هذه الإشعارات بدون تنبيه صوتي"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"العرض أعلى قائمة الإشعارات مع تنبيه صوتي"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"الظهور سريعًا على الشاشة مع تنبيه صوتي"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"المزيد من الإعدادات"</string>
+    <string name="notification_done" msgid="5279426047273930175">"تم"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"ألوان عادية"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"ألوان ليلية"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"ألوان مخصصة"</string>
diff --git a/packages/SystemUI/res/values-az-rAZ/strings.xml b/packages/SystemUI/res/values-az-rAZ/strings.xml
index 4efc5df..55f0841 100644
--- a/packages/SystemUI/res/values-az-rAZ/strings.xml
+++ b/packages/SystemUI/res/values-az-rAZ/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Bu bildişləri səssiz göstərin"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Bildirişlər siyahısında yuxarıda göstərin və səsli edin"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Ekranda nəzər salın və səsli edin"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Daha çox ayar"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Hazırdır"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Normal rənglər"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Gecə rəngləri"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Xüsusi rənglər"</string>
diff --git a/packages/SystemUI/res/values-b+sr+Latn/strings.xml b/packages/SystemUI/res/values-b+sr+Latn/strings.xml
index f482e96..4056963 100644
--- a/packages/SystemUI/res/values-b+sr+Latn/strings.xml
+++ b/packages/SystemUI/res/values-b+sr+Latn/strings.xml
@@ -455,12 +455,14 @@
     <string name="low_importance" msgid="4109929986107147930">"Mala važnost"</string>
     <string name="default_importance" msgid="8192107689995742653">"Uobičajena važnost"</string>
     <string name="high_importance" msgid="1527066195614050263">"Velika važnost"</string>
-    <string name="max_importance" msgid="5089005872719563894">"Najveća važnost"</string>
+    <string name="max_importance" msgid="5089005872719563894">"Važnost: hitno"</string>
     <string name="notification_importance_blocked" msgid="2397192642657872872">"Ova obaveštenja se nikada ne prikazuju"</string>
     <string name="notification_importance_low" msgid="4383563267370859725">"Prikazuju se u dnu liste obaveštenja bez zvuka"</string>
     <string name="notification_importance_default" msgid="4926529615920610817">"Ova obaveštenja se prikazuju bez zvuka"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Prikazuju se u vrhu liste obaveštenja i emituje se zvuk"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Nakratko se prikazuju na ekranu i emituje se zvuk"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Još podešavanja"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Gotovo"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Normalne boje"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Noćne boje"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Prilagođene boje"</string>
diff --git a/packages/SystemUI/res/values-bg/strings.xml b/packages/SystemUI/res/values-bg/strings.xml
index 95c4a22..93c26a4 100644
--- a/packages/SystemUI/res/values-bg/strings.xml
+++ b/packages/SystemUI/res/values-bg/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Тези известия се показват без звук"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Показване най-горе в списъка с известия и издаване на звуков сигнал"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Показване на екрана и издаване на звуков сигнал"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Още настройки"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Готово"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Нормални цветове"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Нощни цветове"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Персонализирани цветове"</string>
diff --git a/packages/SystemUI/res/values-bn-rBD/strings.xml b/packages/SystemUI/res/values-bn-rBD/strings.xml
index 38885d5..939465b6 100644
--- a/packages/SystemUI/res/values-bn-rBD/strings.xml
+++ b/packages/SystemUI/res/values-bn-rBD/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"নিঃশব্দে এই বিজ্ঞপ্তিগুলি দেখানো হয়"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"বিজ্ঞপ্তি তালিকার শীর্ষে দেখানো হয় এবং শব্দ করে"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"স্ক্রীনের উপরে দেখানো হয় এবং শব্দ করে"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"আরো সেটিংস"</string>
+    <string name="notification_done" msgid="5279426047273930175">"সম্পন্ন"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"স্বাভাবিক রঙ"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"রাতের রঙ"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"কাস্টম রঙ"</string>
diff --git a/packages/SystemUI/res/values-ca/strings.xml b/packages/SystemUI/res/values-ca/strings.xml
index d27c3ee..e19aa0e 100644
--- a/packages/SystemUI/res/values-ca/strings.xml
+++ b/packages/SystemUI/res/values-ca/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Mostra aquestes notificacions de manera silenciosa"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Mostra a la part superior de la llista de notificacions i emet un so"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Mostra a la pantalla i emet un so"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Més opcions"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Fet"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Colors normals"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Colors nocturns"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Colors personalitzats"</string>
diff --git a/packages/SystemUI/res/values-cs/strings.xml b/packages/SystemUI/res/values-cs/strings.xml
index 4f26dc1..b1cd561 100644
--- a/packages/SystemUI/res/values-cs/strings.xml
+++ b/packages/SystemUI/res/values-cs/strings.xml
@@ -462,6 +462,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Tato oznámení zobrazovat bez zvukového upozornění"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Tato oznámení zobrazovat na začátku seznamu a upozornit na ně zvukem"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Tato oznámení zobrazovat přímo na obrazovce a upozornit na ně zvukem"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Další nastavení"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Hotovo"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Normální barvy"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Noční barvy"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Vlastní barvy"</string>
diff --git a/packages/SystemUI/res/values-da/strings.xml b/packages/SystemUI/res/values-da/strings.xml
index 3f868a8..2100c57 100644
--- a/packages/SystemUI/res/values-da/strings.xml
+++ b/packages/SystemUI/res/values-da/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Vis disse underretninger lydløst"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Vis øverst på listen over underretninger, og giv lyd"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Vis på skærmen, og giv lyd"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Flere indstillinger"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Færdig"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Almindelige farver"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Nattefarver"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Tilpassede farver"</string>
diff --git a/packages/SystemUI/res/values-de/strings.xml b/packages/SystemUI/res/values-de/strings.xml
index 4c87758..1ad5b26 100644
--- a/packages/SystemUI/res/values-de/strings.xml
+++ b/packages/SystemUI/res/values-de/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Diese Benachrichtigungen ohne Ton anzeigen"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Mit Ton ganz oben in der Benachrichtigungsliste anzeigen"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Mit Ton auf dem Display einblenden"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Weitere Einstellungen"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Fertig"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Standardfarben"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Nachtfarben"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Benutzerdefinierte Farben"</string>
diff --git a/packages/SystemUI/res/values-el/strings.xml b/packages/SystemUI/res/values-el/strings.xml
index 21e1eee..f56d630 100644
--- a/packages/SystemUI/res/values-el/strings.xml
+++ b/packages/SystemUI/res/values-el/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Να εμφανίζονται αυτές οι ειδοποιήσεις χωρίς ήχο"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Να εμφανίζονται στην κορυφή της λίστας ειδοποιήσεων με ήχο"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Να προβάλλονται στην οθόνη και να συνοδεύονται από κάποιον ήχο"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Περισσότερες ρυθμίσεις"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Τέλος"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Κανονικά χρώματα"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Νυχτερινά χρώματα"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Προσαρμοσμένα χρώματα"</string>
diff --git a/packages/SystemUI/res/values-en-rAU/strings.xml b/packages/SystemUI/res/values-en-rAU/strings.xml
index fa8b6c33..f6fc997 100644
--- a/packages/SystemUI/res/values-en-rAU/strings.xml
+++ b/packages/SystemUI/res/values-en-rAU/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Silently show these notifications"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Show at the top of the notifications list and make sound"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Peek onto the screen and make sound"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"More settings"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Finished"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Normal colours"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Night colours"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Customised colours"</string>
diff --git a/packages/SystemUI/res/values-en-rGB/strings.xml b/packages/SystemUI/res/values-en-rGB/strings.xml
index fa8b6c33..f6fc997 100644
--- a/packages/SystemUI/res/values-en-rGB/strings.xml
+++ b/packages/SystemUI/res/values-en-rGB/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Silently show these notifications"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Show at the top of the notifications list and make sound"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Peek onto the screen and make sound"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"More settings"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Finished"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Normal colours"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Night colours"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Customised colours"</string>
diff --git a/packages/SystemUI/res/values-en-rIN/strings.xml b/packages/SystemUI/res/values-en-rIN/strings.xml
index fa8b6c33..f6fc997 100644
--- a/packages/SystemUI/res/values-en-rIN/strings.xml
+++ b/packages/SystemUI/res/values-en-rIN/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Silently show these notifications"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Show at the top of the notifications list and make sound"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Peek onto the screen and make sound"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"More settings"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Finished"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Normal colours"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Night colours"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Customised colours"</string>
diff --git a/packages/SystemUI/res/values-es-rUS/strings.xml b/packages/SystemUI/res/values-es-rUS/strings.xml
index 54850f0..fd59418 100644
--- a/packages/SystemUI/res/values-es-rUS/strings.xml
+++ b/packages/SystemUI/res/values-es-rUS/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Mostrar estas notificaciones de manera silenciosa"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Mostrar en la parte superior de la lista de notificaciones y emitir sonido"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Mostrar en la pantalla y emitir sonido"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Más opciones de configuración"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Listo"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Colores normales"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Colores nocturnos"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Colores personalizados"</string>
diff --git a/packages/SystemUI/res/values-es/strings.xml b/packages/SystemUI/res/values-es/strings.xml
index 41d83dc..223e684 100644
--- a/packages/SystemUI/res/values-es/strings.xml
+++ b/packages/SystemUI/res/values-es/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Mostrar estas notificaciones de forma silenciosa"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Mostrar en la parte superior de la lista de notificaciones y emitir sonido"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Mostrar en la pantalla y emitir sonido"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Más ajustes"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Listo"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Colores normales"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Colores nocturnos"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Colores personalizados"</string>
diff --git a/packages/SystemUI/res/values-et-rEE/strings.xml b/packages/SystemUI/res/values-et-rEE/strings.xml
index 9bb7898..f50e78c 100644
--- a/packages/SystemUI/res/values-et-rEE/strings.xml
+++ b/packages/SystemUI/res/values-et-rEE/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Kuva need märguanded vaikselt"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Kuva märguannete loendi ülaosas koos heliga"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Kuva ekraani servas koos heliga"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Rohkem seadeid"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Valmis"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Tavalised värvid"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Öised värvid"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Kohandatud värvid"</string>
diff --git a/packages/SystemUI/res/values-eu-rES/strings.xml b/packages/SystemUI/res/values-eu-rES/strings.xml
index e62303a..c481f52 100644
--- a/packages/SystemUI/res/values-eu-rES/strings.xml
+++ b/packages/SystemUI/res/values-eu-rES/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Erakutsi jakinarazpen hauek, baina soinurik egin gabe"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Erakutsi jakinarazpen hauek zerrendaren goialdean eta egin soinua"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Agerrarazi jakinarazpen hauek pantailan eta egin soinua"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Ezarpen gehiago"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Eginda"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Kolore normalak"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Gaueko koloreak"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Kolore pertsonalizatuak"</string>
diff --git a/packages/SystemUI/res/values-fa/strings.xml b/packages/SystemUI/res/values-fa/strings.xml
index f45c01b..3dee7c9 100644
--- a/packages/SystemUI/res/values-fa/strings.xml
+++ b/packages/SystemUI/res/values-fa/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"این اعلان‌ها بی‌صدا نشان داده شوند"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"در بالای فهرست اعلان‌ها و به همراه صدا نشان داده شود"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"در جلوی صفحه به همراه صدا نشان داده شود"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"تنظیمات بیشتر"</string>
+    <string name="notification_done" msgid="5279426047273930175">"تمام"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"رنگ‌های عادی"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"رنگ‌های شب"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"رنگ‌های سفارشی"</string>
diff --git a/packages/SystemUI/res/values-fi/strings.xml b/packages/SystemUI/res/values-fi/strings.xml
index af1a1e5..4a5c302 100644
--- a/packages/SystemUI/res/values-fi/strings.xml
+++ b/packages/SystemUI/res/values-fi/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Näytä nämä ilmoitukset huomaamattomasti"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Näytä ilmoitukset luettelon kärjessä ja toista merkkiääni"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Näytä ilmoitus näytöllä ja toista äänimerkki"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Lisäasetukset"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Valmis"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Tavalliset värit"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Yövärit"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Muokatut värit"</string>
diff --git a/packages/SystemUI/res/values-fr-rCA/strings.xml b/packages/SystemUI/res/values-fr-rCA/strings.xml
index 20a8bdc..2a4f4d9 100644
--- a/packages/SystemUI/res/values-fr-rCA/strings.xml
+++ b/packages/SystemUI/res/values-fr-rCA/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Afficher ces notifications en mode silencieux"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Afficher en haut de la liste des notifications et émettre un son"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Afficher sur l\'écran et émettre un son"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Plus de paramètres"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Terminé"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Couleurs normales"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Couleurs nocturnes"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Couleurs personnalisées"</string>
diff --git a/packages/SystemUI/res/values-fr/strings.xml b/packages/SystemUI/res/values-fr/strings.xml
index 8e76ee8..928a8b3 100644
--- a/packages/SystemUI/res/values-fr/strings.xml
+++ b/packages/SystemUI/res/values-fr/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Afficher ces notifications en mode silencieux"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Afficher en haut de la liste des notifications et émettre un son"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Afficher sur l\'écran et émettre un son"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Plus de paramètres"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Terminé"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Couleurs normales"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Couleurs nocturnes"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Couleurs personnalisées"</string>
diff --git a/packages/SystemUI/res/values-gl-rES/strings.xml b/packages/SystemUI/res/values-gl-rES/strings.xml
index 4562d89b..2a951f7 100644
--- a/packages/SystemUI/res/values-gl-rES/strings.xml
+++ b/packages/SystemUI/res/values-gl-rES/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Mostrar estas notificacións de forma silenciosa"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Mostrar na parte superior da lista de notificacións e emitir son"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Mostrar na pantalla e emitir son"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Máis opcións"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Feito"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Cores normais"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Cores nocturnas"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Cores personalizadas"</string>
diff --git a/packages/SystemUI/res/values-gu-rIN/strings.xml b/packages/SystemUI/res/values-gu-rIN/strings.xml
index 69174ef..f331ef9 100644
--- a/packages/SystemUI/res/values-gu-rIN/strings.xml
+++ b/packages/SystemUI/res/values-gu-rIN/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"આ સૂચનાઓ ચુપચાપ બતાવો"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"સૂચનાઓની સૂચિની ટોચ પર બતાવો અને અવાજ કરો"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"સ્ક્રીન પર ત્વરિત દ્રષ્ટિ કરો અને અવાજ કરો"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"વધુ સેટિંગ્સ"</string>
+    <string name="notification_done" msgid="5279426047273930175">"થઈ ગયું"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"સામાન્ય રંગો"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"રાત્રિ રંગો"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"કસ્ટમ રંગો"</string>
diff --git a/packages/SystemUI/res/values-hi/strings.xml b/packages/SystemUI/res/values-hi/strings.xml
index 1ab7f71..b31c1e0 100644
--- a/packages/SystemUI/res/values-hi/strings.xml
+++ b/packages/SystemUI/res/values-hi/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"ये नोटिफिकेशन मौन रूप से दिखाएं"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"नोटिफिकेशन सूची में सबसे ऊपर दिखाएं और ध्वनि चलाएं"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"स्‍क्रीन पर एक झलक दिखाएं और ध्‍वनि चलाएं"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"और सेटिंग"</string>
+    <string name="notification_done" msgid="5279426047273930175">"हो गया"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"सामान्य रंग"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"रात्रि के रंग"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"कस्टम रंग"</string>
diff --git a/packages/SystemUI/res/values-hr/strings.xml b/packages/SystemUI/res/values-hr/strings.xml
index a67258c..3bef6e9 100644
--- a/packages/SystemUI/res/values-hr/strings.xml
+++ b/packages/SystemUI/res/values-hr/strings.xml
@@ -461,6 +461,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Prikaži te obavijesti tiho"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Prikaži na vrhu popisa obavijesti i emitiraj zvučni signal"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Prikaži na zaslonu i emitiraj zvučni signal"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Više postavki"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Gotovo"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Uobičajene boje"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Noćne boje"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Prilagođene boje"</string>
diff --git a/packages/SystemUI/res/values-hu/strings.xml b/packages/SystemUI/res/values-hu/strings.xml
index 8589e95..8dc9a19 100644
--- a/packages/SystemUI/res/values-hu/strings.xml
+++ b/packages/SystemUI/res/values-hu/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Hang nélkül jelennek meg ezek az értesítések"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Az értesítési lista tetején jelennek meg hangjelzéssel"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Az értesítések felugranak a képernyőn hangjelzéssel"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"További beállítások"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Kész"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Hagyományos színek"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Esti színek"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Egyéni színek"</string>
diff --git a/packages/SystemUI/res/values-hy-rAM/strings.xml b/packages/SystemUI/res/values-hy-rAM/strings.xml
index 1b8de04..99d6980 100644
--- a/packages/SystemUI/res/values-hy-rAM/strings.xml
+++ b/packages/SystemUI/res/values-hy-rAM/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Ցուցադրել այս ծանուցումներն առանց ձայնային ազդանշանի"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Ցուցադրել ծանուցումների ցանկի վերևում և հնչեցնել ձայնային ազդանշան"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Ցուցադրել էկրանին և հնչեցնել ձայնային ազդանշան"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Այլ կարգավորումներ"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Պատրաստ է"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Սովորական գույներ"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Գիշերային գույներ"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Հատուկ գույներ"</string>
diff --git a/packages/SystemUI/res/values-in/strings.xml b/packages/SystemUI/res/values-in/strings.xml
index 9075484..f6124db 100644
--- a/packages/SystemUI/res/values-in/strings.xml
+++ b/packages/SystemUI/res/values-in/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Tunjukkan notifikasi ini tanpa suara"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Tunjukkan di bagian atas daftar notifikasi dan bunyikan suara"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Muncul di layar dan bunyikan suara"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Setelan lainnya"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Selesai"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Warna normal"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Warna malam"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Warna khusus"</string>
diff --git a/packages/SystemUI/res/values-is-rIS/strings.xml b/packages/SystemUI/res/values-is-rIS/strings.xml
index 556018c..7ea1746 100644
--- a/packages/SystemUI/res/values-is-rIS/strings.xml
+++ b/packages/SystemUI/res/values-is-rIS/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Sýna þessar tilkynningar án hljóðs"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Sýna efst á tilkynningalistanum og spila hljóð"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Birta á skjánum og spila hljóð"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Fleiri stillingar"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Lokið"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Venjulegir litir"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Næturlitir"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Sérsniðnir litir"</string>
diff --git a/packages/SystemUI/res/values-it/strings.xml b/packages/SystemUI/res/values-it/strings.xml
index b49c387..b395f8b 100644
--- a/packages/SystemUI/res/values-it/strings.xml
+++ b/packages/SystemUI/res/values-it/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Mostra silenziosamente queste notifiche"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Mostra nella parte superiore dell\'elenco delle notifiche e riproduci suono"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Apri sullo schermo e riproduci suono"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Altre impostazioni"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Fine"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Colori normali"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Colori per la notte"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Colori personalizzati"</string>
diff --git a/packages/SystemUI/res/values-iw/strings.xml b/packages/SystemUI/res/values-iw/strings.xml
index e6ac5af..2c894f5 100644
--- a/packages/SystemUI/res/values-iw/strings.xml
+++ b/packages/SystemUI/res/values-iw/strings.xml
@@ -462,6 +462,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"הצג את ההודעות האלה בלי להשמיע צליל"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"הצג בחלק העליון של רשימת ההודעות והשמע צליל"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"הצג לרגע על המסך והשמע צליל"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"הגדרות נוספות"</string>
+    <string name="notification_done" msgid="5279426047273930175">"סיום"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"צבעים רגילים"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"צבעי לילה"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"צבעים מותאמים אישית"</string>
diff --git a/packages/SystemUI/res/values-ja/strings.xml b/packages/SystemUI/res/values-ja/strings.xml
index e7e3a86..580d995 100644
--- a/packages/SystemUI/res/values-ja/strings.xml
+++ b/packages/SystemUI/res/values-ja/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"この通知をマナーモードで表示する"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"通知リストの先頭に表示し、音声でも知らせる"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"画面に数秒間表示し、音声でも知らせる"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"詳細設定"</string>
+    <string name="notification_done" msgid="5279426047273930175">"完了"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"標準の色"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"夜間の色"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"カスタムの色"</string>
diff --git a/packages/SystemUI/res/values-ka-rGE/strings.xml b/packages/SystemUI/res/values-ka-rGE/strings.xml
index 79e0f4f..7a51668 100644
--- a/packages/SystemUI/res/values-ka-rGE/strings.xml
+++ b/packages/SystemUI/res/values-ka-rGE/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"ამ შეტყობინებების უხმოდ ჩვენება"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"ამ შეტყობინებების სიის თავში, ხმოვან სიგნალთან ერთად ჩვენება"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"ამ შეტყობინებების პირდაპირ ეკრანზე, ხმოვან სიგნალთან ერთად ჩვენება"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"დამატებითი პარამეტრები"</string>
+    <string name="notification_done" msgid="5279426047273930175">"მზადაა"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"ჩვეულებრივი ფერები"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"ღამის ფერები"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"მორგებული ფერები"</string>
diff --git a/packages/SystemUI/res/values-kk-rKZ/strings.xml b/packages/SystemUI/res/values-kk-rKZ/strings.xml
index 5187b54..eb8995e 100644
--- a/packages/SystemUI/res/values-kk-rKZ/strings.xml
+++ b/packages/SystemUI/res/values-kk-rKZ/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Осы хабарландыруларды үнсіз көрсету"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Хабарландыруларды тізімінің жоғарғы жағында көрсету және дыбыс шығару"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Экранға бекіту және дыбыс шығару"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Қосымша параметрлер"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Дайын"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Қалыпты түстер"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Түнгі түстер"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Арнаулы түстер"</string>
diff --git a/packages/SystemUI/res/values-km-rKH/strings.xml b/packages/SystemUI/res/values-km-rKH/strings.xml
index 5665a90..5c10213 100644
--- a/packages/SystemUI/res/values-km-rKH/strings.xml
+++ b/packages/SystemUI/res/values-km-rKH/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"បង្ហាញការជូនដំណឹងទាំងនេះស្ងាត់ៗ"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"បង្ហាញនៅផ្នែកខាងលើបញ្ជីនៃការជូនដំណឹង និងបន្លឺសំឡេង"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"លោតបង្ហាញនៅលើអេក្រង់ និងបន្លឺសំឡេង"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"ការកំណត់ច្រើនទៀត"</string>
+    <string name="notification_done" msgid="5279426047273930175">"រួចរាល់"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"ពណ៌ធម្មតា"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"ពណ៌ពេលយប់"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"ពណ៌ផ្ទាល់ខ្លួន"</string>
diff --git a/packages/SystemUI/res/values-kn-rIN/strings.xml b/packages/SystemUI/res/values-kn-rIN/strings.xml
index 0326a67..28b2de5 100644
--- a/packages/SystemUI/res/values-kn-rIN/strings.xml
+++ b/packages/SystemUI/res/values-kn-rIN/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"ಈ ಅಧಿಸೂಚನೆಗಳನ್ನು ಸ್ಥಬ್ಧವಾಗಿ ತೋರಿಸು"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"ಅಧಿಸೂಚನೆಗಳ ಪಟ್ಟಿಯ ಮೇಲ್ಭಾಗದಲ್ಲಿ ತೋರಿಸು ಮತ್ತು ಧ್ವನಿ ಮಾಡು"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"ಪರದೆಯನ್ನು ವೀಕ್ಷಿಸಿ ಮತ್ತು ಧ್ವನಿ ಮಾಡು"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"ಹೆಚ್ಚಿನ ಸೆಟ್ಟಿಂಗ್‌ಗಳು"</string>
+    <string name="notification_done" msgid="5279426047273930175">"ಮುಗಿದಿದೆ"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"ಸಾಮಾನ್ಯ ಬಣ್ಣಗಳು"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"ರಾತ್ರಿ ಬಣ್ಣಗಳು"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"ಕಸ್ಟಮ್ ಬಣ್ಣಗಳು"</string>
diff --git a/packages/SystemUI/res/values-ko/strings.xml b/packages/SystemUI/res/values-ko/strings.xml
index b910c04..110376f 100644
--- a/packages/SystemUI/res/values-ko/strings.xml
+++ b/packages/SystemUI/res/values-ko/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"무음으로 알림 표시"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"알림 목록 상단에 표시하고 소리로 알림"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"화면에 표시하고 소리로 알림"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"설정 더보기"</string>
+    <string name="notification_done" msgid="5279426047273930175">"완료"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"일반 색상"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"야간 색상"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"맞춤 색상"</string>
diff --git a/packages/SystemUI/res/values-ky-rKG/strings.xml b/packages/SystemUI/res/values-ky-rKG/strings.xml
index e703e00..ee2ef5d 100644
--- a/packages/SystemUI/res/values-ky-rKG/strings.xml
+++ b/packages/SystemUI/res/values-ky-rKG/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Бул эскертмелер үнсүз көрсөтүлсүн"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Эскертмелер тизмесинин эң жогорусунда үн чыгарып көрсөтүлсүн"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Үн менен коштолуп, экранга чыгарылсын"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Дагы жөндөөлөр"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Аткарылды"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Кадимки түстөр"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Түнкү түстөр"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Ыңгайлаштырылган түстөр"</string>
diff --git a/packages/SystemUI/res/values-lo-rLA/strings.xml b/packages/SystemUI/res/values-lo-rLA/strings.xml
index 8e43408..ed103ea 100644
--- a/packages/SystemUI/res/values-lo-rLA/strings.xml
+++ b/packages/SystemUI/res/values-lo-rLA/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"ສະແດງການແຈ້ງເຕືອນເຫຼົ່ານີ້ແບບບໍ່ມີສຽງ"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"ສະແດງຢູ່ສ່ວນເທິງຂອງລາຍການແຈ້ງເຕືອນ ແລະສົ່ງສຽງດັງ"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"ເດັ້ງຂຶ້ນເທິງຫນ້າຈໍ ແລະສົ່ງສຽງດັງ"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"​ການ​ຕັ້ງ​ຄ່າ​ເພີ່ມ​ເຕີມ"</string>
+    <string name="notification_done" msgid="5279426047273930175">"ສຳເລັດແລ້ວ"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"ສີ​ປົກ​ກະ​ຕິ"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"ສີ​ຕອນ​ກາງ​ຄືນ"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"ສີແບບກຳນົດເອງ"</string>
diff --git a/packages/SystemUI/res/values-lt/strings.xml b/packages/SystemUI/res/values-lt/strings.xml
index 04066a7..ba98e2b 100644
--- a/packages/SystemUI/res/values-lt/strings.xml
+++ b/packages/SystemUI/res/values-lt/strings.xml
@@ -462,6 +462,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Tyliai rodyti šiuos pranešimus"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Rodyti pranešimų sąrašo viršuje ir skambėti"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Rodyti ekrane ir skambėti"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Daugiau nustatymų"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Atlikta"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Įprastos spalvos"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Nakties spalvos"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Tinkintos spalvos"</string>
diff --git a/packages/SystemUI/res/values-lv/strings.xml b/packages/SystemUI/res/values-lv/strings.xml
index 649d07b..0143fea 100644
--- a/packages/SystemUI/res/values-lv/strings.xml
+++ b/packages/SystemUI/res/values-lv/strings.xml
@@ -461,6 +461,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Rādīt šos paziņojumus bez skaņas signāla"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Rādīt paziņojumu saraksta augšdaļā un ar skaņas signālu"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Rādīt ekrānā ar skaņas signālu"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Citi iestatījumi"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Gatavs"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Parastas krāsas"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Nakts krāsas"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Pielāgotas krāsas"</string>
diff --git a/packages/SystemUI/res/values-mk-rMK/strings.xml b/packages/SystemUI/res/values-mk-rMK/strings.xml
index 928bbcd..c573139 100644
--- a/packages/SystemUI/res/values-mk-rMK/strings.xml
+++ b/packages/SystemUI/res/values-mk-rMK/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Тивко прикажувај ги известувањава"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Прикажувај ги на врвот на списокот со известувања и дај звучен сигнал"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Појави се на екранот и дај звучен сигнал"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Повеќе поставки"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Готово"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Нормални бои"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Ноќни бои"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Приспособени бои"</string>
diff --git a/packages/SystemUI/res/values-ml-rIN/strings.xml b/packages/SystemUI/res/values-ml-rIN/strings.xml
index 2f4b81a..c6a08e6 100644
--- a/packages/SystemUI/res/values-ml-rIN/strings.xml
+++ b/packages/SystemUI/res/values-ml-rIN/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"ഈ അറിയിപ്പുകൾ നിശബ്ദമായി കാണിക്കുക"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"അറിയിപ്പ് ലിസ്റ്റിന്റെ ഏറ്റവും മുകളിൽ കാണിക്കുക, ശബ്ദമുണ്ടാക്കുക"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"സ്ക്രീനിൽ ദൃശ്യമാക്കുക, ശബ്ദമുണ്ടാക്കുക"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"കൂടുതൽ ക്രമീകരണം"</string>
+    <string name="notification_done" msgid="5279426047273930175">"പൂർത്തിയായി"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"സാധാരണ വര്‍ണ്ണങ്ങൾ"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"രാത്രി വര്‍ണ്ണങ്ങൾ"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"ഇഷ്ടാനുസൃത വര്‍ണ്ണങ്ങൾ"</string>
diff --git a/packages/SystemUI/res/values-mn-rMN/strings.xml b/packages/SystemUI/res/values-mn-rMN/strings.xml
index 3dd084e..91c817a 100644
--- a/packages/SystemUI/res/values-mn-rMN/strings.xml
+++ b/packages/SystemUI/res/values-mn-rMN/strings.xml
@@ -458,6 +458,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Эдгээр мэдэгдлийг дуугүй харуулах"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Мэдэгдлийг жагсаалтын эхэнд дуутай харуулах"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Дэлгэцэнд яаралтайгаар дуутай гаргах"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Бусад тохиргоо"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Дууссан"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Хэвийн өнгө"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Шөнийн өнгө"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Өгөгдмөл өнгө"</string>
diff --git a/packages/SystemUI/res/values-mr-rIN/strings.xml b/packages/SystemUI/res/values-mr-rIN/strings.xml
index 59eadf1..5d3a96f 100644
--- a/packages/SystemUI/res/values-mr-rIN/strings.xml
+++ b/packages/SystemUI/res/values-mr-rIN/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"या सूचना शांतपणे दर्शवा"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"सूचना सूचीच्या शीर्षस्थानी दर्शवा आणि ध्वनी चालू करा"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"स्क्रीनवर डोकावून पहा आणि ध्वनी चालू करा"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"अधिक सेटिंग्ज"</string>
+    <string name="notification_done" msgid="5279426047273930175">"पूर्ण झाले"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"सामान्य रंग"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"रात्रीचे रंग"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"सानुकूल रंग"</string>
diff --git a/packages/SystemUI/res/values-ms-rMY/strings.xml b/packages/SystemUI/res/values-ms-rMY/strings.xml
index 5dd221a..f0a013c 100644
--- a/packages/SystemUI/res/values-ms-rMY/strings.xml
+++ b/packages/SystemUI/res/values-ms-rMY/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Tunjukkan pemberitahuan ini secara senyap"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Tunjukkan pada bahagian atas senarai pemberitahuan dan bunyikan"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Intai pada skrin dan bunyikan"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Lagi tetapan"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Selesai"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Warna biasa"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Warna malam"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Warna tersuai"</string>
diff --git a/packages/SystemUI/res/values-my-rMM/strings.xml b/packages/SystemUI/res/values-my-rMM/strings.xml
index 293e010..75008cb 100644
--- a/packages/SystemUI/res/values-my-rMM/strings.xml
+++ b/packages/SystemUI/res/values-my-rMM/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"ဤသတိပေးချက်များကို တိတ်တဆိတ်ပြပါ"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"သတိပေးချက်စာရင်းများ၏ ထိပ်တွင်ပြကာ အသံဖွင့်ပါ"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"မျက်နှာပြင်ပေါ်သို့ ဖော်ပြကာ အသံဖွင့်ပါ"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"နောက်ထပ် ဆက်တင်များ"</string>
+    <string name="notification_done" msgid="5279426047273930175">"ပြီးပါပြီ"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"ပုံမှန် အရောင်များ"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"ည အရောင်များ"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"စိတ်ကြိုက် အရောင်များ"</string>
diff --git a/packages/SystemUI/res/values-nb/strings.xml b/packages/SystemUI/res/values-nb/strings.xml
index ffc2fcf..295a49a 100644
--- a/packages/SystemUI/res/values-nb/strings.xml
+++ b/packages/SystemUI/res/values-nb/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Vis disse varslene uten lyd"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Vis øverst på varsellisten med lyd"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Vis fort på skjermen med lyd"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Flere innstillinger"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Ferdig"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Normale farger"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Nattfarger"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Spesialtilpassede farger"</string>
diff --git a/packages/SystemUI/res/values-ne-rNP/strings.xml b/packages/SystemUI/res/values-ne-rNP/strings.xml
index 6f40d55..d0aa510 100644
--- a/packages/SystemUI/res/values-ne-rNP/strings.xml
+++ b/packages/SystemUI/res/values-ne-rNP/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"यी सूचनाहरू बिना आवाज देखाउनुहोस्"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"सूचना सूचीको शीर्षमा देखाउनुहोस् र आवाज निकाल्नुहोस्"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"स्क्रिनमा हेर्नुहोस् र आवाज निकाल्नुहोस्"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"थप सेटिङहरू"</string>
+    <string name="notification_done" msgid="5279426047273930175">"सम्पन्‍न भयो"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"सामान्य रङहरू"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"रात्री रङहरू"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"अनुकूलन रङहरू"</string>
diff --git a/packages/SystemUI/res/values-nl/strings.xml b/packages/SystemUI/res/values-nl/strings.xml
index 27eb1d11..75812ad 100644
--- a/packages/SystemUI/res/values-nl/strings.xml
+++ b/packages/SystemUI/res/values-nl/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Deze meldingen zonder geluid weergeven"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Boven aan de lijst met meldingen weergeven en geluid laten horen"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Op het scherm weergeven en geluid laten horen"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Meer instellingen"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Gereed"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Normale kleuren"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Nachtkleuren"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Aangepaste kleuren"</string>
diff --git a/packages/SystemUI/res/values-pa-rIN/strings.xml b/packages/SystemUI/res/values-pa-rIN/strings.xml
index 2dd91ec..fc5a3ea 100644
--- a/packages/SystemUI/res/values-pa-rIN/strings.xml
+++ b/packages/SystemUI/res/values-pa-rIN/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"ਇਹਨਾਂ ਸੂਚਨਾਵਾਂ ਨੂੰ ਚੁੱਪਚਾਪ ਢੰਗ ਨਾਲ ਵਿਖਾਓ"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"ਸੂਚਨਾਵਾਂ ਸੂਚੀ ਦੇ ਸਿਖਰ \'ਤੇ ਵਿਖਾਓ ਅਤੇ ਆਵਾਜ਼ ਕਰੋ"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"ਸਕਰੀਨ \'ਤੇ ਝਾਤੀ ਮਾਰੋ ਅਤੇ ਆਵਾਜ਼ ਕਰੋ"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"ਹੋਰ ਸੈਟਿੰਗਾਂ"</string>
+    <string name="notification_done" msgid="5279426047273930175">"ਹੋ ਗਿਆ"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"ਸਧਾਰਨ ਰੰਗ"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"ਰਾਤ ਦੇ ਰੰਗ"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"ਕਸਟਮ ਰੰਗ"</string>
diff --git a/packages/SystemUI/res/values-pl/strings.xml b/packages/SystemUI/res/values-pl/strings.xml
index bf222bc..8ef50c9 100644
--- a/packages/SystemUI/res/values-pl/strings.xml
+++ b/packages/SystemUI/res/values-pl/strings.xml
@@ -462,6 +462,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Pokazuj te powiadomienia bez sygnału dźwiękowego"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Pokazuj na górze listy powiadomień i sygnalizuj dźwiękiem"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Wyświetlaj na ekranie i odtwarzaj dźwięk"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Więcej ustawień"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Gotowe"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Kolory standardowe"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Kolory nocne"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Kolory niestandardowe"</string>
diff --git a/packages/SystemUI/res/values-pt-rBR/strings.xml b/packages/SystemUI/res/values-pt-rBR/strings.xml
index 5d43efa..8f61478 100644
--- a/packages/SystemUI/res/values-pt-rBR/strings.xml
+++ b/packages/SystemUI/res/values-pt-rBR/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Mostrar essas notificações de forma silenciosa"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Mostrar na parte superior da lista de notificações e emitir som"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Mostrar parcialmente na tela e emitir som"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Mais configurações"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Concluído"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Cores normais"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Cores noturnas"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Cores personalizadas"</string>
diff --git a/packages/SystemUI/res/values-pt-rPT/strings.xml b/packages/SystemUI/res/values-pt-rPT/strings.xml
index 44ecd41..8a727a1 100644
--- a/packages/SystemUI/res/values-pt-rPT/strings.xml
+++ b/packages/SystemUI/res/values-pt-rPT/strings.xml
@@ -425,7 +425,7 @@
     <string name="status_bar_airplane" msgid="7057575501472249002">"Modo de avião"</string>
     <string name="add_tile" msgid="2995389510240786221">"Adicionar mosaico"</string>
     <string name="broadcast_tile" msgid="3894036511763289383">"Mosaico de transmissão"</string>
-    <string name="zen_alarm_warning_indef" msgid="3482966345578319605">"Só vai ouvir o próximo alarme às <xliff:g id="WHEN">%1$s</xliff:g> se desativar esta funcionalidade antes dessa hora"</string>
+    <string name="zen_alarm_warning_indef" msgid="3482966345578319605">"Só vai ouvir o próximo alarme (<xliff:g id="WHEN">%1$s</xliff:g>) se desativar esta funcionalidade antes dessa hora"</string>
     <string name="zen_alarm_warning" msgid="444533119582244293">"Não vai ouvir o próximo alarme às <xliff:g id="WHEN">%1$s</xliff:g>"</string>
     <string name="alarm_template" msgid="3980063409350522735">"às <xliff:g id="WHEN">%1$s</xliff:g>"</string>
     <string name="alarm_template_far" msgid="4242179982586714810">"em <xliff:g id="WHEN">%1$s</xliff:g>"</string>
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Mostrar estas notificações sem som"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Mostrar na parte superior da lista de notificações e emitir som"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Mostrar no ecrã e emitir som"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Mais definições"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Concluído"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Cores normais"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Cores noturnas"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Cores personalizadas"</string>
diff --git a/packages/SystemUI/res/values-pt/strings.xml b/packages/SystemUI/res/values-pt/strings.xml
index 5d43efa..8f61478 100644
--- a/packages/SystemUI/res/values-pt/strings.xml
+++ b/packages/SystemUI/res/values-pt/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Mostrar essas notificações de forma silenciosa"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Mostrar na parte superior da lista de notificações e emitir som"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Mostrar parcialmente na tela e emitir som"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Mais configurações"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Concluído"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Cores normais"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Cores noturnas"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Cores personalizadas"</string>
diff --git a/packages/SystemUI/res/values-ro/strings.xml b/packages/SystemUI/res/values-ro/strings.xml
index e9e7bdc..3ab8bf2 100644
--- a/packages/SystemUI/res/values-ro/strings.xml
+++ b/packages/SystemUI/res/values-ro/strings.xml
@@ -461,6 +461,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Aceste notificări se afișează fără a se emite un sunet"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Se afișează în partea de sus a listei cu notificări și se emite un sunet"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Se afișează pentru o scurtă durată pe ecran și se emite un sunet"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Mai multe setări"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Terminat"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Culori normale"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Culori de noapte"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Culori personalizate"</string>
diff --git a/packages/SystemUI/res/values-ru/strings.xml b/packages/SystemUI/res/values-ru/strings.xml
index b68b434..6ffd333 100644
--- a/packages/SystemUI/res/values-ru/strings.xml
+++ b/packages/SystemUI/res/values-ru/strings.xml
@@ -462,6 +462,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Показывать уведомления без звука."</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Показывать со звуком в начале списка уведомлений."</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Показывать со звуком поверх всех окон."</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Другие настройки"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Готово"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Обычные цвета"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Ночные цвета"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Собственные цвета"</string>
diff --git a/packages/SystemUI/res/values-si-rLK/strings.xml b/packages/SystemUI/res/values-si-rLK/strings.xml
index b9f7e53..efbc042 100644
--- a/packages/SystemUI/res/values-si-rLK/strings.xml
+++ b/packages/SystemUI/res/values-si-rLK/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"නිශ්ශබ්දව මෙම දැනුම්දීම් පෙන්වන්න"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"දැනුම්දීම් ලැයිස්තුවෙහි ඉහළින්ම පෙන්වන්න සහ ශබ්ද කරන්න"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"තිරයට පැමිණ ශබ්ද කරන්න"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"තව සැකසීම්"</string>
+    <string name="notification_done" msgid="5279426047273930175">"නිමයි"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"සාමාන්‍ය වර්ණ"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"රාත්‍රී වර්ණ"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"අභිරුචි වර්ණ"</string>
diff --git a/packages/SystemUI/res/values-sk/strings.xml b/packages/SystemUI/res/values-sk/strings.xml
index 91a143e..31985b4 100644
--- a/packages/SystemUI/res/values-sk/strings.xml
+++ b/packages/SystemUI/res/values-sk/strings.xml
@@ -462,6 +462,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Tieto upozornenia zobrazovať bez zvukového signálu"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Zobrazovať v hornej časti zoznamu upozornení so zvukovým signálom"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Zobrazovať cez obrazovku so zvukovým signálom"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Ďalšie nastavenia"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Hotovo"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Normálne farby"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Nočné farby"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Vlastné farby"</string>
diff --git a/packages/SystemUI/res/values-sl/strings.xml b/packages/SystemUI/res/values-sl/strings.xml
index 96974ae..7c8d443 100644
--- a/packages/SystemUI/res/values-sl/strings.xml
+++ b/packages/SystemUI/res/values-sl/strings.xml
@@ -462,6 +462,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Prikaži ta obvestila brez zvoka"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Prikaži na vrhu seznama obvestil in predvajaj zvok"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Za hip pokaži predogled na zaslonu in predvajaj zvok"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Več nastavitev"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Dokončano"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Običajne barve"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Nočne barve"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Barve po meri"</string>
diff --git a/packages/SystemUI/res/values-sq-rAL/strings.xml b/packages/SystemUI/res/values-sq-rAL/strings.xml
index b904ae1..c8add94 100644
--- a/packages/SystemUI/res/values-sq-rAL/strings.xml
+++ b/packages/SystemUI/res/values-sq-rAL/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Shfaqi këto njoftime në heshtje"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Shfaqi në krye të listës së njoftimeve dhe lësho tingull"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Shfaq një vështrim të shpejtë në ekran dhe lësho tingull"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Cilësime të tjera"</string>
+    <string name="notification_done" msgid="5279426047273930175">"U krye"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Ngjyrat normale"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Ngjyrat e natës"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Ngjyrat e personalizuara"</string>
diff --git a/packages/SystemUI/res/values-sr/strings.xml b/packages/SystemUI/res/values-sr/strings.xml
index 6470fcc..bec1fd4 100644
--- a/packages/SystemUI/res/values-sr/strings.xml
+++ b/packages/SystemUI/res/values-sr/strings.xml
@@ -455,12 +455,14 @@
     <string name="low_importance" msgid="4109929986107147930">"Мала важност"</string>
     <string name="default_importance" msgid="8192107689995742653">"Уобичајена важност"</string>
     <string name="high_importance" msgid="1527066195614050263">"Велика важност"</string>
-    <string name="max_importance" msgid="5089005872719563894">"Највећа важност"</string>
+    <string name="max_importance" msgid="5089005872719563894">"Важност: хитно"</string>
     <string name="notification_importance_blocked" msgid="2397192642657872872">"Ова обавештења се никада не приказују"</string>
     <string name="notification_importance_low" msgid="4383563267370859725">"Приказују се у дну листе обавештења без звука"</string>
     <string name="notification_importance_default" msgid="4926529615920610817">"Ова обавештења се приказују без звука"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Приказују се у врху листе обавештења и емитује се звук"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Накратко се приказују на екрану и емитује се звук"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Још подешавања"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Готово"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Нормалне боје"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Ноћне боје"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Прилагођене боје"</string>
diff --git a/packages/SystemUI/res/values-sv/strings.xml b/packages/SystemUI/res/values-sv/strings.xml
index 5f2b397..d4a9cdc 100644
--- a/packages/SystemUI/res/values-sv/strings.xml
+++ b/packages/SystemUI/res/values-sv/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Visa aviseringarna utan ljud"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Visa högst upp på listan, med ljud"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Visa på skärmen, med ljud"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Fler inställningar"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Klar"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Normala färger"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Nattfärger"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Anpassade färger"</string>
diff --git a/packages/SystemUI/res/values-sw/strings.xml b/packages/SystemUI/res/values-sw/strings.xml
index 8f962da..2ffbf2b 100644
--- a/packages/SystemUI/res/values-sw/strings.xml
+++ b/packages/SystemUI/res/values-sw/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Onyesha arifa hizi bila sauti"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Onyesha katika sehemu ya juu ya orodha ya arifa na itoe sauti"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Weka onyesho la kuchungulia kwenye skrini na itoe sauti"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Mipangilio zaidi"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Nimemaliza"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Rangi za kawaida"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Rangi za usiku"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Rangi maalum"</string>
diff --git a/packages/SystemUI/res/values-ta-rIN/strings.xml b/packages/SystemUI/res/values-ta-rIN/strings.xml
index a625c6f..168a11b 100644
--- a/packages/SystemUI/res/values-ta-rIN/strings.xml
+++ b/packages/SystemUI/res/values-ta-rIN/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"ஒலியின்றி இந்த அறிவிப்புகளைக் காட்டு"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"அறிவிப்புகள் பட்டியலின் மேல் பகுதியில் ஒலியுடன் காட்டு"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"ஒலியுடன் திரையில் காட்டு"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"மேலும் அமைப்புகள்"</string>
+    <string name="notification_done" msgid="5279426047273930175">"முடிந்தது"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"இயல்பான வண்ணங்கள்"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"இரவுநேர வண்ணங்கள்"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"தனிப்பயன் வண்ணங்கள்"</string>
diff --git a/packages/SystemUI/res/values-te-rIN/strings.xml b/packages/SystemUI/res/values-te-rIN/strings.xml
index 9d1403f..086dede 100644
--- a/packages/SystemUI/res/values-te-rIN/strings.xml
+++ b/packages/SystemUI/res/values-te-rIN/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"ఈ నోటిఫికేషన్‌లను శబ్దం లేకుండా చూపుతుంది"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"నోటిఫికేషన్‌ల జాబితా ఎగువ భాగంలో శబ్దంతో చూపుతుంది"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"స్క్రీన్‌పై శీఘ్రంగా శబ్దంతో చూపుతుంది"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"మరిన్ని సెట్టింగ్‌లు"</string>
+    <string name="notification_done" msgid="5279426047273930175">"పూర్తయింది"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"సాధారణ రంగులు"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"రాత్రి రంగులు"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"అనుకూల రంగులు"</string>
diff --git a/packages/SystemUI/res/values-th/strings.xml b/packages/SystemUI/res/values-th/strings.xml
index 38e028c..8c1a7d3 100644
--- a/packages/SystemUI/res/values-th/strings.xml
+++ b/packages/SystemUI/res/values-th/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"แสดงการแจ้งเตือนเหล่านี้โดยไม่ส่งเสียง"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"แสดงที่ด้านบนของรายการแจ้งเตือนและส่งเสียง"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"แสดงบนหน้าจอในช่วงเวลาสั้นๆ และส่งเสียง"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"การตั้งค่าเพิ่มเติม"</string>
+    <string name="notification_done" msgid="5279426047273930175">"เสร็จสิ้น"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"สีปกติ"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"สียามค่ำคืน"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"สีที่กำหนดเอง"</string>
diff --git a/packages/SystemUI/res/values-tl/strings.xml b/packages/SystemUI/res/values-tl/strings.xml
index 5815041..4bee3ea 100644
--- a/packages/SystemUI/res/values-tl/strings.xml
+++ b/packages/SystemUI/res/values-tl/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Tahimik na ipakita ang mga notification na ito"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Ipakita sa itaas ng listahan ng mga notification at mag-play ng tunog"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Ipasilip sa screen at mag-play ng tunog"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Higit pang mga setting"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Tapos Na"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Mga karaniwang kulay"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Madidilim na kulay"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Mga custom na kulay"</string>
diff --git a/packages/SystemUI/res/values-tr/strings.xml b/packages/SystemUI/res/values-tr/strings.xml
index 6832808..c0ecc78 100644
--- a/packages/SystemUI/res/values-tr/strings.xml
+++ b/packages/SystemUI/res/values-tr/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Bu bildirimleri sessizce göster"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Bildirim listesinin en üstünde göster ve ses çıkar"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Ekrana getir ve ses çıkar"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Diğer ayarlar"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Bitti"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Normal renkler"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Gece renkleri"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Özel renkler"</string>
diff --git a/packages/SystemUI/res/values-uk/strings.xml b/packages/SystemUI/res/values-uk/strings.xml
index 9736028..3109403 100644
--- a/packages/SystemUI/res/values-uk/strings.xml
+++ b/packages/SystemUI/res/values-uk/strings.xml
@@ -462,6 +462,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Показувати ці сповіщення без звукового сигналу"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Показувати сповіщення вгорі списку зі звуковим сигналом"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Показувати сповіщення на екрані зі звуковим сигналом"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Більше налаштувань"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Готово"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Стандартні кольори"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Нічні кольори"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Користувацькі кольори"</string>
diff --git a/packages/SystemUI/res/values-ur-rPK/strings.xml b/packages/SystemUI/res/values-ur-rPK/strings.xml
index 28484eb..52aa580 100644
--- a/packages/SystemUI/res/values-ur-rPK/strings.xml
+++ b/packages/SystemUI/res/values-ur-rPK/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"خاموشی سے یہ اطلاعات دکھائیں"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"اطلاعات کی فہرست پر سب سے اوپر دکھائیں اور آواز چلائیں"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"اسکرین پر دکھائیں اور آواز چلائیں"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"مزید ترتیبات"</string>
+    <string name="notification_done" msgid="5279426047273930175">"ہوگیا"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"عام رنگ"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"رات کے رنگ"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"حسب ضرورت رنگ"</string>
diff --git a/packages/SystemUI/res/values-uz-rUZ/strings.xml b/packages/SystemUI/res/values-uz-rUZ/strings.xml
index 4bd9dbc..a849cfc 100644
--- a/packages/SystemUI/res/values-uz-rUZ/strings.xml
+++ b/packages/SystemUI/res/values-uz-rUZ/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Bu bildirishnomalar ovozsiz ko‘rsatilsin"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Bildirishnomalar ro‘yxatining boshida ovoz bilan ko‘rsatilsin"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Barcha oynalar ustida signal ovozi bilan ko‘rsatilsin"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Boshqa sozlamalar"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Tayyor"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Odatiy ranglar"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Qoramtir ranglar"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Foydalanuvchi rangi"</string>
diff --git a/packages/SystemUI/res/values-vi/strings.xml b/packages/SystemUI/res/values-vi/strings.xml
index c094d5b..fa835ba 100644
--- a/packages/SystemUI/res/values-vi/strings.xml
+++ b/packages/SystemUI/res/values-vi/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Hiển thị im lặng các thông báo này"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Hiển thị ở đầu danh sách thông báo và phát ra âm thanh"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Hiển thị trên màn hình và phát ra âm thanh"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Cài đặt khác"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Xong"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Màu thông thường"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Màu tối"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Màu tùy chỉnh"</string>
diff --git a/packages/SystemUI/res/values-zh-rCN/strings.xml b/packages/SystemUI/res/values-zh-rCN/strings.xml
index 3af77c2..bb8f4ad 100644
--- a/packages/SystemUI/res/values-zh-rCN/strings.xml
+++ b/packages/SystemUI/res/values-zh-rCN/strings.xml
@@ -460,6 +460,10 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"显示这些通知,但不发出提示音"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"在通知列表顶部显示,并发出提示音"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"在屏幕上持续显示,并发出提示音"</string>
+    <!-- no translation found for notification_more_settings (816306283396553571) -->
+    <skip />
+    <!-- no translation found for notification_done (5279426047273930175) -->
+    <skip />
     <string name="color_matrix_none" msgid="2121957926040543148">"常规颜色"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"夜间颜色"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"自定义颜色"</string>
diff --git a/packages/SystemUI/res/values-zh-rHK/strings.xml b/packages/SystemUI/res/values-zh-rHK/strings.xml
index 8591785..0782354 100644
--- a/packages/SystemUI/res/values-zh-rHK/strings.xml
+++ b/packages/SystemUI/res/values-zh-rHK/strings.xml
@@ -454,12 +454,14 @@
     <string name="low_importance" msgid="4109929986107147930">"低重要性"</string>
     <string name="default_importance" msgid="8192107689995742653">"一般重要性"</string>
     <string name="high_importance" msgid="1527066195614050263">"高重要性"</string>
-    <string name="max_importance" msgid="5089005872719563894">"緊急"</string>
+    <string name="max_importance" msgid="5089005872719563894">"緊急重要性"</string>
     <string name="notification_importance_blocked" msgid="2397192642657872872">"永不顯示這些通知"</string>
     <string name="notification_importance_low" msgid="4383563267370859725">"顯示在通知清單底部但不發出音效"</string>
     <string name="notification_importance_default" msgid="4926529615920610817">"顯示這些通知但不發出音效"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"顯示在通知清單頂部並發出音效"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"不時於螢幕出現並發出音效"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"更多設定"</string>
+    <string name="notification_done" msgid="5279426047273930175">"完成"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"一般色系"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"深沉色系"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"自訂顏色"</string>
diff --git a/packages/SystemUI/res/values-zh-rTW/strings.xml b/packages/SystemUI/res/values-zh-rTW/strings.xml
index 34fa7aa..29520f6 100644
--- a/packages/SystemUI/res/values-zh-rTW/strings.xml
+++ b/packages/SystemUI/res/values-zh-rTW/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"顯示這些通知且不發出任何音效"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"顯示在通知清單頂端並發出音效"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"短暫顯示在螢幕上並發出音效"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"更多設定"</string>
+    <string name="notification_done" msgid="5279426047273930175">"完成"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"一般顏色"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"夜間顏色"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"自訂顏色"</string>
diff --git a/packages/SystemUI/res/values-zu/strings.xml b/packages/SystemUI/res/values-zu/strings.xml
index ebd857c..3ee46ea 100644
--- a/packages/SystemUI/res/values-zu/strings.xml
+++ b/packages/SystemUI/res/values-zu/strings.xml
@@ -460,6 +460,8 @@
     <string name="notification_importance_default" msgid="4926529615920610817">"Bonisa ngokuthulile lezi zaziso"</string>
     <string name="notification_importance_high" msgid="3222680136612408223">"Bonisa ngaphezulu kohlu lwezaziso uphinde wenze umsindo"</string>
     <string name="notification_importance_max" msgid="5236987171904756134">"Bheka kusikrini uphinde wenze umsindo"</string>
+    <string name="notification_more_settings" msgid="816306283396553571">"Izilungiselelo eziningi"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Kwenziwe"</string>
     <string name="color_matrix_none" msgid="2121957926040543148">"Imibala ejwayelekile"</string>
     <string name="color_matrix_night" msgid="5943817622105307072">"Imibala yasebusuku"</string>
     <string name="color_matrix_custom" msgid="3655576492322298713">"Imibala yangokwezifiso"</string>
diff --git a/packages/SystemUI/res/values/arrays_car.xml b/packages/SystemUI/res/values/arrays_car.xml
new file mode 100644
index 0000000..230479d
--- /dev/null
+++ b/packages/SystemUI/res/values/arrays_car.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 2015, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+<resources>
+    <!-- These should be overriden in an overlay. The default implementation is empty.
+         There needs to be correspondence per index between these arrays, which means that if there
+         isn't a longpress action associated with a shortcut item, put in an empty item to make
+         sure everything lines up.
+    -->
+    <array name="car_shortcut_icons" />
+    <array name="car_shortcut_intent_uris" />
+    <array name="car_shortcut_longpress_intent_uris" />
+</resources>
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 40e8b50..955af82 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -172,7 +172,7 @@
     <integer name="recents_nav_bar_scrim_enter_duration">400</integer>
 
     <!-- The animation duration for animating the removal of a task view. -->
-    <integer name="recents_animate_task_view_remove_duration">250</integer>
+    <integer name="recents_animate_task_view_remove_duration">175</integer>
 
     <!-- The animation duration for scrolling the stack to a particular item. -->
     <integer name="recents_animate_task_stack_scroll_duration">200</integer>
diff --git a/packages/SystemUI/res/values/internal.xml b/packages/SystemUI/res/values/internal.xml
index 67685ee..e0d3cd2 100644
--- a/packages/SystemUI/res/values/internal.xml
+++ b/packages/SystemUI/res/values/internal.xml
@@ -17,6 +17,7 @@
 <resources>
     <dimen name="status_bar_height">@*android:dimen/status_bar_height</dimen>
     <dimen name="navigation_bar_height">@*android:dimen/navigation_bar_height</dimen>
+    <dimen name="navigation_bar_height_car_mode">@*android:dimen/navigation_bar_height_car_mode</dimen>
     <color name="screen_pinning_primary_text">@*android:color/primary_text_default_material_light</color>
 </resources>
 
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 45ddd50..876c21e 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -1228,6 +1228,11 @@
     <!-- [CHAR LIMIT=100] Notification Importance slider: max importance level description -->
     <string name="notification_importance_max">Peek onto the screen and make sound</string>
 
+    <!-- Notification: Control panel: Label for button that launches notification settings. [CHAR LIMIT=NONE] -->
+    <string name="notification_more_settings">More settings</string>
+    <!-- Notification: Control panel: Label for button that dismisses control panel. [CHAR LIMIT=NONE] -->
+    <string name="notification_done">Done</string>
+
     <!-- Label for no color transform [CHAR LIMIT=30] -->
     <string name="color_matrix_none">Normal colors</string>
 
diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml
index 3b0ab791..527b638 100644
--- a/packages/SystemUI/res/values/styles.xml
+++ b/packages/SystemUI/res/values/styles.xml
@@ -317,4 +317,12 @@
         <item name="@dropdownPreferenceStyle">@style/Preference.DropDown.Material</item>
     </style>
 
+    <style name="TextAppearance.NotificationGuts">
+        <item name="android:textSize">14sp</item>
+        <item name="android:textColor">@color/notification_guts_btn_color</item>
+        <item name="android:textAllCaps">true</item>
+        <item name="android:fontFamily">sans-serif-medium</item>
+        <item name="android:gravity">center</item>
+    </style>
+
 </resources>
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSIconView.java b/packages/SystemUI/src/com/android/systemui/qs/QSIconView.java
index b56ad76..01eb5f9 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSIconView.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSIconView.java
@@ -75,7 +75,8 @@
             iv.setTag(R.id.qs_icon_tag, state.icon);
             if (d instanceof Animatable) {
                 Animatable a = (Animatable) d;
-                if (state.icon instanceof QSTile.AnimationIcon && !iv.isShown()) {
+                a.start();
+                if (!iv.isShown()) {
                     a.stop(); // skip directly to end state
                 }
             }
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java
index 39f0c55..1a36abd 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java
@@ -19,8 +19,6 @@
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
-import android.graphics.drawable.Animatable;
-import android.graphics.drawable.AnimatedVectorDrawable;
 import android.graphics.drawable.Drawable;
 import android.os.Handler;
 import android.os.Looper;
@@ -29,9 +27,20 @@
 import android.util.SparseArray;
 import android.view.View;
 import android.view.ViewGroup;
-
 import com.android.systemui.qs.QSTile.State;
-import com.android.systemui.statusbar.policy.*;
+import com.android.systemui.statusbar.policy.BatteryController;
+import com.android.systemui.statusbar.policy.BluetoothController;
+import com.android.systemui.statusbar.policy.CastController;
+import com.android.systemui.statusbar.policy.FlashlightController;
+import com.android.systemui.statusbar.policy.HotspotController;
+import com.android.systemui.statusbar.policy.KeyguardMonitor;
+import com.android.systemui.statusbar.policy.Listenable;
+import com.android.systemui.statusbar.policy.LocationController;
+import com.android.systemui.statusbar.policy.NetworkController;
+import com.android.systemui.statusbar.policy.RotationLockController;
+import com.android.systemui.statusbar.policy.UserInfoController;
+import com.android.systemui.statusbar.policy.UserSwitcherController;
+import com.android.systemui.statusbar.policy.ZenModeController;
 
 import java.util.Collection;
 import java.util.Objects;
@@ -389,11 +398,7 @@
 
         @Override
         public Drawable getDrawable(Context context) {
-            Drawable d = context.getDrawable(mResId);
-            if (d instanceof Animatable) {
-                ((Animatable) d).start();
-            }
-            return d;
+            return context.getDrawable(mResId);
         }
 
         @Override
@@ -408,41 +413,14 @@
     }
 
     protected class AnimationIcon extends ResourceIcon {
-        private boolean mAllowAnimation;
-
         public AnimationIcon(int resId) {
             super(resId);
         }
 
-        public void setAllowAnimation(boolean allowAnimation) {
-            mAllowAnimation = allowAnimation;
-        }
-
         @Override
         public Drawable getDrawable(Context context) {
             // workaround: get a clean state for every new AVD
-            final AnimatedVectorDrawable d = (AnimatedVectorDrawable) context.getDrawable(mResId)
-                    .getConstantState().newDrawable();
-            d.start();
-            if (mAllowAnimation) {
-                mAllowAnimation = false;
-            } else {
-                d.stop(); // skip directly to end state
-            }
-            return d;
-        }
-    }
-
-    protected enum UserBoolean {
-        USER_TRUE(true, true),
-        USER_FALSE(true, false),
-        BACKGROUND_TRUE(false, true),
-        BACKGROUND_FALSE(false, false);
-        public final boolean value;
-        public final boolean userInitiated;
-        private UserBoolean(boolean userInitiated, boolean value) {
-            this.value = value;
-            this.userInitiated = userInitiated;
+            return context.getDrawable(mResId).getConstantState().newDrawable();
         }
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSTileServiceWrapper.java b/packages/SystemUI/src/com/android/systemui/qs/QSTileServiceWrapper.java
deleted file mode 100644
index a5e1fd5..0000000
--- a/packages/SystemUI/src/com/android/systemui/qs/QSTileServiceWrapper.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.android.systemui.qs;
-
-import android.os.IBinder;
-import android.service.quicksettings.IQSTileService;
-import android.service.quicksettings.Tile;
-import android.util.Log;
-
-
-public class QSTileServiceWrapper implements IQSTileService {
-    private static final String TAG = "IQSTileServiceWrapper";
-
-    private final IQSTileService mService;
-    
-    public QSTileServiceWrapper(IQSTileService service) {
-        mService = service;
-    }
-
-    @Override
-    public IBinder asBinder() {
-        return mService.asBinder();
-    }
-
-    @Override
-    public void setQSTile(Tile tile) {
-        try {
-            mService.setQSTile(tile);
-        } catch (Exception e) {
-            Log.d(TAG, "Caught exception from QSTileService", e);
-        }
-    }
-
-    @Override
-    public void onTileAdded() {
-        try {
-            mService.onTileAdded();
-        } catch (Exception e) {
-            Log.d(TAG, "Caught exception from QSTileService", e);
-        }
-    }
-
-    @Override
-    public void onTileRemoved() {
-        try {
-            mService.onTileRemoved();
-        } catch (Exception e) {
-            Log.d(TAG, "Caught exception from QSTileService", e);
-        }
-    }
-
-    @Override
-    public void onStartListening() {
-        try {
-            mService.onStartListening();
-        } catch (Exception e) {
-            Log.d(TAG, "Caught exception from QSTileService", e);
-        }
-    }
-
-    @Override
-    public void onStopListening() {
-        try {
-            mService.onStopListening();
-        } catch (Exception e) {
-            Log.d(TAG, "Caught exception from QSTileService", e);
-        }
-    }
-
-    @Override
-    public void onClick(IBinder token) {
-        try {
-            mService.onClick(token);
-        } catch (Exception e) {
-            Log.d(TAG, "Caught exception from QSTileService", e);
-        }
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java
index bda4675..5fa38c6 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java
@@ -49,6 +49,11 @@
         mQsContainer.addView((View) mTileLayout, 1 /* Between brightness and footer */);
     }
 
+    @Override
+    protected void createCustomizePanel() {
+        // No customizing from the header.
+    }
+
     public void setQSPanelAndHeader(QSPanel fullPanel, View header) {
         mFullPanel = fullPanel;
         mHeader = header;
diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/CustomQSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/customize/CustomQSPanel.java
index 87c2973..7448493 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/customize/CustomQSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/customize/CustomQSPanel.java
@@ -16,32 +16,28 @@
 package com.android.systemui.qs.customize;
 
 import android.app.ActivityManager;
-import android.app.Service;
 import android.content.ClipData;
-import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
-import android.content.ServiceConnection;
-import android.os.IBinder;
+import android.os.Handler;
 import android.os.UserHandle;
 import android.provider.Settings.Secure;
-import android.service.quicksettings.IQSTileService;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
-
 import com.android.systemui.R;
 import com.android.systemui.qs.QSPanel;
 import com.android.systemui.qs.QSTile;
-import com.android.systemui.qs.QSTileServiceWrapper;
-import com.android.systemui.qs.tiles.CustomTile;
+import com.android.systemui.qs.external.CustomTile;
+import com.android.systemui.qs.external.TileLifecycleManager;
 import com.android.systemui.statusbar.phone.QSTileHost;
 import com.android.systemui.tuner.TunerService;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -52,8 +48,9 @@
 public class CustomQSPanel extends QSPanel {
     
     private static final String TAG = "CustomQSPanel";
+    private static final boolean DEBUG = false;
 
-    private List<String> mSavedTiles;
+    private List<String> mSavedTiles = Collections.emptyList();
     private ArrayList<String> mStash;
     private List<String> mTiles = new ArrayList<>();
 
@@ -67,17 +64,25 @@
         ((NonPagedTileLayout) mTileLayout).setCustomQsPanel(this);
         removeView(mFooter.getView());
 
+        if (DEBUG) Log.d(TAG, "new CustomQSPanel", new Throwable());
         TunerService.get(mContext).addTunable(this, QSTileHost.TILES_SETTING);
     }
 
     @Override
+    protected void onDetachedFromWindow() {
+        // Don't allow the super to unregister the tunable.
+    }
+
+    @Override
     public void onTuningChanged(String key, String newValue) {
         if (key.equals(QS_SHOW_BRIGHTNESS)) {
             // No Brightness for you.
             super.onTuningChanged(key, "0");
         }
         if (QSTileHost.TILES_SETTING.equals(key)) {
-            mSavedTiles = QSTileHost.loadTileSpecs(mContext, newValue);
+            mSavedTiles = Collections.unmodifiableList(
+                    QSTileHost.loadTileSpecs(mContext, newValue));
+            if (DEBUG) Log.d(TAG, "New saved tiles " + TextUtils.join(",", mSavedTiles));
         }
     }
 
@@ -106,6 +111,7 @@
     }
 
     public void setSavedTiles() {
+        if (DEBUG) Log.d(TAG, "setSavedTiles " + TextUtils.join(",", mSavedTiles));
         setTiles(mSavedTiles);
     }
 
@@ -114,47 +120,26 @@
             String tileSpec = mSavedTiles.get(i);
             if (!tileSpec.startsWith(CustomTile.PREFIX)) continue;
             if (!mTiles.contains(tileSpec)) {
-                mContext.bindServiceAsUser(
-                        new Intent().setComponent(CustomTile.getComponentFromSpec(tileSpec)),
-                        new ServiceConnection() {
-                            @Override
-                            public void onServiceDisconnected(ComponentName name) {
-                            }
-
-                            @Override
-                            public void onServiceConnected(ComponentName name, IBinder service) {
-                                QSTileServiceWrapper wrapper = new QSTileServiceWrapper(
-                                        IQSTileService.Stub.asInterface(service));
-                                wrapper.onStopListening();
-                                wrapper.onTileRemoved();
-                                mContext.unbindService(this);
-                            }
-                        }, Service.BIND_AUTO_CREATE,
-                        new UserHandle(ActivityManager.getCurrentUser()));
+                Intent intent = new Intent().setComponent(CustomTile.getComponentFromSpec(tileSpec));
+                TileLifecycleManager lifecycleManager = new TileLifecycleManager(new Handler(),
+                        mContext, intent, new UserHandle(ActivityManager.getCurrentUser()));
+                lifecycleManager.onStopListening();
+                lifecycleManager.onTileRemoved();
+                lifecycleManager.flushMessagesAndUnbind();
             }
         }
         for (int i = 0; i < mTiles.size(); i++) {
             String tileSpec = mTiles.get(i);
             if (!tileSpec.startsWith(CustomTile.PREFIX)) continue;
             if (!mSavedTiles.contains(tileSpec)) {
-                mContext.bindServiceAsUser(
-                        new Intent().setComponent(CustomTile.getComponentFromSpec(tileSpec)),
-                        new ServiceConnection() {
-                            @Override
-                            public void onServiceDisconnected(ComponentName name) {
-                            }
-
-                            @Override
-                            public void onServiceConnected(ComponentName name, IBinder service) {
-                                QSTileServiceWrapper wrapper = new QSTileServiceWrapper(
-                                        IQSTileService.Stub.asInterface(service));
-                                wrapper.onTileAdded();
-                                mContext.unbindService(this);
-                            }
-                        }, Service.BIND_AUTO_CREATE,
-                        new UserHandle(ActivityManager.getCurrentUser()));
+                Intent intent = new Intent().setComponent(CustomTile.getComponentFromSpec(tileSpec));
+                TileLifecycleManager lifecycleManager = new TileLifecycleManager(new Handler(),
+                        mContext, intent, new UserHandle(ActivityManager.getCurrentUser()));
+                lifecycleManager.onTileAdded();
+                lifecycleManager.flushMessagesAndUnbind();
             }
         }
+        if (DEBUG) Log.d(TAG, "saveCurrentTiles " + mTiles);
         Secure.putStringForUser(getContext().getContentResolver(), QSTileHost.TILES_SETTING,
                 TextUtils.join(",", mTiles), ActivityManager.getCurrentUser());
     }
@@ -173,30 +158,37 @@
     }
 
     private void setTilesInternal() {
+        if (DEBUG) Log.d(TAG, "Set tiles internal");
         for (int i = 0; i < mCurrentTiles.size(); i++) {
             mCurrentTiles.get(i).destroy();
         }
         mCurrentTiles.clear();
         for (int i = 0; i < mTiles.size(); i++) {
             if (mTiles.get(i).startsWith(CustomTile.PREFIX)) {
-                mCurrentTiles.add(BlankCustomTile.create(mHost, mTiles.get(i)));
+                QSTile<?> tile = BlankCustomTile.create(mHost, mTiles.get(i));
+                tile.setTileSpec(mTiles.get(i));
+                mCurrentTiles.add(tile);
             } else {
                 QSTile<?> tile = mHost.createTile(mTiles.get(i));
                 if (tile != null) {
+                    tile.setTileSpec(mTiles.get(i));
                     mCurrentTiles.add(tile);
+                } else {
+                    if (DEBUG) Log.d(TAG, "Skipping " + mTiles.get(i));
                 }
             }
-            mCurrentTiles.get(mCurrentTiles.size() - 1).setTileSpec(mTiles.get(i));
         }
         super.setTiles(mCurrentTiles);
     }
 
     public void addTile(String spec) {
+        if (DEBUG) Log.d(TAG, "addTile " + spec);
         mTiles.add(spec);
         setTilesInternal();
     }
 
     public void moveTo(String from, String to) {
+        if (DEBUG) Log.d(TAG, "moveTo " + from + " " + to);
         int fromIndex = mTiles.indexOf(from);
         if (fromIndex < 0) {
             Log.e(TAG, "Unknown from tile " + from);
@@ -220,6 +212,7 @@
     }
 
     public void setTiles(List<String> tiles) {
+        if (DEBUG) Log.d(TAG, "Set tiles " + TextUtils.join(",", tiles));
         mTiles = new ArrayList<>(tiles);
         setTilesInternal();
     }
diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java
index 6706c7a..a6a7143 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java
@@ -41,7 +41,7 @@
 import com.android.systemui.R;
 import com.android.systemui.qs.QSTile;
 import com.android.systemui.qs.QSTile.Icon;
-import com.android.systemui.qs.tiles.CustomTile;
+import com.android.systemui.qs.external.CustomTile;
 import com.android.systemui.statusbar.phone.QSTileHost;
 import com.android.systemui.tuner.QSPagingSwitch;
 
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/CustomTile.java b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java
similarity index 67%
rename from packages/SystemUI/src/com/android/systemui/qs/tiles/CustomTile.java
rename to packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java
index bb74f34..2e5a0b2 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/CustomTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java
@@ -11,32 +11,26 @@
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
- * limitations under the License.
+ * limitations under the License
  */
+package com.android.systemui.qs.external;
 
-package com.android.systemui.qs.tiles;
-
-import android.app.ActivityManager;
-import android.app.Service;
 import android.content.ComponentName;
-import android.content.Intent;
-import android.content.ServiceConnection;
 import android.content.pm.PackageManager;
 import android.content.pm.ServiceInfo;
 import android.graphics.drawable.Drawable;
 import android.os.Binder;
 import android.os.IBinder;
 import android.os.RemoteException;
-import android.os.UserHandle;
 import android.service.quicksettings.IQSTileService;
 import android.service.quicksettings.Tile;
+import android.service.quicksettings.TileService;
 import android.util.Log;
 import android.view.IWindowManager;
 import android.view.WindowManager;
 import android.view.WindowManagerGlobal;
 import com.android.internal.logging.MetricsLogger;
 import com.android.systemui.qs.QSTile;
-import com.android.systemui.qs.QSTileServiceWrapper;
 import com.android.systemui.statusbar.phone.QSTileHost;
 
 public class CustomTile extends QSTile<QSTile.State> {
@@ -52,8 +46,9 @@
     private final Tile mTile;
     private final IWindowManager mWindowManager;
     private final IBinder mToken = new Binder();
+    private final IQSTileService mService;
+    private final TileServiceManager mServiceManager;
 
-    private QSTileServiceWrapper mService;
     private boolean mListening;
     private boolean mBound;
     private boolean mIsTokenGranted;
@@ -63,7 +58,9 @@
         super(host);
         mWindowManager = WindowManagerGlobal.getWindowManagerService();
         mComponent = ComponentName.unflattenFromString(action);
-        mTile = new Tile(mComponent, host);
+        mServiceManager = host.getTileServices().getTileWrapper(this);
+        mService = mServiceManager.getTileService();
+        mTile = new Tile(mComponent);
         try {
             PackageManager pm = mContext.getPackageManager();
             ServiceInfo info = pm.getServiceInfo(mComponent, 0);
@@ -72,6 +69,11 @@
             mTile.setLabel(info.loadLabel(pm));
         } catch (Exception e) {
         }
+        try {
+            mService.setQSTile(mTile);
+        } catch (RemoteException e) {
+            // Called through wrapper, won't happen here.
+        }
     }
 
     public ComponentName getComponent() {
@@ -96,42 +98,33 @@
     public void setListening(boolean listening) {
         if (mListening == listening) return;
         mListening = listening;
-        if (listening) {
-            mHandler.removeCallbacks(mUnbind);
-            if (!mBound) {
-                // TODO: Guarantee re-bind on user-switch.
-                mContext.bindServiceAsUser(new Intent().setComponent(mComponent),
-                        mServiceConnection, Service.BIND_AUTO_CREATE,
-                        new UserHandle(ActivityManager.getCurrentUser()));
-                mBound = true;
-            } else {
-                if (mService != null) {
+        try {
+            if (listening) {
+                if (mServiceManager.getType() == TileService.TILE_MODE_PASSIVE) {
+                    mServiceManager.setBindRequested(true);
                     mService.onStartListening();
-                } else {
-                    Log.d(TAG, "Can't start service listening");
                 }
-            }
-        } else {
-            if (mService != null) {
+            } else {
                 mService.onStopListening();
-            }
-            if (mIsTokenGranted && !mIsShowingDialog) {
-                try {
-                    if (DEBUG) Log.d(TAG, "Removing token");
-                    mWindowManager.removeWindowToken(mToken);
-                } catch (RemoteException e) {
+                if (mIsTokenGranted && !mIsShowingDialog) {
+                    try {
+                        if (DEBUG) Log.d(TAG, "Removing token");
+                        mWindowManager.removeWindowToken(mToken);
+                    } catch (RemoteException e) {
+                    }
+                    mIsTokenGranted = false;
                 }
-                mIsTokenGranted = false;
+                mIsShowingDialog = false;
+                mServiceManager.setBindRequested(false);
             }
-            mIsShowingDialog = false;
-            mHandler.postDelayed(mUnbind, UNBIND_DELAY);
+        } catch (RemoteException e) {
+            // Called through wrapper, won't happen here.
         }
     }
 
     @Override
     protected void handleDestroy() {
         super.handleDestroy();
-        mHandler.removeCallbacks(mUnbind);
         if (mIsTokenGranted) {
             try {
                 if (DEBUG) Log.d(TAG, "Removing token");
@@ -139,7 +132,6 @@
             } catch (RemoteException e) {
             }
         }
-        mUnbind.run();
     }
 
     @Override
@@ -154,16 +146,20 @@
 
     @Override
     protected void handleClick() {
-        if (mService != null) {
-            try {
-                if (DEBUG) Log.d(TAG, "Adding token");
-                mWindowManager.addWindowToken(mToken, WindowManager.LayoutParams.TYPE_QS_DIALOG);
-                mIsTokenGranted = true;
-            } catch (RemoteException e) {
+        try {
+            if (DEBUG) Log.d(TAG, "Adding token");
+            mWindowManager.addWindowToken(mToken, WindowManager.LayoutParams.TYPE_QS_DIALOG);
+            mIsTokenGranted = true;
+        } catch (RemoteException e) {
+        }
+        try {
+            if (mServiceManager.getType() == TileService.TILE_MODE_ACTIVE) {
+                mServiceManager.setBindRequested(true);
+                mService.onStartListening();
             }
             mService.onClick(mToken);
-        } else {
-            Log.e(TAG, "Click with no service " + getTileSpec());
+        } catch (RemoteException e) {
+            // Called through wrapper, won't happen here.
         }
         MetricsLogger.action(mContext, getMetricsCategory(), mComponent.getPackageName());
     }
@@ -187,34 +183,9 @@
 
     @Override
     public int getMetricsCategory() {
-        return MetricsLogger.QS_INTENT;
+        return MetricsLogger.QS_CUSTOM;
     }
 
-    private final ServiceConnection mServiceConnection = new ServiceConnection() {
-        @Override
-        public void onServiceConnected(ComponentName name, IBinder service) {
-            mService = new QSTileServiceWrapper(IQSTileService.Stub.asInterface(service));
-            if (mListening) {
-                mService.setQSTile(mTile);
-                mService.onStartListening();
-            } else {
-                mService.onStopListening();
-            }
-        }
-
-        @Override
-        public void onServiceDisconnected(ComponentName name) {
-        }
-    };
-
-    private final Runnable mUnbind = new Runnable() {
-        @Override
-        public void run() {
-            mContext.unbindService(mServiceConnection);
-            mBound = false;
-        }
-    };
-
     public static ComponentName getComponentFromSpec(String spec) {
         final String action = spec.substring(PREFIX.length(), spec.length() - 1);
         if (action.isEmpty()) {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/QSTileServiceWrapper.java b/packages/SystemUI/src/com/android/systemui/qs/external/QSTileServiceWrapper.java
new file mode 100644
index 0000000..d41cdde
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/external/QSTileServiceWrapper.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.systemui.qs.external;
+
+import android.os.IBinder;
+import android.service.quicksettings.IQSService;
+import android.service.quicksettings.IQSTileService;
+import android.service.quicksettings.Tile;
+import android.util.Log;
+
+
+public class QSTileServiceWrapper {
+    private static final String TAG = "IQSTileServiceWrapper";
+
+    private final IQSTileService mService;
+
+    public QSTileServiceWrapper(IQSTileService service) {
+        mService = service;
+    }
+
+    public IBinder asBinder() {
+        return mService.asBinder();
+    }
+
+    public boolean setQSTile(Tile tile) {
+        try {
+            mService.setQSTile(tile);
+            return true;
+        } catch (Exception e) {
+            Log.d(TAG, "Caught exception from TileService", e);
+            return false;
+        }
+    }
+
+    public boolean onTileAdded() {
+        try {
+            mService.onTileAdded();
+            return true;
+        } catch (Exception e) {
+            Log.d(TAG, "Caught exception from TileService", e);
+            return false;
+        }
+    }
+
+    public boolean onTileRemoved() {
+        try {
+            mService.onTileRemoved();
+            return true;
+        } catch (Exception e) {
+            Log.d(TAG, "Caught exception from TileService", e);
+            return false;
+        }
+    }
+
+    public boolean onStartListening() {
+        try {
+            mService.onStartListening();
+            return true;
+        } catch (Exception e) {
+            Log.d(TAG, "Caught exception from TileService", e);
+            return false;
+        }
+    }
+
+    public boolean onStopListening() {
+        try {
+            mService.onStopListening();
+            return true;
+        } catch (Exception e) {
+            Log.d(TAG, "Caught exception from TileService", e);
+            return false;
+        }
+    }
+
+    public boolean onClick(IBinder token) {
+        try {
+            mService.onClick(token);
+            return true;
+        } catch (Exception e) {
+            Log.d(TAG, "Caught exception from TileService", e);
+            return false;
+        }
+    }
+
+    public boolean setQSService(IQSService service) {
+        try {
+            mService.setQSService(service);
+            return true;
+        } catch (Exception e) {
+            Log.d(TAG, "Caught exception from TileService", e);
+            return false;
+        }
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java b/packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java
new file mode 100644
index 0000000..8c5e87e
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/external/TileLifecycleManager.java
@@ -0,0 +1,360 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.systemui.qs.external;
+
+import android.app.AppGlobals;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.ServiceConnection;
+import android.content.pm.PackageManager;
+import android.content.pm.ServiceInfo;
+import android.net.Uri;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.service.quicksettings.IQSService;
+import android.service.quicksettings.IQSTileService;
+import android.service.quicksettings.Tile;
+import android.support.annotation.VisibleForTesting;
+import android.util.ArraySet;
+import android.util.Log;
+import libcore.util.Objects;
+
+import java.util.Set;
+
+/**
+ * Manages the lifecycle of a TileService.
+ * <p>
+ * Will keep track of all calls on the IQSTileService interface and will relay those calls to the
+ * TileService as soon as it is bound.  It will only bind to the service when it is allowed to
+ * ({@link #setBindService(boolean)}) and when the service is available.
+ */
+public class TileLifecycleManager extends BroadcastReceiver implements
+        IQSTileService, ServiceConnection, IBinder.DeathRecipient {
+    public static final boolean DEBUG = false;
+
+    private static final String TAG = "TileLifecycleManager";
+
+    private static final int MSG_ON_ADDED = 0;
+    private static final int MSG_ON_REMOVED = 1;
+    private static final int MSG_ON_CLICK = 2;
+
+    // Bind retry control.
+    private static final int MAX_BIND_RETRIES = 5;
+    private static final int BIND_RETRY_DELAY = 1000;
+
+    private final Context mContext;
+    private final Handler mHandler;
+    private final Intent mIntent;
+    private final UserHandle mUser;
+
+    private Set<Integer> mQueuedMessages = new ArraySet<>();
+    private QSTileServiceWrapper mWrapper;
+    private boolean mListening;
+    private Tile mTile;
+    private IBinder mClickBinder;
+
+    private int mBindTryCount;
+    private boolean mBound;
+    @VisibleForTesting
+    boolean mReceiverRegistered;
+    private IQSService mService;
+    private boolean mUnbindImmediate;
+
+    public TileLifecycleManager(Handler handler, Context context, Intent intent, UserHandle user) {
+        mContext = context;
+        mHandler = handler;
+        mIntent = intent;
+        mUser = user;
+    }
+
+    public ComponentName getComponent() {
+        return mIntent.getComponent();
+    }
+
+    public boolean hasPendingClick() {
+        synchronized (mQueuedMessages) {
+            return mQueuedMessages.contains(MSG_ON_CLICK);
+        }
+    }
+
+    /**
+     * Binds just long enough to send any queued messages, then unbinds.
+     */
+    public void flushMessagesAndUnbind() {
+        mUnbindImmediate = true;
+        setBindService(true);
+    }
+
+    public void setBindService(boolean bind) {
+        mBound = bind;
+        if (bind) {
+            if (mBindTryCount == MAX_BIND_RETRIES) {
+                // Too many failures, give up on this tile until an update.
+                startPackageListening();
+                return;
+            }
+            if (!checkComponentState()) {
+                return;
+            }
+            if (DEBUG) Log.d(TAG, "Binding service " + mIntent);
+            mBindTryCount++;
+            mContext.bindServiceAsUser(mIntent, this,
+                    Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE,
+                    mUser);
+        } else {
+            if (DEBUG) Log.d(TAG, "Unbinding service " + mIntent);
+            // Give it another chance next time it needs to be bound, out of kindness.
+            mBindTryCount = 0;
+            mWrapper = null;
+            mContext.unbindService(this);
+        }
+    }
+
+    @Override
+    public void onServiceConnected(ComponentName name, IBinder service) {
+        if (DEBUG) Log.d(TAG, "onServiceConnected " + name);
+        // Got a connection, set the binding count to 0.
+        mBindTryCount = 0;
+        mWrapper = new QSTileServiceWrapper(Stub.asInterface(service));
+        try {
+            service.linkToDeath(this, 0);
+        } catch (RemoteException e) {
+        }
+        setQSService(mService);
+        setQSTile(mTile);
+        handlePendingMessages();
+    }
+
+    @Override
+    public void onServiceDisconnected(ComponentName name) {
+        if (DEBUG) Log.d(TAG, "onServiceDisconnected " + name);
+        mWrapper = null;
+    }
+
+    private void handlePendingMessages() {
+        // This ordering is laid out manually to make sure we preserve the TileService
+        // lifecycle.
+        ArraySet<Integer> queue;
+        synchronized (mQueuedMessages) {
+            queue = new ArraySet<>(mQueuedMessages);
+            mQueuedMessages.clear();
+        }
+        if (queue.contains(MSG_ON_ADDED)) {
+            if (DEBUG) Log.d(TAG, "Handling pending onAdded");
+            onTileAdded();
+        }
+        if (mListening) {
+            if (DEBUG) Log.d(TAG, "Handling pending onStartListening");
+            onStartListening();
+        }
+        if (queue.contains(MSG_ON_CLICK)) {
+            if (DEBUG) Log.d(TAG, "Handling pending onClick");
+            if (!mListening) {
+                Log.w(TAG, "Managed to get click on non-listening state...");
+                // Skipping click since lost click privileges.
+            } else {
+                onClick(mClickBinder);
+            }
+        }
+        if (queue.contains(MSG_ON_REMOVED)) {
+            if (DEBUG) Log.d(TAG, "Handling pending onRemoved");
+            if (mListening) {
+                Log.w(TAG, "Managed to get remove in listening state...");
+                onStopListening();
+            }
+            onTileRemoved();
+        }
+        if (mUnbindImmediate) {
+            mUnbindImmediate = false;
+            setBindService(false);
+        }
+    }
+
+    public void handleDestroy() {
+        if (DEBUG) Log.d(TAG, "handleDestroy");
+        if (mReceiverRegistered) {
+            stopPackageListening();
+        }
+    }
+
+    private void handleDeath() {
+        if (mWrapper == null) return;
+        mWrapper = null;
+        if (!mBound) return;
+        if (DEBUG) Log.d(TAG, "handleDeath");
+        if (checkComponentState()) {
+            mHandler.postDelayed(new Runnable() {
+                @Override
+                public void run() {
+                    if (mBound) {
+                        // Retry binding.
+                        setBindService(true);
+                    }
+                }
+            }, BIND_RETRY_DELAY);
+        }
+    }
+
+    @Override
+    public void setQSTile(Tile tile) {
+        if (DEBUG) Log.d(TAG, "setQSTile " + tile);
+        mTile = tile;
+        if (mWrapper != null && !mWrapper.setQSTile(tile)) {
+            handleDeath();
+        }
+    }
+
+    private boolean checkComponentState() {
+        PackageManager pm = mContext.getPackageManager();
+        if (!isPackageAvailable(pm) || !isComponentAvailable(pm)) {
+            startPackageListening();
+            return false;
+        }
+        return true;
+    }
+
+    private void startPackageListening() {
+        if (DEBUG) Log.d(TAG, "startPackageListening");
+        IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
+        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+        filter.addDataScheme("package");
+        mContext.registerReceiverAsUser(this, mUser, filter, null, mHandler);
+        mReceiverRegistered = true;
+    }
+
+    private void stopPackageListening() {
+        if (DEBUG) Log.d(TAG, "stopPackageListening");
+        mContext.unregisterReceiver(this);
+        mReceiverRegistered = false;
+    }
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        if (DEBUG) Log.d(TAG, "onReceive: " + intent);
+        Uri data = intent.getData();
+        String pkgName = data.getEncodedSchemeSpecificPart();
+        if (!Objects.equal(pkgName, mIntent.getComponent().getPackageName())) {
+            return;
+        }
+        stopPackageListening();
+        if (mBound) {
+            // Trying to bind again will check the state of the package before bothering to bind.
+            if (DEBUG) Log.d(TAG, "Trying to rebind");
+            setBindService(true);
+        }
+    }
+
+    private boolean isComponentAvailable(PackageManager pm) {
+        String packageName = mIntent.getComponent().getPackageName();
+        try {
+            ServiceInfo si = AppGlobals.getPackageManager().getServiceInfo(mIntent.getComponent(),
+                    0, mUser.getIdentifier());
+            if (DEBUG && si == null) Log.d(TAG, "Can't find component " + mIntent.getComponent());
+            return si != null;
+        } catch (RemoteException e) {
+            // Shouldn't happen.
+        }
+        return false;
+    }
+
+    private boolean isPackageAvailable(PackageManager pm) {
+        String packageName = mIntent.getComponent().getPackageName();
+        try {
+            pm.getPackageInfoAsUser(packageName, 0, mUser.getIdentifier());
+            return true;
+        } catch (PackageManager.NameNotFoundException e) {
+            if (DEBUG) Log.d(TAG, "Package not available: " + packageName, e);
+            else Log.d(TAG, "Package not available: " + packageName);
+        }
+        return false;
+    }
+
+    private void queueMessage(int message) {
+        synchronized (mQueuedMessages) {
+            mQueuedMessages.add(message);
+        }
+    }
+
+    @Override
+    public void setQSService(IQSService service) {
+        mService = service;
+        if (mWrapper == null || !mWrapper.setQSService(service)) {
+            handleDeath();
+        }
+    }
+
+    @Override
+    public void onTileAdded() {
+        if (DEBUG) Log.d(TAG, "onTileAdded");
+        if (mWrapper == null || !mWrapper.onTileAdded()) {
+            queueMessage(MSG_ON_ADDED);
+            handleDeath();
+        }
+    }
+
+    @Override
+    public void onTileRemoved() {
+        if (DEBUG) Log.d(TAG, "onTileRemoved");
+        if (mWrapper == null || !mWrapper.onTileRemoved()) {
+            queueMessage(MSG_ON_REMOVED);
+            handleDeath();
+        }
+    }
+
+    @Override
+    public void onStartListening() {
+        if (DEBUG) Log.d(TAG, "onStartListening");
+        mListening = true;
+        if (mWrapper != null && !mWrapper.onStartListening()) {
+            handleDeath();
+        }
+    }
+
+    @Override
+    public void onStopListening() {
+        if (DEBUG) Log.d(TAG, "onStopListening");
+        mListening = false;
+        if (mWrapper != null && !mWrapper.onStopListening()) {
+            handleDeath();
+        }
+    }
+
+    @Override
+    public void onClick(IBinder iBinder) {
+        if (DEBUG) Log.d(TAG, "onClick " + iBinder);
+        if (mWrapper == null || !mWrapper.onClick(iBinder)) {
+            mClickBinder = iBinder;
+            queueMessage(MSG_ON_CLICK);
+            handleDeath();
+        }
+    }
+
+    @Override
+    public IBinder asBinder() {
+        return mWrapper != null ? mWrapper.asBinder() : null;
+    }
+
+    @Override
+    public void binderDied() {
+        if (DEBUG) Log.d(TAG, "binderDeath");
+        handleDeath();
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/TileServiceManager.java b/packages/SystemUI/src/com/android/systemui/qs/external/TileServiceManager.java
new file mode 100644
index 0000000..2f77a30
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/external/TileServiceManager.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.systemui.qs.external;
+
+import android.app.ActivityManager;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.os.Handler;
+import android.os.UserHandle;
+import android.service.quicksettings.IQSTileService;
+import android.service.quicksettings.TileService;
+import android.support.annotation.VisibleForTesting;
+import android.util.Log;
+
+/**
+ * Manages the priority which lets {@link TileServices} make decisions about which tiles
+ * to bind.  Also holds on to and manages the {@link TileLifecycleManager}, informing it
+ * of when it is allowed to bind based on decisions frome the {@link TileServices}.
+ */
+public class TileServiceManager {
+
+    private static final long MIN_BIND_TIME = 5000;
+    private static final long UNBIND_DELAY = 30000;
+
+    public static final boolean DEBUG = true;
+
+    private static final String TAG = "TileServiceManager";
+
+    @VisibleForTesting
+    static final String PREFS_FILE = "CustomTileModes";
+
+    private final TileServices mServices;
+    private final TileLifecycleManager mStateManager;
+    private final Handler mHandler;
+    private boolean mBindRequested;
+    private boolean mBindAllowed;
+    private boolean mBound;
+    private int mPriority;
+    private boolean mJustBound;
+    private long mLastUpdate;
+    private int mType;
+
+    TileServiceManager(TileServices tileServices, Handler handler, ComponentName component) {
+        this(tileServices, handler, new TileLifecycleManager(handler,
+                tileServices.getContext(), new Intent().setComponent(component),
+                new UserHandle(ActivityManager.getCurrentUser())));
+    }
+
+    @VisibleForTesting
+    TileServiceManager(TileServices tileServices, Handler handler,
+            TileLifecycleManager tileLifecycleManager) {
+        mServices = tileServices;
+        mHandler = handler;
+        mStateManager = tileLifecycleManager;
+        mType = tileServices.getContext().getSharedPreferences(PREFS_FILE, 0)
+                .getInt(tileLifecycleManager.getComponent().flattenToString(),
+                        TileService.TILE_MODE_UNSET);
+        mStateManager.setQSService(tileServices);
+        if (mType == TileService.TILE_MODE_UNSET) {
+            bindService();
+            mStateManager.onTileAdded();
+        }
+    }
+
+    public int getType() {
+        return mType;
+    }
+
+    public void setType(int type) {
+        mServices.getContext().getSharedPreferences(PREFS_FILE, 0).edit()
+                .putInt(mStateManager.getComponent().flattenToString(), type).commit();
+        mType = type;
+        mServices.recalculateBindAllowance();
+    }
+
+    public IQSTileService getTileService() {
+        return mStateManager;
+    }
+
+    public void setBindRequested(boolean bindRequested) {
+        if (mBindRequested == bindRequested) return;
+        mBindRequested = bindRequested;
+        if (mBindAllowed && mBindRequested && !mBound) {
+            mHandler.removeCallbacks(mUnbind);
+            bindService();
+        } else {
+            mServices.recalculateBindAllowance();
+        }
+        if (mBound && !mBindRequested) {
+            mHandler.postDelayed(mUnbind, UNBIND_DELAY);
+        }
+    }
+
+    public void setLastUpdate(long lastUpdate) {
+        mLastUpdate = lastUpdate;
+        if (mBound && mType == TileService.TILE_MODE_ACTIVE) {
+            mStateManager.onStopListening();
+            setBindRequested(false);
+        }
+        mServices.recalculateBindAllowance();
+    }
+
+    public void handleDestroy() {
+        mStateManager.handleDestroy();
+    }
+
+    public void setBindAllowed(boolean allowed) {
+        if (mBindAllowed == allowed) return;
+        mBindAllowed = allowed;
+        if (!mBindAllowed && mBound) {
+            unbindService();
+        } else if (mBindAllowed && mBindRequested && !mBound) {
+            bindService();
+        }
+    }
+
+    private void bindService() {
+        if (mBound) {
+            Log.e(TAG, "Service already bound");
+            return;
+        }
+        mBound = true;
+        mJustBound = true;
+        mHandler.postDelayed(mJustBoundOver, MIN_BIND_TIME);
+        mStateManager.setBindService(true);
+    }
+
+    private void unbindService() {
+        if (!mBound) {
+            Log.e(TAG, "Service not bound");
+            return;
+        }
+        mBound = false;
+        mJustBound = false;
+        mStateManager.setBindService(false);
+    }
+
+    public void calculateBindPriority(long currentTime) {
+        if (mStateManager.hasPendingClick()) {
+            // Pending click is the most important thing, need to put this service at the top of
+            // the list to be bound.
+            mPriority = Integer.MAX_VALUE;
+        } else if (mJustBound) {
+            // If we just bound, lets not thrash on binding/unbinding too much, this is second most
+            // important.
+            mPriority = Integer.MAX_VALUE - 1;
+        } else if (!mBindRequested) {
+            // Don't care about binding right now, put us last.
+            mPriority = Integer.MIN_VALUE;
+        } else {
+            // Order based on whether this was just updated.
+            long timeSinceUpdate = currentTime - mLastUpdate;
+            // Fit compare into integer space for simplicity. Make sure to leave MAX_VALUE and
+            // MAX_VALUE - 1 for the more important states above.
+            if (timeSinceUpdate > Integer.MAX_VALUE - 2) {
+                mPriority = Integer.MAX_VALUE - 2;
+            } else {
+                mPriority = (int) timeSinceUpdate;
+            }
+        }
+    }
+
+    public int getBindPriority() {
+        return mPriority;
+    }
+
+    private final Runnable mUnbind = new Runnable() {
+        @Override
+        public void run() {
+            if (mBound && !mBindRequested) {
+                unbindService();
+            }
+        }
+    };
+
+    @VisibleForTesting
+    final Runnable mJustBoundOver = new Runnable() {
+        @Override
+        public void run() {
+            mJustBound = false;
+            mServices.recalculateBindAllowance();
+        }
+    };
+}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/TileServices.java b/packages/SystemUI/src/com/android/systemui/qs/external/TileServices.java
new file mode 100644
index 0000000..7403ae0
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/external/TileServices.java
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.systemui.qs.external;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.RemoteException;
+import android.service.quicksettings.IQSService;
+import android.service.quicksettings.Tile;
+import android.service.quicksettings.TileService;
+import android.util.ArrayMap;
+import android.util.Log;
+import com.android.systemui.statusbar.phone.QSTileHost;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
+/**
+ * Runs the day-to-day operations of which tiles should be bound and when.
+ */
+public class TileServices extends IQSService.Stub {
+    static final int DEFAULT_MAX_BOUND = 3;
+    static final int REDUCED_MAX_BOUND = 1;
+
+    private final ArrayMap<CustomTile, TileServiceManager> mServices = new ArrayMap<>();
+    private final ArrayMap<ComponentName, CustomTile> mTiles = new ArrayMap<>();
+    private final Context mContext;
+    private final Handler mHandler;
+    private final QSTileHost mHost;
+
+    private int mMaxBound = DEFAULT_MAX_BOUND;
+
+    public TileServices(QSTileHost host, Looper looper) {
+        mHost = host;
+        mContext = mHost.getContext();
+        mContext.registerReceiver(mRequestListeningReceiver,
+                new IntentFilter(TileService.ACTION_REQUEST_LISTENING));
+        mHandler = new Handler(looper);
+    }
+
+    public Context getContext() {
+        return mContext;
+    }
+
+    public TileServiceManager getTileWrapper(CustomTile tile) {
+        ComponentName component = tile.getComponent();
+        TileServiceManager service = onCreateTileService(component);
+        synchronized (mServices) {
+            mServices.put(tile, service);
+            mTiles.put(component, tile);
+        }
+        return service;
+    }
+
+    protected TileServiceManager onCreateTileService(ComponentName component) {
+        return new TileServiceManager(this, mHandler, component);
+    }
+
+    public void freeService(CustomTile tile, TileServiceManager service) {
+        synchronized (mServices) {
+            service.setBindAllowed(false);
+            mServices.remove(tile);
+            mTiles.remove(tile.getComponent());
+        }
+    }
+
+    public void setMemoryPressure(boolean memoryPressure) {
+        mMaxBound = memoryPressure ? REDUCED_MAX_BOUND : DEFAULT_MAX_BOUND;
+        recalculateBindAllowance();
+    }
+
+    public void recalculateBindAllowance() {
+        final ArrayList<TileServiceManager> services;
+        synchronized (mServices) {
+            services = new ArrayList<>(mServices.values());
+        }
+        final int N = services.size();
+        if (N > mMaxBound) {
+            long currentTime = System.currentTimeMillis();
+            // Precalculate the priority of services for binding.
+            for (int i = 0; i < N; i++) {
+                services.get(i).calculateBindPriority(currentTime);
+            }
+            // Sort them so we can bind the most important first.
+            Collections.sort(services, SERVICE_SORT);
+        }
+        int i;
+        // Allow mMaxBound items to bind.
+        for (i = 0; i < mMaxBound && i < N; i++) {
+            services.get(i).setBindAllowed(true);
+        }
+        // The rest aren't allowed to bind for now.
+        while (i < N) {
+            services.get(i).setBindAllowed(false);
+            i++;
+        }
+    }
+
+    private void verifyCaller(String packageName) {
+        try {
+            int uid = mContext.getPackageManager().getPackageUidAsUser(packageName,
+                    Binder.getCallingUserHandle().getIdentifier());
+            if (Binder.getCallingUid() != uid) {
+                throw new SecurityException("Component outside caller's uid");
+            }
+        } catch (PackageManager.NameNotFoundException e) {
+            throw new SecurityException(e);
+        }
+    }
+
+    private void requestListening(ComponentName component) {
+        synchronized (mServices) {
+            CustomTile customTile = getTileForComponent(component);
+            if (customTile == null) {
+                Log.d("TileServices", "Couldn't find tile for " + component);
+                return;
+            }
+            TileServiceManager service = mServices.get(customTile);
+            if (service.getType() != TileService.TILE_MODE_ACTIVE) {
+                return;
+            }
+            service.setBindRequested(true);
+            try {
+                service.getTileService().onStartListening();
+            } catch (RemoteException e) {
+            }
+        }
+    }
+
+    @Override
+    public void setTileMode(ComponentName component, int mode) {
+        verifyCaller(component.getPackageName());
+        CustomTile customTile = getTileForComponent(component);
+        if (customTile != null) {
+            synchronized (mServices) {
+                mServices.get(customTile).setType(mode);
+            }
+        }
+    }
+
+    @Override
+    public void updateQsTile(Tile tile) {
+        verifyCaller(tile.getComponentName().getPackageName());
+        CustomTile customTile = getTileForComponent(tile.getComponentName());
+        if (customTile != null) {
+            synchronized (mServices) {
+                mServices.get(customTile).setLastUpdate(System.currentTimeMillis());
+            }
+            customTile.updateState(tile);
+            customTile.refreshState();
+        }
+    }
+
+    @Override
+    public void onShowDialog(Tile tile) {
+        verifyCaller(tile.getComponentName().getPackageName());
+        CustomTile customTile = getTileForComponent(tile.getComponentName());
+        if (customTile != null) {
+            customTile.onDialogShown();
+            mHost.collapsePanels();
+        }
+    }
+
+    private CustomTile getTileForComponent(ComponentName component) {
+        synchronized (mServices) {
+            return mTiles.get(component);
+        }
+    }
+
+    private final BroadcastReceiver mRequestListeningReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (TileService.ACTION_REQUEST_LISTENING.equals(intent.getAction())) {
+                requestListening(
+                        (ComponentName) intent.getParcelableExtra(TileService.EXTRA_COMPONENT));
+            }
+        }
+    };
+
+    private static final Comparator<TileServiceManager> SERVICE_SORT =
+            new Comparator<TileServiceManager>() {
+        @Override
+        public int compare(TileServiceManager left, TileServiceManager right) {
+            return -Integer.compare(left.getBindPriority(), right.getBindPriority());
+        }
+    };
+}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/AirplaneModeTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/AirplaneModeTile.java
index fc802dd..c696f88 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/AirplaneModeTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/AirplaneModeTile.java
@@ -58,8 +58,6 @@
     public void handleClick() {
         MetricsLogger.action(mContext, getMetricsCategory(), !mState.value);
         setEnabled(!mState.value);
-        mEnable.setAllowAnimation(true);
-        mDisable.setAllowAnimation(true);
     }
 
     private void setEnabled(boolean enabled) {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java
index f73ee35..23a15b9 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java
@@ -71,8 +71,6 @@
     protected void handleClick() {
         MetricsLogger.action(mContext, getMetricsCategory(), !mState.value);
         mSetting.setValue(mState.value ? 0 : 1);
-        mEnable.setAllowAnimation(true);
-        mDisable.setAllowAnimation(true);
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java
index d96f735..4f9f46d 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java
@@ -107,8 +107,6 @@
                     Toast.LENGTH_LONG).show();
             return;
         }
-        mDisable.setAllowAnimation(true);
-        mDisableTotalSilence.setAllowAnimation(true);
         MetricsLogger.action(mContext, getMetricsCategory(), !mState.value);
         if (mState.value) {
             mController.setZen(Global.ZEN_MODE_OFF, null, TAG);
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java
index 12c1298..39d9da1 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/FlashlightTile.java
@@ -64,7 +64,7 @@
         }
         MetricsLogger.action(mContext, getMetricsCategory(), !mState.value);
         boolean newState = !mState.value;
-        refreshState(newState ? UserBoolean.USER_TRUE : UserBoolean.USER_FALSE);
+        refreshState(newState);
         mFlashlightController.setFlashlight(newState);
     }
 
@@ -73,8 +73,8 @@
         // TODO: Flashlight available handling...
 //        state.visible = mFlashlightController.isAvailable();
         state.label = mHost.getContext().getString(R.string.quick_settings_flashlight_label);
-        if (arg instanceof UserBoolean) {
-            boolean value = ((UserBoolean) arg).value;
+        if (arg instanceof Boolean) {
+            boolean value = (Boolean) arg;
             if (value == state.value) {
                 return;
             }
@@ -83,7 +83,6 @@
             state.value = mFlashlightController.isEnabled();
         }
         final AnimationIcon icon = state.value ? mEnable : mDisable;
-        icon.setAllowAnimation(arg instanceof UserBoolean && ((UserBoolean) arg).userInitiated);
         state.icon = icon;
         int onOrOffId = state.value
                 ? R.string.accessibility_quick_settings_flashlight_on
@@ -107,12 +106,12 @@
 
     @Override
     public void onFlashlightChanged(boolean enabled) {
-        refreshState(enabled ? UserBoolean.BACKGROUND_TRUE : UserBoolean.BACKGROUND_FALSE);
+        refreshState(enabled);
     }
 
     @Override
     public void onFlashlightError() {
-        refreshState(UserBoolean.BACKGROUND_FALSE);
+        refreshState(false);
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java
index 250d567..55aa32b 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java
@@ -59,8 +59,6 @@
         final boolean isEnabled = (Boolean) mState.value;
         MetricsLogger.action(mContext, getMetricsCategory(), !isEnabled);
         mController.setHotspotEnabled(!isEnabled);
-        mEnable.setAllowAnimation(true);
-        mDisable.setAllowAnimation(true);
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java
index 08540f6..e79aabf 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/LocationTile.java
@@ -67,8 +67,6 @@
                     mHost.openPanels();
                     MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled);
                     mController.setLocationEnabled(!wasEnabled);
-                    mEnable.setAllowAnimation(true);
-                    mDisable.setAllowAnimation(true);
                 }
             });
             return;
@@ -76,8 +74,6 @@
         final boolean wasEnabled = (Boolean) mState.value;
         MetricsLogger.action(mContext, getMetricsCategory(), !wasEnabled);
         mController.setLocationEnabled(!wasEnabled);
-        mEnable.setAllowAnimation(true);
-        mDisable.setAllowAnimation(true);
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java
index d85cf60..7bce54b 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/RotationLockTile.java
@@ -63,15 +63,14 @@
         MetricsLogger.action(mContext, getMetricsCategory(), !mState.value);
         final boolean newState = !mState.value;
         mController.setRotationLocked(newState);
-        refreshState(newState ? UserBoolean.USER_TRUE : UserBoolean.USER_FALSE);
+        refreshState(newState);
     }
 
     @Override
     protected void handleUpdateState(BooleanState state, Object arg) {
         if (mController == null) return;
-        final boolean rotationLocked = arg != null ? ((UserBoolean) arg).value
+        final boolean rotationLocked = arg != null ? (Boolean) arg
                 : mController.isRotationLocked();
-        final boolean userInitiated = arg != null ? ((UserBoolean) arg).userInitiated : false;
         // TODO: Handle accessibility rotation lock and whatnot.
 //        state.visible = mController.isRotationLockAffordanceVisible();
         if (state.value == rotationLocked && state.contentDescription != null) {
@@ -80,18 +79,15 @@
         }
         state.value = rotationLocked;
         final boolean portrait = isCurrentOrientationLockPortrait();
-        final AnimationIcon icon;
         if (rotationLocked) {
             final int label = portrait ? R.string.quick_settings_rotation_locked_portrait_label
                     : R.string.quick_settings_rotation_locked_landscape_label;
             state.label = mContext.getString(label);
-            icon = portrait ? mAutoToPortrait : mAutoToLandscape;
+            state.icon = portrait ? mAutoToPortrait : mAutoToLandscape;
         } else {
             state.label = mContext.getString(R.string.quick_settings_rotation_unlocked_label);
-            icon = portrait ? mPortraitToAuto : mLandscapeToAuto;
+            state.icon = portrait ? mPortraitToAuto : mLandscapeToAuto;
         }
-        icon.setAllowAnimation(userInitiated);
-        state.icon = icon;
         state.contentDescription = getAccessibilityString(rotationLocked,
                 R.string.accessibility_rotation_lock_on_portrait,
                 R.string.accessibility_rotation_lock_on_landscape,
@@ -145,8 +141,7 @@
     private final RotationLockControllerCallback mCallback = new RotationLockControllerCallback() {
         @Override
         public void onRotationLockStateChanged(boolean rotationLocked, boolean affordanceVisible) {
-            refreshState(rotationLocked ? UserBoolean.BACKGROUND_TRUE
-                    : UserBoolean.BACKGROUND_FALSE);
+            refreshState(rotationLocked);
         }
     };
 }
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java
index 07915f8..255f29f 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java
@@ -93,12 +93,7 @@
     }
 
     private void refreshQuietModeState(boolean backgroundRefresh) {
-        if (backgroundRefresh) {
-            refreshState(isWorkModeEnabled() ? UserBoolean.BACKGROUND_TRUE
-                    : UserBoolean.BACKGROUND_FALSE);
-        } else {
-            refreshState(isWorkModeEnabled() ? UserBoolean.USER_TRUE : UserBoolean.USER_FALSE);
-        }
+        refreshState(isWorkModeEnabled());
     }
 
     @Override
@@ -108,28 +103,22 @@
             return;
         }
 
-        final boolean userInitialized;
-        if (arg instanceof UserBoolean) {
-            state.value = ((UserBoolean) arg).value;
-            userInitialized = ((UserBoolean) arg).userInitiated;
+        if (arg instanceof Boolean) {
+            state.value = (Boolean) arg;
         } else {
             state.value = isWorkModeEnabled();
-            userInitialized = false;
         }
 
-        final AnimationIcon icon;
         state.label = mContext.getString(R.string.quick_settings_work_mode_label);
         if (state.value) {
-            icon = mEnable;
+            state.icon = mEnable;
             state.contentDescription =  mContext.getString(
                     R.string.accessibility_quick_settings_work_mode_on);
         } else {
-            icon = mDisable;
+            state.icon = mDisable;
             state.contentDescription =  mContext.getString(
                     R.string.accessibility_quick_settings_work_mode_off);
         }
-        icon.setAllowAnimation(userInitialized);
-        state.icon = icon;
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
index ffcc805..e4d8067 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java
@@ -43,8 +43,10 @@
 import com.android.systemui.recents.events.activity.AppWidgetProviderChangedEvent;
 import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent;
 import com.android.systemui.recents.events.activity.DebugFlagsChangedEvent;
+import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
 import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent;
 import com.android.systemui.recents.events.activity.EnterRecentsWindowLastAnimationFrameEvent;
+import com.android.systemui.recents.events.activity.ExitRecentsWindowFirstAnimationFrameEvent;
 import com.android.systemui.recents.events.activity.HideHistoryEvent;
 import com.android.systemui.recents.events.activity.HideRecentsEvent;
 import com.android.systemui.recents.events.activity.IterateRecentsEvent;
@@ -56,8 +58,7 @@
 import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent;
 import com.android.systemui.recents.events.component.ScreenPinningRequestEvent;
 import com.android.systemui.recents.events.ui.AllTaskViewsDismissedEvent;
-import com.android.systemui.recents.events.ui.DismissTaskEvent;
-import com.android.systemui.recents.events.ui.DismissTaskViewEvent;
+import com.android.systemui.recents.events.ui.DeleteTaskDataEvent;
 import com.android.systemui.recents.events.ui.ShowApplicationInfoEvent;
 import com.android.systemui.recents.events.ui.StackViewScrolledEvent;
 import com.android.systemui.recents.events.ui.UpdateFreeformTaskViewVisibilityEvent;
@@ -67,7 +68,6 @@
 import com.android.systemui.recents.events.ui.focus.FocusPreviousTaskViewEvent;
 import com.android.systemui.recents.history.RecentsHistoryView;
 import com.android.systemui.recents.misc.DozeTrigger;
-import com.android.systemui.recents.misc.ReferenceCountedTrigger;
 import com.android.systemui.recents.misc.SystemServicesProxy;
 import com.android.systemui.recents.model.RecentsPackageMonitor;
 import com.android.systemui.recents.model.RecentsTaskLoadPlan;
@@ -76,7 +76,7 @@
 import com.android.systemui.recents.model.TaskStack;
 import com.android.systemui.recents.views.RecentsView;
 import com.android.systemui.recents.views.SystemBarScrimViews;
-import com.android.systemui.recents.views.ViewAnimation;
+import com.android.systemui.statusbar.BaseStatusBar;
 
 import java.util.ArrayList;
 
@@ -273,7 +273,7 @@
             // If we have a focused Task, launch that Task now
             if (mRecentsView.launchPreviousTask()) return true;
             // If none of the other cases apply, then just go Home
-            dismissRecentsToHome(true);
+            dismissRecentsToHome(true /* animateTaskViews */);
         }
         return false;
     }
@@ -287,7 +287,7 @@
             // If we have a focused Task, launch that Task now
             if (mRecentsView.launchFocusedTask()) return true;
             // If none of the other cases apply, then just go Home
-            dismissRecentsToHome(true);
+            dismissRecentsToHome(true /* animateTaskViews */);
             return true;
         }
         return false;
@@ -296,21 +296,18 @@
     /**
      * Dismisses Recents directly to Home without checking whether it is currently visible.
      */
-    void dismissRecentsToHome(boolean animated) {
-        if (animated) {
-            ReferenceCountedTrigger exitTrigger = new ReferenceCountedTrigger(null,
-                    mFinishLaunchHomeRunnable, null);
-            mRecentsView.startExitToHomeAnimation(
-                    new ViewAnimation.TaskViewExitContext(exitTrigger));
-        } else {
-            mFinishLaunchHomeRunnable.run();
-        }
-    }
-
-    /** Dismisses Recents directly to Home without transition animation. */
-    void dismissRecentsToHomeWithoutTransitionAnimation() {
-        finish();
-        overridePendingTransition(0, 0);
+    void dismissRecentsToHome(boolean animateTaskViews) {
+        DismissRecentsToHomeAnimationStarted dismissEvent =
+                new DismissRecentsToHomeAnimationStarted(animateTaskViews);
+        dismissEvent.addPostAnimationCallback(mFinishLaunchHomeRunnable);
+        dismissEvent.addPostAnimationCallback(new Runnable() {
+            @Override
+            public void run() {
+                Recents.getSystemServices().sendCloseSystemWindows(
+                        BaseStatusBar.SYSTEM_DIALOG_REASON_HOME_KEY);
+            }
+        });
+        EventBus.getDefault().send(dismissEvent);
     }
 
     /** Dismisses Recents directly to Home if we currently aren't transitioning. */
@@ -343,7 +340,7 @@
         EventBus.getDefault().register(this, EVENT_BUS_PRIORITY);
 
         // Initialize the widget host (the host id is static and does not change)
-        if (!RecentsDebugFlags.Static.DisableSearchBar) {
+        if (RecentsDebugFlags.Static.EnableSearchBar) {
             mAppWidgetHost = new RecentsAppWidgetHost(this, RecentsAppWidgetHost.HOST_ID);
         }
         mPackageMonitor = new RecentsPackageMonitor();
@@ -368,14 +365,14 @@
         mFinishLaunchHomeRunnable = new FinishRecentsRunnable(homeIntent);
 
         // Bind the search app widget when we first start up
-        if (!RecentsDebugFlags.Static.DisableSearchBar) {
+        if (RecentsDebugFlags.Static.EnableSearchBar) {
             mSearchWidgetInfo = ssp.getOrBindSearchAppWidget(this, mAppWidgetHost);
         }
 
         // Register the broadcast receiver to handle messages when the screen is turned off
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_SCREEN_OFF);
-        if (!RecentsDebugFlags.Static.DisableSearchBar) {
+        if (RecentsDebugFlags.Static.EnableSearchBar) {
             filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
         }
         registerReceiver(mSystemBroadcastReceiver, filter);
@@ -475,7 +472,7 @@
         mPackageMonitor.unregister();
 
         // Stop listening for widget package changes if there was one bound
-        if (!RecentsDebugFlags.Static.DisableSearchBar) {
+        if (RecentsDebugFlags.Static.EnableSearchBar) {
             mAppWidgetHost.stopListening();
         }
 
@@ -597,7 +594,7 @@
         if (!dismissHistory()) {
             RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
             if (launchState.launchedFromHome) {
-                dismissRecentsToHome(true);
+                dismissRecentsToHome(true /* animateTaskViews */);
             } else {
                 dismissRecentsToLaunchTargetTaskOrHome();
             }
@@ -638,13 +635,13 @@
                 hideEvent.addPostAnimationCallback(new Runnable() {
                     @Override
                     public void run() {
-                        dismissRecentsToHome(true /* animated */);
+                        dismissRecentsToHome(true /* animateTaskViews */);
                     }
                 });
                 EventBus.getDefault().send(hideEvent);
 
             } else {
-                dismissRecentsToHome(true /* animated */);
+                dismissRecentsToHome(true /* animateTaskViews */);
             }
         } else {
             // Do nothing
@@ -653,12 +650,9 @@
 
     public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) {
         // Try and start the enter animation (or restart it on configuration changed)
-        ReferenceCountedTrigger t = new ReferenceCountedTrigger();
-        ViewAnimation.TaskViewEnterContext ctx = new ViewAnimation.TaskViewEnterContext(t);
-        ctx.postAnimationTrigger.increment();
-        if (mSearchWidgetInfo != null) {
-            if (!RecentsDebugFlags.Static.DisableSearchBar) {
-                ctx.postAnimationTrigger.addLastDecrementRunnable(new Runnable() {
+        if (RecentsDebugFlags.Static.EnableSearchBar) {
+            if (mSearchWidgetInfo != null) {
+                event.addPostAnimationCallback(new Runnable() {
                     @Override
                     public void run() {
                         // Start listening for widget package changes if there is one bound
@@ -669,8 +663,6 @@
                 });
             }
         }
-        mRecentsView.startEnterRecentsAnimation(ctx);
-        ctx.postAnimationTrigger.decrement();
     }
 
     public final void onBusEvent(EnterRecentsWindowLastAnimationFrameEvent event) {
@@ -715,7 +707,7 @@
         MetricsLogger.count(this, "overview_app_info", 1);
     }
 
-    public final void onBusEvent(DismissTaskEvent event) {
+    public final void onBusEvent(DeleteTaskDataEvent event) {
         // Remove any stored data from the loader
         RecentsTaskLoader loader = Recents.getTaskLoader();
         loader.deleteTaskData(event.task, false);
@@ -731,7 +723,7 @@
             mRecentsView.showEmptyView();
         } else {
             // Just go straight home (no animation necessary because there are no more task views)
-            dismissRecentsToHome(false /* animated */);
+            dismissRecentsToHome(false /* animateTaskViews */);
         }
 
         // Keep track of all-deletions
@@ -744,7 +736,7 @@
 
     public final void onBusEvent(LaunchTaskFailedEvent event) {
         // Return to Home
-        dismissRecentsToHome(true);
+        dismissRecentsToHome(true /* animateTaskViews */);
 
         MetricsLogger.count(this, "overview_task_launch_failed", 1);
     }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java
index 7547570f..67135d5 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsConfiguration.java
@@ -19,7 +19,6 @@
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Rect;
-import android.provider.Settings;
 import com.android.systemui.R;
 import com.android.systemui.recents.misc.SystemServicesProxy;
 
@@ -74,9 +73,6 @@
     public int svelteLevel;
     public int searchBarSpaceHeightPx;
 
-    /** Dev options and global settings */
-    public boolean lockToAppEnabled;
-
     public RecentsConfiguration(Context context) {
         // Load only resources that can not change after the first load either through developer
         // settings or via multi window
@@ -106,12 +102,7 @@
     /**
      * Updates the configuration based on the current state of the system
      */
-    void update(Context context, SystemServicesProxy ssp, Rect windowRect) {
-        // Only update resources that can change after the first load, either through developer
-        // settings or via multi window
-        lockToAppEnabled = !ssp.hasFreeformWorkspaceSupport() &&
-                ssp.getSystemSetting(context, Settings.System.LOCK_TO_APP_ENABLED) != 0;
-
+    void update(Rect windowRect) {
         // Recompute some values based on the given state, since we can not rely on the resource
         // system to get certain values.
         boolean isLandscape = windowRect.width() > windowRect.height();
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsDebugFlags.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsDebugFlags.java
index 40c84ba..c323522 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsDebugFlags.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsDebugFlags.java
@@ -32,8 +32,8 @@
     public static class Static {
         // Enables debug drawing for the transition thumbnail
         public static final boolean EnableTransitionThumbnailDebugMode = false;
-        // This disables the search bar integration
-        public static final boolean DisableSearchBar = true;
+        // This enables the search bar integration
+        public static final boolean EnableSearchBar = false;
         // This disables the bitmap and icon caches
         public static final boolean DisableBackgroundCache = false;
         // Enables the simulated task affiliations
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java
index 949fb86..213018a 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java
@@ -19,6 +19,7 @@
 import android.app.ActivityManager;
 import android.app.ActivityOptions;
 import android.app.ITaskStackListener;
+import android.appwidget.AppWidgetProviderInfo;
 import android.content.ActivityNotFoundException;
 import android.content.Context;
 import android.content.Intent;
@@ -60,6 +61,7 @@
 import com.android.systemui.recents.views.TaskStackView;
 import com.android.systemui.recents.views.TaskViewHeader;
 import com.android.systemui.recents.views.TaskViewTransform;
+import com.android.systemui.statusbar.BaseStatusBar;
 import com.android.systemui.statusbar.phone.PhoneStatusBar;
 
 import java.util.ArrayList;
@@ -104,6 +106,10 @@
             mHandler.post(this);
         }
 
+        @Override
+        public void onActivityPinned() {
+        }
+
         /** Preloads the next task */
         public void run() {
             // TODO: Temporarily skip this if multi stack is enabled
@@ -332,7 +338,6 @@
             if (topTask != null && ssp.isRecentsTopMost(topTask, isTopTaskHome)) {
                 RecentsConfiguration config = Recents.getConfiguration();
                 RecentsActivityLaunchState launchState = config.getLaunchState();
-                RecentsDebugFlags flags = Recents.getDebugFlags();
                 if (!launchState.launchedWithAltTab) {
                     // Notify recents to move onto the next task
                     EventBus.getDefault().post(new IterateRecentsEvent());
@@ -360,6 +365,9 @@
 
                 // Otherwise, start the recents activity
                 startRecentsActivity(topTask, isTopTaskHome.value, true /* animate */);
+
+                // Only close the other system windows if we are actually showing recents
+                ssp.sendCloseSystemWindows(BaseStatusBar.SYSTEM_DIALOG_REASON_RECENT_APPS);
                 mLastToggleTime = SystemClock.elapsedRealtime();
             }
         } catch (ActivityNotFoundException e) {
@@ -572,9 +580,9 @@
         Rect windowRect = ssp.getWindowRect();
 
         // Update the configuration for the current state
-        config.update(mContext, ssp, ssp.getWindowRect());
+        config.update(windowRect);
 
-        if (!RecentsDebugFlags.Static.DisableSearchBar && tryAndBindSearchWidget) {
+        if (RecentsDebugFlags.Static.EnableSearchBar && tryAndBindSearchWidget) {
             // Try and pre-emptively bind the search widget on startup to ensure that we
             // have the right thumbnail bounds to animate to.
             // Note: We have to reload the widget id before we get the task stack bounds below
@@ -850,11 +858,19 @@
         if (!useThumbnailTransition) {
             // If there is no thumbnail transition, but is launching from home into recents, then
             // use a quick home transition and do the animation from home
-            if (!RecentsDebugFlags.Static.DisableSearchBar && hasRecentTasks) {
+            if (hasRecentTasks) {
                 SystemServicesProxy ssp = Recents.getSystemServices();
                 String homeActivityPackage = ssp.getHomeActivityPackageName();
-                String searchWidgetPackage = Prefs.getString(mContext,
-                        Prefs.Key.OVERVIEW_SEARCH_APP_WIDGET_PACKAGE, null);
+                String searchWidgetPackage = null;
+                if (RecentsDebugFlags.Static.EnableSearchBar) {
+                    searchWidgetPackage = Prefs.getString(mContext,
+                            Prefs.Key.OVERVIEW_SEARCH_APP_WIDGET_PACKAGE, null);
+                } else {
+                    AppWidgetProviderInfo searchWidgetInfo = ssp.resolveSearchAppWidget();
+                    if (searchWidgetInfo != null) {
+                        searchWidgetPackage = searchWidgetInfo.provider.getPackageName();
+                    }
+                }
 
                 // Determine whether we are coming from a search owned home activity
                 boolean fromSearchHome = (homeActivityPackage != null) &&
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/EventBus.java b/packages/SystemUI/src/com/android/systemui/recents/events/EventBus.java
index 5c49ac3..b0c8ff3 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/events/EventBus.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/EventBus.java
@@ -27,7 +27,6 @@
 import android.os.UserHandle;
 import android.util.Log;
 import android.util.MutableBoolean;
-
 import com.android.systemui.recents.misc.ReferenceCountedTrigger;
 
 import java.lang.ref.WeakReference;
@@ -663,8 +662,6 @@
 
     /**
      * Registers a new subscriber.
-     *
-     * @return return whether or not this
      */
     private void registerSubscriber(Object subscriber, int priority,
             MutableBoolean hasInterprocessEventsChangedOut) {
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/DismissRecentsToHomeAnimationStarted.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/DismissRecentsToHomeAnimationStarted.java
index 5f3e830..e7be858 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/events/activity/DismissRecentsToHomeAnimationStarted.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/DismissRecentsToHomeAnimationStarted.java
@@ -21,6 +21,11 @@
 /**
  * This is sent when the task animation when dismissing Recents starts.
  */
-public class DismissRecentsToHomeAnimationStarted extends EventBus.Event {
-    // Simple event
+public class DismissRecentsToHomeAnimationStarted extends EventBus.AnimatedEvent {
+
+    public final boolean animated;
+
+    public DismissRecentsToHomeAnimationStarted(boolean animated) {
+        this.animated = animated;
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/EnterRecentsWindowAnimationCompletedEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/EnterRecentsWindowAnimationCompletedEvent.java
index b31f320..918875a 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/events/activity/EnterRecentsWindowAnimationCompletedEvent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/EnterRecentsWindowAnimationCompletedEvent.java
@@ -23,6 +23,6 @@
  * we can start in-app animations so that they don't conflict with the window transition into
  * Recents.
  */
-public class EnterRecentsWindowAnimationCompletedEvent extends EventBus.Event {
+public class EnterRecentsWindowAnimationCompletedEvent extends EventBus.AnimatedEvent {
     // Simple event
 }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/ExitRecentsWindowFirstAnimationFrameEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/ExitRecentsWindowFirstAnimationFrameEvent.java
similarity index 94%
rename from packages/SystemUI/src/com/android/systemui/recents/ExitRecentsWindowFirstAnimationFrameEvent.java
rename to packages/SystemUI/src/com/android/systemui/recents/events/activity/ExitRecentsWindowFirstAnimationFrameEvent.java
index 8ae8c53..fa806eb 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/ExitRecentsWindowFirstAnimationFrameEvent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/ExitRecentsWindowFirstAnimationFrameEvent.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.systemui.recents;
+package com.android.systemui.recents.events.activity;
 
 import com.android.systemui.recents.events.EventBus;
 
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/HideHistoryEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/HideHistoryEvent.java
index e85dea3..af3eeb0 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/events/activity/HideHistoryEvent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/HideHistoryEvent.java
@@ -17,7 +17,6 @@
 package com.android.systemui.recents.events.activity;
 
 import com.android.systemui.recents.events.EventBus;
-import com.android.systemui.recents.misc.ReferenceCountedTrigger;
 
 /**
  * This is sent when the history view will be closed.
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskEvent.java
index 457d81e..21b9301 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskEvent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskEvent.java
@@ -22,7 +22,7 @@
 import com.android.systemui.recents.views.TaskView;
 
 /**
- * This is sent to launch a task from Recents.
+ * This event is sent to request that a particular task is launched.
  */
 public class LaunchTaskEvent extends EventBus.Event {
 
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskStartedEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskStartedEvent.java
new file mode 100644
index 0000000..3925ab1
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/LaunchTaskStartedEvent.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.recents.events.activity;
+
+import com.android.systemui.recents.events.EventBus;
+import com.android.systemui.recents.views.TaskView;
+
+/**
+ * This event is sent following {@link LaunchTaskEvent} after the call to the system is made to
+ * start the task.
+ */
+public class LaunchTaskStartedEvent extends EventBus.AnimatedEvent {
+
+    public final TaskView taskView;
+    public final boolean screenPinningRequested;
+
+    public LaunchTaskStartedEvent(TaskView taskView, boolean screenPinningRequested) {
+        this.taskView = taskView;
+        this.screenPinningRequested = screenPinningRequested;
+    }
+
+}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/ShowHistoryEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/ShowHistoryEvent.java
index 94e5a97..b39d645 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/events/activity/ShowHistoryEvent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/ShowHistoryEvent.java
@@ -17,7 +17,6 @@
 package com.android.systemui.recents.events.activity;
 
 import com.android.systemui.recents.events.EventBus;
-import com.android.systemui.recents.misc.ReferenceCountedTrigger;
 
 /**
  * This is sent when the history view button is clicked.
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/TaskStackUpdatedEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/TaskStackUpdatedEvent.java
index b94ed7b..7579cd8 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/events/activity/TaskStackUpdatedEvent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/TaskStackUpdatedEvent.java
@@ -16,7 +16,6 @@
 
 package com.android.systemui.recents.events.activity;
 
-import com.android.systemui.recents.RecentsAppWidgetHost;
 import com.android.systemui.recents.events.EventBus;
 import com.android.systemui.recents.model.TaskStack;
 
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/ui/DeleteTaskDataEvent.java
similarity index 80%
rename from packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskEvent.java
rename to packages/SystemUI/src/com/android/systemui/recents/events/ui/DeleteTaskDataEvent.java
index bcbbde8..4ed0270 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskEvent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/ui/DeleteTaskDataEvent.java
@@ -18,16 +18,16 @@
 
 import com.android.systemui.recents.events.EventBus;
 import com.android.systemui.recents.model.Task;
-import com.android.systemui.recents.views.TaskView;
 
 /**
- * This is sent when a {@link Task} has been dismissed.
+ * This is sent when the data associated with a given {@link Task} should be deleted from the
+ * system.
  */
-public class DismissTaskEvent extends EventBus.Event {
+public class DeleteTaskDataEvent extends EventBus.Event {
 
     public final Task task;
 
-    public DismissTaskEvent(Task task) {
+    public DeleteTaskDataEvent(Task task) {
         this.task = task;
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskViewEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskViewEvent.java
index 968890a..1165f4e 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskViewEvent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskViewEvent.java
@@ -21,15 +21,15 @@
 import com.android.systemui.recents.views.TaskView;
 
 /**
- * This is sent when a {@link TaskView} has been dismissed.
+ * This event is sent to request that the given {@link TaskView} is dismissed.
  */
-public class DismissTaskViewEvent extends EventBus.Event {
+public class DismissTaskViewEvent extends EventBus.AnimatedEvent {
 
-    public final Task task;
     public final TaskView taskView;
+    public final Task task;
 
-    public DismissTaskViewEvent(Task task, TaskView taskView) {
-        this.task = task;
+    public DismissTaskViewEvent(TaskView taskView, Task task) {
         this.taskView = taskView;
+        this.task = task;
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/ui/TaskViewDismissedEvent.java
similarity index 75%
copy from packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskEvent.java
copy to packages/SystemUI/src/com/android/systemui/recents/events/ui/TaskViewDismissedEvent.java
index bcbbde8..7bd0958 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/events/ui/DismissTaskEvent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/ui/TaskViewDismissedEvent.java
@@ -21,13 +21,15 @@
 import com.android.systemui.recents.views.TaskView;
 
 /**
- * This is sent when a {@link Task} has been dismissed.
+ * This event is sent when a {@link TaskView} has been dismissed and is no longer visible.
  */
-public class DismissTaskEvent extends EventBus.Event {
+public class TaskViewDismissedEvent extends EventBus.Event {
 
     public final Task task;
+    public final TaskView taskView;
 
-    public DismissTaskEvent(Task task) {
+    public TaskViewDismissedEvent(Task task, TaskView taskView) {
         this.task = task;
+        this.taskView = taskView;
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/ui/dragndrop/DragEndEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/ui/dragndrop/DragEndEvent.java
index 8aa4631..73c282f 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/events/ui/dragndrop/DragEndEvent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/ui/dragndrop/DragEndEvent.java
@@ -17,7 +17,6 @@
 package com.android.systemui.recents.events.ui.dragndrop;
 
 import com.android.systemui.recents.events.EventBus;
-import com.android.systemui.recents.misc.ReferenceCountedTrigger;
 import com.android.systemui.recents.model.Task;
 import com.android.systemui.recents.views.DropTarget;
 import com.android.systemui.recents.views.TaskView;
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/ui/focus/DismissFocusedTaskViewEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/ui/focus/DismissFocusedTaskViewEvent.java
index 9f3e9d5..df74018 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/events/ui/focus/DismissFocusedTaskViewEvent.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/ui/focus/DismissFocusedTaskViewEvent.java
@@ -17,9 +17,10 @@
 package com.android.systemui.recents.events.ui.focus;
 
 import com.android.systemui.recents.events.EventBus;
+import com.android.systemui.recents.views.TaskView;
 
 /**
- * Dismisses the currently focused task view.
+ * This event is sent to request that the currently focused {@link TaskView} is dismissed.
  */
 public class DismissFocusedTaskViewEvent extends EventBus.Event {
     // Simple event
diff --git a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java
index 72ec7b7..f0fa1da 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java
@@ -185,7 +185,6 @@
      * remove the task from the TaskStack since the TaskStackView will also receive this event.
      */
     public void removeTasks(String packageName, int userId) {
-        boolean packagesRemoved = false;
         for (int i = mRows.size() - 1; i >= 0; i--) {
             Row row = mRows.get(i);
             if (row.getViewType() == TASK_ROW_VIEW_TYPE) {
diff --git a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryItemTouchCallbacks.java b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryItemTouchCallbacks.java
index e0a2730..a91ea7e 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryItemTouchCallbacks.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryItemTouchCallbacks.java
@@ -22,7 +22,7 @@
 import com.android.internal.logging.MetricsLogger;
 import com.android.systemui.recents.Constants;
 import com.android.systemui.recents.events.EventBus;
-import com.android.systemui.recents.events.ui.DismissTaskEvent;
+import com.android.systemui.recents.events.ui.DeleteTaskDataEvent;
 
 
 /**
@@ -65,7 +65,7 @@
             RecentsHistoryAdapter.TaskRow taskRow = (RecentsHistoryAdapter.TaskRow) row;
 
             // Remove the task from the system
-            EventBus.getDefault().send(new DismissTaskEvent(taskRow.task));
+            EventBus.getDefault().send(new DeleteTaskDataEvent(taskRow.task));
             mAdapter.onTaskRemoved(taskRow.task, position);
 
             // Keep track of deletions by swiping within history
diff --git a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryView.java b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryView.java
index 9524da5..a2f5159 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryView.java
@@ -35,7 +35,6 @@
 import com.android.systemui.recents.events.EventBus;
 import com.android.systemui.recents.events.activity.PackagesChangedEvent;
 import com.android.systemui.recents.misc.ReferenceCountedTrigger;
-import com.android.systemui.recents.misc.SystemServicesProxy;
 import com.android.systemui.recents.model.TaskStack;
 
 /**
diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/ReferenceCountedTrigger.java b/packages/SystemUI/src/com/android/systemui/recents/misc/ReferenceCountedTrigger.java
index 367f2e2..2637d88 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/misc/ReferenceCountedTrigger.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/misc/ReferenceCountedTrigger.java
@@ -18,8 +18,6 @@
 
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
-import android.content.Context;
-import android.util.Log;
 
 import java.util.ArrayList;
 
@@ -30,8 +28,8 @@
 public class ReferenceCountedTrigger {
 
     int mCount;
-    ArrayList<Runnable> mFirstIncRunnables = new ArrayList<Runnable>();
-    ArrayList<Runnable> mLastDecRunnables = new ArrayList<Runnable>();
+    ArrayList<Runnable> mFirstIncRunnables = new ArrayList<>();
+    ArrayList<Runnable> mLastDecRunnables = new ArrayList<>();
     Runnable mErrorRunnable;
 
     // Convenience runnables
@@ -107,16 +105,20 @@
         mLastDecRunnables.clear();
     }
 
-    /** Convenience method to decrement this trigger as a runnable. */
-    public Runnable decrementAsRunnable() {
-        return mDecrementRunnable;
-    }
-    /** Convenience method to decrement this trigger as a animator listener. */
+    /**
+     * Convenience method to decrement this trigger as a animator listener.  This listener is
+     * guarded to prevent being called back multiple times, and will trigger a decrement once and
+     * only once.
+     */
     public Animator.AnimatorListener decrementOnAnimationEnd() {
         return new AnimatorListenerAdapter() {
+            private boolean hasEnded;
+
             @Override
             public void onAnimationEnd(Animator animation) {
+                if (hasEnded) return;
                 decrement();
+                hasEnded = true;
             }
         };
     }
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 35e53f6..dfcf41bc 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java
@@ -58,7 +58,7 @@
 import android.util.MutableBoolean;
 import android.util.Pair;
 import android.view.Display;
-import android.view.IDockDividerVisibilityListener;
+import android.view.IDockedStackListener;
 import android.view.WindowManager;
 import android.view.WindowManagerGlobal;
 import android.view.accessibility.AccessibilityManager;
@@ -78,7 +78,7 @@
 import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
 import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
 import static android.app.ActivityManager.StackId.HOME_STACK_ID;
-import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
+import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT;
 
 /**
  * Acts as a shim around the real system services that we need to access data from, and provides
@@ -128,7 +128,9 @@
         mDisplay = mWm.getDefaultDisplay();
         mRecentsPackage = context.getPackageName();
         mHasFreeformWorkspaceSupport =
-                mPm.hasSystemFeature(PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT);
+                mPm.hasSystemFeature(PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT) ||
+                        Settings.Global.getInt(context.getContentResolver(),
+                                DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0;
 
         // Get the dummy thumbnail width/heights
         Resources res = context.getResources();
@@ -310,7 +312,8 @@
         try {
             final ActivityOptions options = ActivityOptions.makeBasic();
             options.setDockCreateMode(createMode);
-            mIam.startActivityFromRecents(taskId, DOCKED_STACK_ID, options.toBundle());
+            options.setLaunchStackId(DOCKED_STACK_ID);
+            mIam.startActivityFromRecents(taskId, options.toBundle());
         } catch (RemoteException e) {
             e.printStackTrace();
         }
@@ -465,7 +468,7 @@
 
         try {
             mIam.positionTaskInStack(taskId, stackId, 0);
-        } catch (RemoteException e) {
+        } catch (RemoteException | IllegalArgumentException e) {
             e.printStackTrace();
         }
     }
@@ -498,6 +501,18 @@
     }
 
     /**
+     * Sends a message to close other system windows.
+     */
+    public void sendCloseSystemWindows(String reason) {
+        if (ActivityManagerNative.isSystemReady()) {
+            try {
+                ActivityManagerNative.getDefault().closeSystemDialogs(reason);
+            } catch (RemoteException e) {
+            }
+        }
+    }
+
+    /**
      * Returns the activity info for a given component name.
      *
      * @param cn The component name of the activity.
@@ -634,7 +649,7 @@
         if (mPm == null) return null;
         if (RecentsDebugFlags.Static.EnableSystemServicesProxy) return null;
 
-        ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
+        ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
         ComponentName defaultHomeActivity = mPm.getHomeActivities(homeActivities);
         if (defaultHomeActivity != null) {
             return defaultHomeActivity.getPackageName();
@@ -722,7 +737,7 @@
     /**
      * Returns the first Recents widget from the same package as the global assist activity.
      */
-    private AppWidgetProviderInfo resolveSearchAppWidget() {
+    public AppWidgetProviderInfo resolveSearchAppWidget() {
         if (mAssistComponent == null) return null;
         List<AppWidgetProviderInfo> widgets = mAwm.getInstalledProviders(
                 AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
@@ -836,8 +851,7 @@
             ActivityOptions options) {
         if (mIam != null) {
             try {
-                mIam.startActivityFromRecents(
-                        taskId, INVALID_STACK_ID, options == null ? null : options.toBundle());
+                mIam.startActivityFromRecents(taskId, options == null ? null : options.toBundle());
                 return true;
             } catch (Exception e) {
                 Log.e(TAG, context.getString(R.string.recents_launch_error_message, taskName), e);
@@ -879,12 +893,11 @@
         }
     }
 
-    public void registerDockDividerVisibilityListener(IDockDividerVisibilityListener listener) {
+    public void registerDockedStackListener(IDockedStackListener listener) {
         if (mWm == null) return;
 
         try {
-            WindowManagerGlobal.getWindowManagerService().registerDockDividerVisibilityListener(
-                    listener);
+            WindowManagerGlobal.getWindowManagerService().registerDockedStackListener(listener);
         } catch (Exception e) {
             e.printStackTrace();
         }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/Utilities.java b/packages/SystemUI/src/com/android/systemui/recents/misc/Utilities.java
index 2bf2ccb..086fb58 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/misc/Utilities.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/misc/Utilities.java
@@ -88,6 +88,15 @@
     }
 
     /**
+     * Cancels an animation.
+     */
+    public static void cancelAnimation(Animator animator) {
+        if (animator != null) {
+            animator.cancel();
+        }
+    }
+
+    /**
      * Cancels an animation ensuring that if it has listeners, onCancel and onEnd
      * are not called.
      */
diff --git a/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java b/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java
index 7a92b2a..d8dfce5 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java
@@ -25,7 +25,6 @@
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.util.ArraySet;
-import android.util.Log;
 import com.android.systemui.Prefs;
 import com.android.systemui.recents.Recents;
 import com.android.systemui.recents.RecentsConfiguration;
@@ -115,8 +114,6 @@
      * - least-recent to most-recent freeform tasks
      */
     public synchronized void preloadPlan(RecentsTaskLoader loader, boolean isTopTaskHome) {
-        RecentsConfiguration config = Recents.getConfiguration();
-        SystemServicesProxy ssp = Recents.getSystemServices();
         Resources res = mContext.getResources();
         ArrayList<Task> allTasks = new ArrayList<>();
         if (mRawTasks == null) {
@@ -155,7 +152,7 @@
             // Add the task to the stack
             Task task = new Task(taskKey, t.affiliatedTaskId, t.affiliatedTaskColor, icon,
                     thumbnail, title, contentDescription, activityColor, !isStackTask,
-                    (i == (taskCount - 1)), config.lockToAppEnabled, t.bounds, t.taskDescription);
+                    t.bounds, t.taskDescription);
 
             allTasks.add(task);
         }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/model/Task.java b/packages/SystemUI/src/com/android/systemui/recents/model/Task.java
index 34a0e52..f7e2b9d 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/model/Task.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/model/Task.java
@@ -131,8 +131,6 @@
      */
     public boolean isLaunchTarget;
     public boolean isHistorical;
-    public boolean lockToThisTask;
-    public boolean lockToTaskEnabled;
 
     private ArrayList<TaskCallbacks> mCallbacks = new ArrayList<>();
 
@@ -142,8 +140,8 @@
 
     public Task(TaskKey key, int affiliationTaskId, int affiliationColor, Drawable icon,
                 Bitmap thumbnail, String title, String contentDescription, int colorPrimary,
-                boolean isHistorical, boolean lockToThisTask, boolean lockToTaskEnabled,
-                Rect bounds, ActivityManager.TaskDescription taskDescription) {
+                boolean isHistorical, Rect bounds,
+                ActivityManager.TaskDescription taskDescription) {
         boolean isInAffiliationGroup = (affiliationTaskId != key.id);
         boolean hasAffiliationGroupColor = isInAffiliationGroup && (affiliationColor != 0);
         this.key = key;
@@ -159,8 +157,6 @@
         this.bounds = bounds;
         this.taskDescription = taskDescription;
         this.isHistorical = isHistorical;
-        this.lockToThisTask = lockToTaskEnabled && lockToThisTask;
-        this.lockToTaskEnabled = lockToTaskEnabled;
     }
 
     /** Copies the other task. */
@@ -178,8 +174,6 @@
         this.bounds = o.bounds;
         this.isLaunchTarget = o.isLaunchTarget;
         this.isHistorical = o.isHistorical;
-        this.lockToThisTask = o.lockToThisTask;
-        this.lockToTaskEnabled = o.lockToTaskEnabled;
     }
 
     /**
@@ -236,8 +230,7 @@
     public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultApplicationIcon) {
         icon = defaultApplicationIcon;
         thumbnail = defaultThumbnail;
-        int callbackCount = mCallbacks.size();
-        for (int i = 0; i < callbackCount; i++) {
+        for (int i = mCallbacks.size() - 1; i >= 0; i--) {
             mCallbacks.get(i).onTaskDataUnloaded();
         }
     }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java b/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java
index 6f003ab..856200d 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/model/TaskStack.java
@@ -427,8 +427,6 @@
                 removeGroup(group);
             }
         }
-        // Update the lock-to-app state
-        t.lockToThisTask = false;
     }
 
     /** Removes a task */
@@ -437,9 +435,6 @@
             boolean wasFrontMostTask = (getStackFrontMostTask() == t);
             removeTaskImpl(mStackTaskList, t);
             Task newFrontMostTask = getStackFrontMostTask();
-            if (newFrontMostTask != null && newFrontMostTask.lockToTaskEnabled) {
-                newFrontMostTask.lockToThisTask = true;
-            }
             if (mCb != null) {
                 // Notify that a task has been removed
                 mCb.onStackTaskRemoved(this, t, wasFrontMostTask, newFrontMostTask);
@@ -500,9 +495,6 @@
         // Sort all the tasks to ensure they are ordered correctly
         Collections.sort(newTasks, FREEFORM_LAST_ACTIVE_TIME_COMPARATOR);
 
-        // TODO: Update screen pinning for the new front-most task post refactoring lockToTask out
-        // of the Task
-
         // Filter out the historical tasks from this new list
         ArrayList<Task> stackTasks = new ArrayList<>();
         ArrayList<Task> historyTasks = new ArrayList<>();
@@ -524,10 +516,21 @@
         mAffinitiesGroups.clear();
     }
 
-    /** Gets the front task */
+    /**
+     * Gets the front-most task in the stack.
+     */
     public Task getStackFrontMostTask() {
-        if (mStackTaskList.size() == 0) return null;
-        return mStackTaskList.getTasks().get(mStackTaskList.size() - 1);
+        ArrayList<Task> stackTasks = mStackTaskList.getTasks();
+        if (stackTasks.isEmpty()) {
+            return null;
+        }
+        for (int i = stackTasks.size() - 1; i >= 0; i--) {
+            Task task = stackTasks.get(i);
+            if (!task.isFreeformTask()) {
+                return task;
+            }
+        }
+        return null;
     }
 
     /** Gets the task keys */
@@ -558,6 +561,22 @@
     }
 
     /**
+     * Returns the set of "freeform" tasks in the stack.
+     */
+    public ArrayList<Task> getFreeformTasks() {
+        ArrayList<Task> freeformTasks = new ArrayList<>();
+        ArrayList<Task> tasks = mStackTaskList.getTasks();
+        int taskCount = tasks.size();
+        for (int i = 0; i < taskCount; i++) {
+            Task task = tasks.get(i);
+            if (task.isFreeformTask()) {
+                freeformTasks.add(task);
+            }
+        }
+        return freeformTasks;
+    }
+
+    /**
      * Computes a set of all the active and historical tasks ordered by their last active time.
      */
     public ArrayList<Task> computeAllTasksList() {
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/AnimateableViewBounds.java b/packages/SystemUI/src/com/android/systemui/recents/views/AnimateableViewBounds.java
index c0b8a9d..b8bbf51 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/AnimateableViewBounds.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/AnimateableViewBounds.java
@@ -18,8 +18,6 @@
 
 import android.graphics.Outline;
 import android.graphics.Rect;
-import android.util.IntProperty;
-import android.util.Property;
 import android.view.View;
 import android.view.ViewOutlineProvider;
 
@@ -29,23 +27,11 @@
     View mSourceView;
     Rect mClipRect = new Rect();
     Rect mClipBounds = new Rect();
+    Rect mLastClipBounds = new Rect();
     int mCornerRadius;
     float mAlpha = 1f;
     final float mMinAlpha = 0.25f;
 
-    public static final Property<AnimateableViewBounds, Integer> CLIP_BOTTOM =
-            new IntProperty<AnimateableViewBounds>("clipBottom") {
-                @Override
-                public void setValue(AnimateableViewBounds object, int clip) {
-                    object.setClipBottom(clip, false /* force */);
-                }
-
-                @Override
-                public Integer get(AnimateableViewBounds object) {
-                    return object.getClipBottom();
-                }
-            };
-
     public AnimateableViewBounds(View source, int cornerRadius) {
         mSourceView = source;
         mCornerRadius = cornerRadius;
@@ -77,11 +63,9 @@
     }
 
     /** Sets the bottom clip. */
-    public void setClipBottom(int bottom, boolean force) {
-        if (bottom != mClipRect.bottom || force) {
-            mClipRect.bottom = bottom;
-            updateClipBounds();
-        }
+    public void setClipBottom(int bottom) {
+        mClipRect.bottom = bottom;
+        updateClipBounds();
     }
 
     /** Returns the bottom clip. */
@@ -93,7 +77,10 @@
         mClipBounds.set(Math.max(0, mClipRect.left), Math.max(0, mClipRect.top),
                 mSourceView.getWidth() - Math.max(0, mClipRect.right),
                 mSourceView.getHeight() - Math.max(0, mClipRect.bottom));
-        mSourceView.setClipBounds(mClipBounds);
-        mSourceView.invalidateOutline();
+        if (!mLastClipBounds.equals(mClipBounds)) {
+            mSourceView.setClipBounds(mClipBounds);
+            mSourceView.invalidateOutline();
+            mLastClipBounds.set(mClipBounds);
+        }
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/FreeformWorkspaceLayoutAlgorithm.java b/packages/SystemUI/src/com/android/systemui/recents/views/FreeformWorkspaceLayoutAlgorithm.java
index 7f907ef..fce916b 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/FreeformWorkspaceLayoutAlgorithm.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/FreeformWorkspaceLayoutAlgorithm.java
@@ -19,8 +19,6 @@
 import android.content.Context;
 import android.graphics.Rect;
 import android.graphics.RectF;
-import android.util.Log;
-
 import com.android.systemui.R;
 import com.android.systemui.recents.model.Task;
 
@@ -33,9 +31,6 @@
  */
 public class FreeformWorkspaceLayoutAlgorithm {
 
-    private static final String TAG = "FreeformWorkspaceLayoutAlgorithm";
-    private static final boolean DEBUG = false;
-
     // Optimization, allows for quick lookup of task -> rect
     private HashMap<Task.TaskKey, RectF> mTaskRectMap = new HashMap<>();
 
@@ -177,10 +172,6 @@
             transformOut.rect.offset(stackLayout.mFreeformRect.left, stackLayout.mFreeformRect.top);
             transformOut.visible = true;
             transformOut.p = 1f;
-
-            if (DEBUG) {
-                Log.d(TAG, "getTransform: " + task.key + ", " + transformOut);
-            }
             return transformOut;
         }
         return null;
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java
index 0af7c1e..51cae86 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsTransitionHelper.java
@@ -32,15 +32,15 @@
 import android.view.IAppTransitionAnimationSpecsFuture;
 import android.view.WindowManagerGlobal;
 import com.android.internal.annotations.GuardedBy;
-import com.android.systemui.recents.ExitRecentsWindowFirstAnimationFrameEvent;
 import com.android.systemui.recents.Recents;
 import com.android.systemui.recents.RecentsDebugFlags;
 import com.android.systemui.recents.events.EventBus;
 import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent;
+import com.android.systemui.recents.events.activity.ExitRecentsWindowFirstAnimationFrameEvent;
 import com.android.systemui.recents.events.activity.LaunchTaskFailedEvent;
+import com.android.systemui.recents.events.activity.LaunchTaskStartedEvent;
 import com.android.systemui.recents.events.activity.LaunchTaskSucceededEvent;
 import com.android.systemui.recents.events.component.ScreenPinningRequestEvent;
-import com.android.systemui.recents.events.ui.DismissTaskViewEvent;
 import com.android.systemui.recents.misc.SystemServicesProxy;
 import com.android.systemui.recents.model.Task;
 import com.android.systemui.recents.model.TaskStack;
@@ -90,7 +90,7 @@
      */
     public void launchTaskFromRecents(final TaskStack stack, @Nullable final Task task,
             final TaskStackView stackView, final TaskView taskView,
-            final boolean lockToTask, final Rect bounds, int destinationStack) {
+            final boolean screenPinningRequested, final Rect bounds, int destinationStack) {
         final ActivityOptions opts = ActivityOptions.makeBasic();
         if (bounds != null) {
             opts.setLaunchBounds(bounds.isEmpty() ? null : bounds);
@@ -109,7 +109,7 @@
                     EventBus.getDefault().send(new CancelEnterRecentsWindowAnimationEvent(task));
                     EventBus.getDefault().send(new ExitRecentsWindowFirstAnimationFrameEvent());
 
-                    if (lockToTask) {
+                    if (screenPinningRequested) {
                         // Request screen pinning after the animation runs
                         mHandler.postDelayed(mStartScreenPinningRunnable, 350);
                     }
@@ -131,16 +131,19 @@
             // task views, and we can launch immediately
             startTaskActivity(stack, task, taskView, opts, transitionFuture, animStartedListener);
         } else {
+            LaunchTaskStartedEvent launchStartedEvent = new LaunchTaskStartedEvent(taskView,
+                    screenPinningRequested);
             if (task.group != null && !task.group.isFrontMostTask(task)) {
-                stackView.startLaunchTaskAnimation(taskView, new Runnable() {
+                launchStartedEvent.addPostAnimationCallback(new Runnable() {
                     @Override
                     public void run() {
                         startTaskActivity(stack, task, taskView, opts, transitionFuture,
                                 animStartedListener);
                     }
-                }, lockToTask);
+                });
+                EventBus.getDefault().send(launchStartedEvent);
             } else {
-                stackView.startLaunchTaskAnimation(taskView, null, lockToTask);
+                EventBus.getDefault().send(launchStartedEvent);
                 startTaskActivity(stack, task, taskView, opts, transitionFuture,
                         animStartedListener);
             }
@@ -167,7 +170,7 @@
             EventBus.getDefault().send(new LaunchTaskSucceededEvent(taskIndexFromFront));
         } else {
             // Dismiss the task if we fail to launch it
-            EventBus.getDefault().send(new DismissTaskViewEvent(task, taskView));
+            taskView.dismissTask();
 
             // Keep track of failed launches
             EventBus.getDefault().send(new LaunchTaskFailedEvent());
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
index 9b1315a..e28e2b3 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
@@ -16,8 +16,9 @@
 
 package com.android.systemui.recents.views;
 
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
 import android.content.Context;
-import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
@@ -32,8 +33,8 @@
 import android.view.animation.AnimationUtils;
 import android.view.animation.Interpolator;
 import android.widget.FrameLayout;
-import com.android.internal.logging.MetricsLogger;
 import android.widget.TextView;
+import com.android.internal.logging.MetricsLogger;
 import com.android.systemui.R;
 import com.android.systemui.recents.Recents;
 import com.android.systemui.recents.RecentsActivity;
@@ -43,7 +44,6 @@
 import com.android.systemui.recents.RecentsDebugFlags;
 import com.android.systemui.recents.events.EventBus;
 import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent;
-import com.android.systemui.recents.events.activity.DebugFlagsChangedEvent;
 import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
 import com.android.systemui.recents.events.activity.HideHistoryButtonEvent;
 import com.android.systemui.recents.events.activity.HideHistoryEvent;
@@ -65,6 +65,7 @@
 import com.android.systemui.statusbar.FlingAnimationUtils;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
@@ -116,7 +117,6 @@
 
     public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
-        Resources res = context.getResources();
         setWillNotDraw(false);
         mHandler = new Handler();
         mTransitionHelper = new RecentsTransitionHelper(getContext(), mHandler);
@@ -145,14 +145,11 @@
         RecentsConfiguration config = Recents.getConfiguration();
         RecentsActivityLaunchState launchState = config.getLaunchState();
         mStack = stack;
-        // Disable reusing task stack views until the visibility bug is fixed. b/25998134
-        if (false && launchState.launchedReuseTaskStackViews) {
+        if (launchState.launchedReuseTaskStackViews) {
             if (mTaskStackView != null) {
                 // If onRecentsHidden is not triggered, we need to the stack view again here
                 mTaskStackView.reset();
                 mTaskStackView.setStack(stack);
-                removeView(mTaskStackView);
-                addView(mTaskStackView);
             } else {
                 mTaskStackView = new TaskStackView(getContext(), stack);
                 addView(mTaskStackView);
@@ -216,7 +213,6 @@
     /** Launches the focused task from the first stack if possible */
     public boolean launchFocusedTask() {
         if (mTaskStackView != null) {
-            TaskStack stack = mTaskStackView.getStack();
             Task task = mTaskStackView.getFocusedTask();
             if (task != null) {
                 TaskView taskView = mTaskStackView.getChildViewForTask(task);
@@ -246,7 +242,6 @@
     /** Launches a given task. */
     public boolean launchTask(Task task, Rect taskBounds, int destinationStack) {
         if (mTaskStackView != null) {
-            TaskStack stack = mTaskStackView.getStack();
             // Iterate the stack views and try and find the given task.
             List<TaskView> taskViews = mTaskStackView.getTaskViews();
             int taskViewCount = taskViews.size();
@@ -262,39 +257,6 @@
         return false;
     }
 
-    /** Requests all task stacks to start their enter-recents animation */
-    public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) {
-        // We have to increment/decrement the post animation trigger in case there are no children
-        // to ensure that it runs
-        ctx.postAnimationTrigger.increment();
-        if (mTaskStackView != null) {
-            mTaskStackView.startEnterRecentsAnimation(ctx);
-        }
-        ctx.postAnimationTrigger.decrement();
-    }
-
-    /** Requests all task stacks to start their exit-recents animation */
-    public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) {
-        // We have to increment/decrement the post animation trigger in case there are no children
-        // to ensure that it runs
-        ctx.postAnimationTrigger.increment();
-        if (mTaskStackView != null) {
-            mTaskStackView.startExitToHomeAnimation(ctx);
-        }
-        ctx.postAnimationTrigger.decrement();
-
-        // Hide the history button
-        int taskViewExitToHomeDuration = getResources().getInteger(
-                R.integer.recents_task_exit_to_home_duration);
-        hideHistoryButton(taskViewExitToHomeDuration);
-
-        // If we are going home, cancel the previous task's window transition
-        EventBus.getDefault().send(new CancelEnterRecentsWindowAnimationEvent(null));
-
-        // Notify sof the exit animation
-        EventBus.getDefault().send(new DismissRecentsToHomeAnimationStarted());
-    }
-
     /** Adds the search bar */
     public void setSearchBar(RecentsAppWidgetHostView searchBar) {
         // Remove the previous search bar if one exists
@@ -317,7 +279,7 @@
      * Hides the task stack and shows the empty view.
      */
     public void showEmptyView() {
-        if (!RecentsDebugFlags.Static.DisableSearchBar && (mSearchBar != null)) {
+        if (RecentsDebugFlags.Static.EnableSearchBar && (mSearchBar != null)) {
             mSearchBar.setVisibility(View.INVISIBLE);
         }
         mTaskStackView.setVisibility(View.INVISIBLE);
@@ -332,7 +294,7 @@
     public void hideEmptyView() {
         mEmptyView.setVisibility(View.INVISIBLE);
         mTaskStackView.setVisibility(View.VISIBLE);
-        if (!RecentsDebugFlags.Static.DisableSearchBar && (mSearchBar != null)) {
+        if (RecentsDebugFlags.Static.EnableSearchBar && (mSearchBar != null)) {
             mSearchBar.setVisibility(View.VISIBLE);
         }
         mTaskStackView.bringToFront();
@@ -496,6 +458,16 @@
                 event.screenPinningRequested, event.targetTaskBounds, event.targetTaskStack);
     }
 
+    public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) {
+        // Hide the history button
+        int taskViewExitToHomeDuration = getResources().getInteger(
+                R.integer.recents_task_exit_to_home_duration);
+        hideHistoryButton(taskViewExitToHomeDuration);
+
+        // If we are going home, cancel the previous task's window transition
+        EventBus.getDefault().send(new CancelEnterRecentsWindowAnimationEvent(null));
+    }
+
     public final void onBusEvent(DragStartEvent event) {
         updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(),
                 TaskStack.DockState.NONE.viewState.dockAreaAlpha);
@@ -517,23 +489,25 @@
 
         // Handle the case where we drop onto a dock region
         if (event.dropTarget instanceof TaskStack.DockState) {
-            final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget;
+            TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget;
+            TaskStackLayoutAlgorithm stackLayout = mTaskStackView.getStackAlgorithm();
+            TaskStackViewScroller stackScroller = mTaskStackView.getScroller();
+            TaskViewTransform tmpTransform = new TaskViewTransform();
 
-            // Remove the task after it is docked
-            event.taskView.animate()
-                    .alpha(0f)
-                    .setDuration(150)
-                    .setInterpolator(mFastOutLinearInInterpolator)
-                    .setUpdateListener(null)
-                    .setListener(null)
-                    .withEndAction(new Runnable() {
-                        @Override
-                        public void run() {
-                            mTaskStackView.getStack().removeTask(event.task);
-                        }
-                    })
-                    .withLayer()
-                    .start();
+            // Remove the task view after it is docked
+            stackLayout.getStackTransform(event.task, stackScroller.getStackScroll(), tmpTransform,
+                    null);
+            tmpTransform.scale = event.taskView.getScaleX();
+            tmpTransform.rect.offset(event.taskView.getTranslationX(),
+                    event.taskView.getTranslationY());
+            mTaskStackView.updateTaskViewToTransform(event.taskView, tmpTransform,
+                    new TaskViewAnimation(150, mFastOutLinearInInterpolator,
+                            new AnimatorListenerAdapter() {
+                                @Override
+                                public void onAnimationEnd(Animator animation) {
+                                    mTaskStackView.getStack().removeTask(event.task);
+                                }
+                            }));
 
             // Dock the task and launch it
             SystemServicesProxy ssp = Recents.getSystemServices();
@@ -613,21 +587,23 @@
 
     private void showHistoryButton(final int duration,
             final ReferenceCountedTrigger postHideHistoryAnimationTrigger) {
-        mHistoryButton.setVisibility(View.VISIBLE);
-        mHistoryButton.setAlpha(0f);
         mHistoryButton.setText(getContext().getString(R.string.recents_history_label_format,
                 mStack.getHistoricalTasks().size()));
-        postHideHistoryAnimationTrigger.addLastDecrementRunnable(new Runnable() {
-            @Override
-            public void run() {
-                mHistoryButton.animate()
-                        .alpha(1f)
-                        .setDuration(duration)
-                        .setInterpolator(mFastOutSlowInInterpolator)
-                        .withLayer()
-                        .start();
-            }
-        });
+        if (mHistoryButton.getVisibility() == View.INVISIBLE) {
+            mHistoryButton.setVisibility(View.VISIBLE);
+            mHistoryButton.setAlpha(0f);
+            postHideHistoryAnimationTrigger.addLastDecrementRunnable(new Runnable() {
+                @Override
+                public void run() {
+                    mHistoryButton.animate()
+                            .alpha(1f)
+                            .setDuration(duration)
+                            .setInterpolator(mFastOutSlowInInterpolator)
+                            .withLayer()
+                            .start();
+                }
+            });
+        }
     }
 
     /**
@@ -641,20 +617,22 @@
 
     private void hideHistoryButton(int duration,
             final ReferenceCountedTrigger postHideStackAnimationTrigger) {
-        mHistoryButton.animate()
-                .alpha(0f)
-                .setDuration(duration)
-                .setInterpolator(mFastOutLinearInInterpolator)
-                .withEndAction(new Runnable() {
-                    @Override
-                    public void run() {
-                        mHistoryButton.setVisibility(View.INVISIBLE);
-                        postHideStackAnimationTrigger.decrement();
-                    }
-                })
-                .withLayer()
-                .start();
-        postHideStackAnimationTrigger.increment();
+        if (mHistoryButton.getVisibility() == View.VISIBLE) {
+            mHistoryButton.animate()
+                    .alpha(0f)
+                    .setDuration(duration)
+                    .setInterpolator(mFastOutLinearInInterpolator)
+                    .withEndAction(new Runnable() {
+                        @Override
+                        public void run() {
+                            mHistoryButton.setVisibility(View.INVISIBLE);
+                            postHideStackAnimationTrigger.decrement();
+                        }
+                    })
+                    .withLayer()
+                    .start();
+            postHideStackAnimationTrigger.increment();
+        }
     }
 
     /**
@@ -663,9 +641,7 @@
     private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates, int overrideAlpha) {
         ArraySet<TaskStack.DockState> newDockStatesSet = new ArraySet<>();
         if (newDockStates != null) {
-            for (TaskStack.DockState dockState : newDockStates) {
-                newDockStatesSet.add(dockState);
-            }
+            Collections.addAll(newDockStatesSet, newDockStates);
         }
         for (TaskStack.DockState dockState : mVisibleDockStates) {
             TaskStack.DockState.ViewState viewState = dockState.viewState;
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsViewTouchHandler.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsViewTouchHandler.java
index 318801d..473334b 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsViewTouchHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsViewTouchHandler.java
@@ -26,7 +26,6 @@
 import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent;
 import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent;
 import com.android.systemui.recents.events.ui.dragndrop.DragStartInitializeDropTargetsEvent;
-import com.android.systemui.recents.misc.ReferenceCountedTrigger;
 import com.android.systemui.recents.misc.SystemServicesProxy;
 import com.android.systemui.recents.model.Task;
 import com.android.systemui.recents.model.TaskStack;
@@ -58,9 +57,6 @@
  */
 public class RecentsViewTouchHandler {
 
-    private static final String TAG = "RecentsViewTouchHandler";
-    private static final boolean DEBUG = false;
-
     private RecentsView mRv;
 
     private Task mDragTask;
@@ -128,7 +124,6 @@
         mTaskView.setTranslationX(x);
         mTaskView.setTranslationY(y);
 
-        RecentsConfiguration config = Recents.getConfiguration();
         if (!ssp.hasDockedTask()) {
             // Add the dock state drop targets (these take priority)
             TaskStack.DockState[] dockStates = getDockStatesForCurrentOrientation();
@@ -150,7 +145,6 @@
 
     /**
      * Handles dragging touch events
-     * @param ev
      */
     private void handleTouchEvent(MotionEvent ev) {
         int action = ev.getAction();
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/SystemBarScrimViews.java b/packages/SystemUI/src/com/android/systemui/recents/views/SystemBarScrimViews.java
index f84eb53..9618f212d 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/SystemBarScrimViews.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/SystemBarScrimViews.java
@@ -22,9 +22,6 @@
 import android.view.animation.AnimationUtils;
 import android.view.animation.Interpolator;
 import com.android.systemui.R;
-import com.android.systemui.recents.Recents;
-import com.android.systemui.recents.RecentsActivityLaunchState;
-import com.android.systemui.recents.RecentsConfiguration;
 import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
 import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent;
 
@@ -64,8 +61,6 @@
      */
     public void prepareEnterRecentsAnimation(boolean hasStatusBarScrim, boolean animateStatusBarScrim,
             boolean hasNavBarScrim, boolean animateNavBarScrim) {
-        RecentsConfiguration config = Recents.getConfiguration();
-        RecentsActivityLaunchState launchState = config.getLaunchState();
         mHasNavBarScrim = hasStatusBarScrim;
         mShouldAnimateStatusBarScrim = animateStatusBarScrim;
         mHasStatusBarScrim = hasNavBarScrim;
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackAnimationHelper.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackAnimationHelper.java
new file mode 100644
index 0000000..80a35de
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackAnimationHelper.java
@@ -0,0 +1,397 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.recents.views;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.RectF;
+import android.view.View;
+import android.view.animation.AnimationUtils;
+import android.view.animation.Interpolator;
+import com.android.systemui.R;
+import com.android.systemui.recents.Recents;
+import com.android.systemui.recents.RecentsActivityLaunchState;
+import com.android.systemui.recents.RecentsConfiguration;
+import com.android.systemui.recents.misc.ReferenceCountedTrigger;
+import com.android.systemui.recents.model.Task;
+import com.android.systemui.recents.model.TaskStack;
+import com.android.systemui.statusbar.phone.PhoneStatusBar;
+
+import java.util.List;
+
+/**
+ * A helper class to create task view animations for {@link TaskView}s in a {@link TaskStackView},
+ * but not the contents of the {@link TaskView}s.
+ */
+public class TaskStackAnimationHelper {
+
+    /**
+     * Callbacks from the helper to coordinate view-content animations with view animations.
+     */
+    public interface Callbacks {
+        /**
+         * Callback to prepare for the start animation for the launch target {@link TaskView}.
+         */
+        void onPrepareLaunchTargetForEnterAnimation();
+
+        /**
+         * Callback to start the animation for the launch target {@link TaskView}.
+         */
+        void onStartLaunchTargetEnterAnimation(int duration, boolean screenPinningEnabled,
+                ReferenceCountedTrigger postAnimationTrigger);
+
+        /**
+         * Callback to start the animation for the launch target {@link TaskView} when it is
+         * launched from Recents.
+         */
+        void onStartLaunchTargetLaunchAnimation(int duration, boolean screenPinningRequested,
+                ReferenceCountedTrigger postAnimationTrigger);
+    }
+
+    private TaskStackView mStackView;
+
+    private Interpolator mFastOutSlowInInterpolator;
+    private Interpolator mFastOutLinearInInterpolator;
+    private Interpolator mQuintOutInterpolator;
+
+    private TaskViewTransform mTmpTransform = new TaskViewTransform();
+
+    public TaskStackAnimationHelper(Context context, TaskStackView stackView) {
+        mStackView = stackView;
+        mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
+                com.android.internal.R.interpolator.fast_out_slow_in);
+        mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
+                com.android.internal.R.interpolator.fast_out_linear_in);
+        mQuintOutInterpolator = AnimationUtils.loadInterpolator(context,
+                com.android.internal.R.interpolator.decelerate_quint);
+    }
+
+    /**
+     * Prepares the stack views and puts them in their initial animation state while visible, before
+     * the in-app enter animations start (after the window-transition completes).
+     */
+    public void prepareForEnterAnimation() {
+        RecentsConfiguration config = Recents.getConfiguration();
+        RecentsActivityLaunchState launchState = config.getLaunchState();
+        Resources res = mStackView.getResources();
+
+        TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
+        TaskStackViewScroller stackScroller = mStackView.getScroller();
+        TaskStack stack = mStackView.getStack();
+        Task launchTargetTask = stack.getLaunchTarget();
+
+        // Break early if there are no tasks
+        if (stack.getStackTaskCount() == 0) {
+            return;
+        }
+
+        int offscreenY = stackLayout.mStackRect.bottom;
+        int taskViewAffiliateGroupEnterOffset = res.getDimensionPixelSize(
+                R.dimen.recents_task_view_affiliate_group_enter_offset);
+
+        // Prepare each of the task views for their enter animation from front to back
+        List<TaskView> taskViews = mStackView.getTaskViews();
+        for (int i = taskViews.size() - 1; i >= 0; i--) {
+            TaskView tv = taskViews.get(i);
+            Task task = tv.getTask();
+            boolean currentTaskOccludesLaunchTarget = (launchTargetTask != null &&
+                    launchTargetTask.group.isTaskAboveTask(task, launchTargetTask));
+            boolean hideTask = (launchTargetTask != null &&
+                    launchTargetTask.isFreeformTask() && task.isFreeformTask());
+
+            // Get the current transform for the task, which will be used to position it offscreen
+            stackLayout.getStackTransform(task, stackScroller.getStackScroll(), mTmpTransform,
+                    null);
+
+            if (hideTask) {
+                tv.setVisibility(View.INVISIBLE);
+            } else if (launchState.launchedHasConfigurationChanged) {
+                // Just load the views as-is
+            } else if (launchState.launchedFromAppWithThumbnail) {
+                if (task.isLaunchTarget) {
+                    tv.onPrepareLaunchTargetForEnterAnimation();
+                } else if (currentTaskOccludesLaunchTarget) {
+                    // Move the task view slightly lower so we can animate it in
+                    RectF bounds = new RectF(mTmpTransform.rect);
+                    bounds.offset(0, taskViewAffiliateGroupEnterOffset);
+                    tv.setAlpha(0f);
+                    tv.setLeftTopRightBottom((int) bounds.left, (int) bounds.top,
+                            (int) bounds.right, (int) bounds.bottom);
+                }
+            } else if (launchState.launchedFromHome) {
+                // Move the task view off screen (below) so we can animate it in
+                RectF bounds = new RectF(mTmpTransform.rect);
+                bounds.offset(0, offscreenY);
+                tv.setLeftTopRightBottom((int) bounds.left, (int) bounds.top, (int) bounds.right,
+                        (int) bounds.bottom);
+            }
+        }
+    }
+
+    /**
+     * Starts the in-app enter animation, which animates the {@link TaskView}s to their final places
+     * depending on how Recents was triggered.
+     */
+    public void startEnterAnimation(final ReferenceCountedTrigger postAnimationTrigger) {
+        RecentsConfiguration config = Recents.getConfiguration();
+        RecentsActivityLaunchState launchState = config.getLaunchState();
+        Resources res = mStackView.getResources();
+
+        TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
+        TaskStackViewScroller stackScroller = mStackView.getScroller();
+        TaskStack stack = mStackView.getStack();
+        Task launchTargetTask = stack.getLaunchTarget();
+
+        // Break early if there are no tasks
+        if (stack.getStackTaskCount() == 0) {
+            return;
+        }
+
+        int taskViewEnterFromAppDuration = res.getInteger(
+                R.integer.recents_task_enter_from_app_duration);
+        int taskViewEnterFromHomeDuration = res.getInteger(
+                R.integer.recents_task_enter_from_home_duration);
+        int taskViewEnterFromHomeStaggerDelay = res.getInteger(
+                R.integer.recents_task_enter_from_home_stagger_delay);
+
+        // Create enter animations for each of the views from front to back
+        List<TaskView> taskViews = mStackView.getTaskViews();
+        int taskViewCount = taskViews.size();
+        for (int i = taskViewCount - 1; i >= 0; i--) {
+            TaskView tv = taskViews.get(i);
+            Task task = tv.getTask();
+            boolean currentTaskOccludesLaunchTarget = false;
+            if (launchTargetTask != null) {
+                currentTaskOccludesLaunchTarget = launchTargetTask.group.isTaskAboveTask(task,
+                        launchTargetTask);
+            }
+
+            // Get the current transform for the task, which will be updated to the final transform
+            // to animate to depending on how recents was invoked
+            stackLayout.getStackTransform(task, stackScroller.getStackScroll(), mTmpTransform,
+                    null);
+
+            if (launchState.launchedFromAppWithThumbnail) {
+                if (task.isLaunchTarget) {
+                    tv.onStartLaunchTargetEnterAnimation(taskViewEnterFromAppDuration,
+                            mStackView.mScreenPinningEnabled, postAnimationTrigger);
+                } else {
+                    // Animate the task up if it was occluding the launch target
+                    if (currentTaskOccludesLaunchTarget) {
+                        TaskViewAnimation taskAnimation = new TaskViewAnimation(
+                                taskViewEnterFromAppDuration, PhoneStatusBar.ALPHA_IN,
+                                postAnimationTrigger.decrementOnAnimationEnd());
+                        postAnimationTrigger.increment();
+                        mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation);
+                    }
+                }
+
+            } else if (launchState.launchedFromHome) {
+                // Animate the tasks up
+                int frontIndex = (taskViewCount - i - 1);
+                int delay = frontIndex * taskViewEnterFromHomeStaggerDelay;
+                int duration = taskViewEnterFromHomeDuration +
+                        frontIndex * taskViewEnterFromHomeStaggerDelay;
+
+                TaskViewAnimation taskAnimation = new TaskViewAnimation(delay,
+                        duration, mQuintOutInterpolator,
+                        postAnimationTrigger.decrementOnAnimationEnd());
+                postAnimationTrigger.increment();
+                mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation);
+            }
+        }
+    }
+
+    /**
+     * Starts an in-app animation to hide all the task views so that we can transition back home.
+     */
+    public void startExitToHomeAnimation(boolean animated,
+            ReferenceCountedTrigger postAnimationTrigger) {
+        Resources res = mStackView.getResources();
+        TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
+        TaskStackViewScroller stackScroller = mStackView.getScroller();
+        TaskStack stack = mStackView.getStack();
+
+        // Break early if there are no tasks
+        if (stack.getStackTaskCount() == 0) {
+            return;
+        }
+
+        int offscreenY = stackLayout.mStackRect.bottom;
+        int taskViewExitToHomeDuration = res.getInteger(
+                R.integer.recents_task_exit_to_home_duration);
+
+        // Create the animations for each of the tasks
+        List<TaskView> taskViews = mStackView.getTaskViews();
+        int taskViewCount = taskViews.size();
+        for (int i = 0; i < taskViewCount; i++) {
+            TaskView tv = taskViews.get(i);
+            Task task = tv.getTask();
+            TaskViewAnimation taskAnimation = new TaskViewAnimation(
+                    animated ? taskViewExitToHomeDuration : 0, mFastOutLinearInInterpolator,
+                    postAnimationTrigger.decrementOnAnimationEnd());
+            postAnimationTrigger.increment();
+
+            stackLayout.getStackTransform(task, stackScroller.getStackScroll(), mTmpTransform,
+                    null);
+            mTmpTransform.rect.offset(0, offscreenY);
+            mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation);
+        }
+    }
+
+    /**
+     * Starts the animation for the launching task view, hiding any tasks that might occlude the
+     * window transition for the launching task.
+     */
+    public void startLaunchTaskAnimation(TaskView launchingTaskView, boolean screenPinningRequested,
+            final ReferenceCountedTrigger postAnimationTrigger) {
+        Resources res = mStackView.getResources();
+        TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
+        TaskStackViewScroller stackScroller = mStackView.getScroller();
+
+        int taskViewExitToAppDuration = res.getInteger(
+                R.integer.recents_task_exit_to_app_duration);
+        int taskViewAffiliateGroupEnterOffset = res.getDimensionPixelSize(
+                R.dimen.recents_task_view_affiliate_group_enter_offset);
+
+        Task launchingTask = launchingTaskView.getTask();
+        List<TaskView> taskViews = mStackView.getTaskViews();
+        int taskViewCount = taskViews.size();
+        for (int i = 0; i < taskViewCount; i++) {
+            TaskView tv = taskViews.get(i);
+            Task task = tv.getTask();
+            boolean currentTaskOccludesLaunchTarget = (launchingTask != null &&
+                    launchingTask.group.isTaskAboveTask(task, launchingTask));
+
+            if (tv == launchingTaskView) {
+                tv.setClipViewInStack(false);
+                tv.onStartLaunchTargetLaunchAnimation(taskViewExitToAppDuration,
+                        screenPinningRequested, postAnimationTrigger);
+            } else if (currentTaskOccludesLaunchTarget) {
+                // Animate this task out of view
+                TaskViewAnimation taskAnimation = new TaskViewAnimation(
+                        taskViewExitToAppDuration, mFastOutLinearInInterpolator,
+                        postAnimationTrigger.decrementOnAnimationEnd());
+                postAnimationTrigger.increment();
+
+                stackLayout.getStackTransform(task, stackScroller.getStackScroll(), mTmpTransform,
+                        null);
+                mTmpTransform.alpha = 0f;
+                mTmpTransform.rect.offset(0, taskViewAffiliateGroupEnterOffset);
+                mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation);
+            }
+        }
+    }
+
+    /**
+     * Starts the delete animation for the specified {@link TaskView}.
+     */
+    public void startDeleteTaskAnimation(Task deleteTask, final TaskView deleteTaskView,
+            final ReferenceCountedTrigger postAnimationTrigger) {
+        Resources res = mStackView.getResources();
+        TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
+        TaskStackViewScroller stackScroller = mStackView.getScroller();
+
+        int taskViewRemoveAnimDuration = res.getInteger(
+                R.integer.recents_animate_task_view_remove_duration);
+        int taskViewRemoveAnimTranslationXPx = res.getDimensionPixelSize(
+                R.dimen.recents_task_view_remove_anim_translation_x);
+
+        // Disabling clipping with the stack while the view is animating away
+        deleteTaskView.setClipViewInStack(false);
+
+        // Compose the new animation and transform and star the animation
+        TaskViewAnimation taskAnimation = new TaskViewAnimation(taskViewRemoveAnimDuration,
+                PhoneStatusBar.ALPHA_OUT, new AnimatorListenerAdapter() {
+            @Override
+            public void onAnimationEnd(Animator animation) {
+                postAnimationTrigger.decrement();
+
+                // Re-enable clipping with the stack (we will reuse this view)
+                deleteTaskView.setClipViewInStack(true);
+            }
+        });
+        postAnimationTrigger.increment();
+
+        stackLayout.getStackTransform(deleteTask, stackScroller.getStackScroll(), mTmpTransform,
+                null);
+        mTmpTransform.alpha = 0f;
+        mTmpTransform.rect.offset(taskViewRemoveAnimTranslationXPx, 0);
+        mStackView.updateTaskViewToTransform(deleteTaskView, mTmpTransform, taskAnimation);
+    }
+
+    /**
+     * Starts the animation to hide the {@link TaskView}s when the history is shown.  The history
+     * view's animation will be deferred until all the {@link TaskView}s are finished animating.
+     */
+    public void startShowHistoryAnimation(ReferenceCountedTrigger postAnimationTrigger) {
+        Resources res = mStackView.getResources();
+        TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
+        TaskStackViewScroller stackScroller = mStackView.getScroller();
+
+        int historyTransitionDuration = res.getInteger(
+                R.integer.recents_history_transition_duration);
+
+        List<TaskView> taskViews = mStackView.getTaskViews();
+        int taskViewCount = taskViews.size();
+        for (int i = taskViewCount - 1; i >= 0; i--) {
+            TaskView tv = taskViews.get(i);
+            Task task = tv.getTask();
+            TaskViewAnimation taskAnimation = new TaskViewAnimation(
+                    historyTransitionDuration, PhoneStatusBar.ALPHA_OUT,
+                    postAnimationTrigger.decrementOnAnimationEnd());
+            postAnimationTrigger.increment();
+
+            stackLayout.getStackTransform(task, stackScroller.getStackScroll(), mTmpTransform,
+                    null);
+            mTmpTransform.alpha = 0f;
+            mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation);
+        }
+    }
+
+    /**
+     * Starts the animation to show the {@link TaskView}s when the history is hidden.  The
+     * {@link TaskView} animations will be deferred until the history view has been animated away.
+     */
+    public void startHideHistoryAnimation(final ReferenceCountedTrigger postAnimationTrigger) {
+        final Resources res = mStackView.getResources();
+        final TaskStackLayoutAlgorithm stackLayout = mStackView.getStackAlgorithm();
+        final TaskStackViewScroller stackScroller = mStackView.getScroller();
+
+        final int historyTransitionDuration = res.getInteger(
+                R.integer.recents_history_transition_duration);
+
+        List<TaskView> taskViews = mStackView.getTaskViews();
+        int taskViewCount = taskViews.size();
+        for (int i = taskViewCount - 1; i >= 0; i--) {
+            final TaskView tv = taskViews.get(i);
+            postAnimationTrigger.addLastDecrementRunnable(new Runnable() {
+                @Override
+                public void run() {
+                    TaskViewAnimation taskAnimation = new TaskViewAnimation(
+                            historyTransitionDuration, PhoneStatusBar.ALPHA_IN);
+                    stackLayout.getStackTransform(tv.getTask(), stackScroller.getStackScroll(),
+                            mTmpTransform, null);
+                    mTmpTransform.alpha = 1f;
+                    mStackView.updateTaskViewToTransform(tv, mTmpTransform, taskAnimation);
+                }
+            });
+        }
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java
index 10df156..1ee22e9 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java
@@ -22,7 +22,6 @@
 import android.graphics.Path;
 import android.graphics.Rect;
 import android.util.FloatProperty;
-import android.util.Log;
 import android.util.Property;
 import android.view.animation.AnimationUtils;
 import android.view.animation.Interpolator;
@@ -103,9 +102,6 @@
  */
 public class TaskStackLayoutAlgorithm {
 
-    private static final String TAG = "TaskStackViewLayoutAlgorithm";
-    private static final boolean DEBUG = false;
-
     // The scale factor to apply to the user movement in the stack to unfocus it
     private static final float UNFOCUS_MULTIPLIER = 0.8f;
 
@@ -130,7 +126,7 @@
          *                          allocate to the freeform workspace
          * @param freeformBackgroundAlpha the background alpha for the freeform workspace
          */
-        StackState(float freeformHeightPct, int freeformBackgroundAlpha) {
+        private StackState(float freeformHeightPct, int freeformBackgroundAlpha) {
             this.freeformHeightPct = freeformHeightPct;
             this.freeformBackgroundAlpha = freeformBackgroundAlpha;
         }
@@ -212,7 +208,6 @@
     }
 
     Context mContext;
-    private TaskStackView mStackView;
     private Interpolator mLinearOutSlowInInterpolator;
     private StackState mState = StackState.SPLIT;
 
@@ -280,9 +275,12 @@
     // The freeform workspace layout
     FreeformWorkspaceLayoutAlgorithm mFreeformLayoutAlgorithm;
 
-    public TaskStackLayoutAlgorithm(Context context, TaskStackView stackView) {
+    // The transform to place TaskViews at the front and back of the stack respectively
+    TaskViewTransform mBackOfStackTransform = new TaskViewTransform();
+    TaskViewTransform mFrontOfStackTransform = new TaskViewTransform();
+
+    public TaskStackLayoutAlgorithm(Context context) {
         Resources res = context.getResources();
-        mStackView = stackView;
 
         mFocusedRange = new Range(res.getFloat(R.integer.recents_layout_focused_range_min),
                 res.getFloat(R.integer.recents_layout_focused_range_max));
@@ -318,7 +316,7 @@
      */
     public void setFocusState(float focusState) {
         mFocusState = focusState;
-        mStackView.requestSynchronizeStackViewsWithModel();
+        updateFrontBackTransforms();
     }
 
     /**
@@ -333,7 +331,6 @@
      * including the search bar.
      */
     public void initialize(Rect taskStackBounds, StackState state) {
-        RecentsDebugFlags debugFlags = Recents.getDebugFlags();
         RecentsConfiguration config = Recents.getConfiguration();
         int widthPadding = (int) (config.taskStackWidthPaddingPct * taskStackBounds.width());
         int heightPadding = mContext.getResources().getDimensionPixelSize(
@@ -369,14 +366,7 @@
         mUnfocusedCurveInterpolator = new FreePathInterpolator(mUnfocusedCurve);
         mFocusedCurve = constructFocusedCurve();
         mFocusedCurveInterpolator = new FreePathInterpolator(mFocusedCurve);
-
-        if (DEBUG) {
-            Log.d(TAG, "initialize");
-            Log.d(TAG, "\tmFreeformRect: " + mFreeformRect);
-            Log.d(TAG, "\tmStackRect: " + mStackRect);
-            Log.d(TAG, "\tmTaskRect: " + mTaskRect);
-            Log.d(TAG, "\tmSystemInsets: " + mSystemInsets);
-        }
+        updateFrontBackTransforms();
     }
 
     /**
@@ -456,13 +446,6 @@
                 mInitialScrollP = (mNumStackTasks - 1) - mUnfocusedRange.getAbsoluteX(normX);
             }
         }
-
-        if (DEBUG) {
-            Log.d(TAG, "mNumStackTasks: " + mNumStackTasks);
-            Log.d(TAG, "mNumFreeformTasks: " + mNumFreeformTasks);
-            Log.d(TAG, "mMinScrollP: " + mMinScrollP);
-            Log.d(TAG, "mMaxScrollP: " + mMaxScrollP);
-        }
     }
 
     /**
@@ -472,7 +455,7 @@
         Utilities.cancelAnimationWithoutCallbacks(mFocusStateAnimator);
         if (mFocusState > STATE_UNFOCUSED) {
             float delta = (float) yMovement / (UNFOCUS_MULTIPLIER * mStackRect.height());
-            mFocusState -= Math.min(mFocusState, Math.abs(delta));
+            setFocusState(mFocusState - Math.min(mFocusState, Math.abs(delta)));
         }
     }
 
@@ -498,27 +481,23 @@
         RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
         RecentsDebugFlags debugFlags = Recents.getDebugFlags();
         if (launchState.launchedWithAltTab || debugFlags.isInitialStatePaging()) {
-            return 1f;
+            return STATE_FOCUSED;
         }
-        return 0f;
+        return STATE_UNFOCUSED;
     }
 
     /**
-     * Returns the task progress that would put the task just off the back of the stack.
+     * Returns the TaskViewTransform that would put the task just off the back of the stack.
      */
-    public float getStackBackTaskProgress(float stackScroll) {
-        float min = mUnfocusedRange.relativeMin +
-                mFocusState * (mFocusedRange.relativeMin - mUnfocusedRange.relativeMin);
-        return stackScroll + min;
+    public TaskViewTransform getBackOfStackTransform() {
+        return mBackOfStackTransform;
     }
 
     /**
-     * Returns the task progress that would put the task just off the front of the stack.
+     * Returns the TaskViewTransform that would put the task just off the front of the stack.
      */
-    public float getStackFrontTaskProgress(float stackScroll) {
-        float max = mUnfocusedRange.relativeMax +
-                mFocusState * (mFocusedRange.relativeMax - mUnfocusedRange.relativeMax);
-        return stackScroll + max;
+    public TaskViewTransform getFrontOfStackTransform() {
+        return mFrontOfStackTransform;
     }
 
     /**
@@ -618,9 +597,6 @@
             if (task.thumbnail != null) {
                 transformOut.thumbnailScale = (float) mTaskRect.width() / task.thumbnail.getWidth();
             }
-            if (DEBUG) {
-                Log.d(TAG, "getTransform: " + task.key + ", " + transformOut);
-            }
             return transformOut;
         }
     }
@@ -770,4 +746,18 @@
         p.cubicTo(0.5f, 1f - peekHeightPct, cpoint2X, cpoint2Y, 1f, 0f);
         return p;
     }
+
+    /**
+     * Updates the current transforms that would put a TaskView at the front and back of the stack.
+     */
+    private void updateFrontBackTransforms() {
+        float min = mUnfocusedRange.relativeMin +
+                mFocusState * (mFocusedRange.relativeMin - mUnfocusedRange.relativeMin);
+        float max = mUnfocusedRange.relativeMax +
+                mFocusState * (mFocusedRange.relativeMax - mUnfocusedRange.relativeMax);
+        getStackTransform(min, 0f, mBackOfStackTransform, null);
+        getStackTransform(max, 0f, mFrontOfStackTransform, null);
+        mBackOfStackTransform.visible = true;
+        mFrontOfStackTransform.visible = true;
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
index 830d607..9568fac 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java
@@ -23,13 +23,12 @@
 import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.Rect;
-import android.graphics.RectF;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.GradientDrawable;
 import android.os.Bundle;
 import android.os.Parcelable;
+import android.provider.Settings;
 import android.util.IntProperty;
-import android.util.Log;
 import android.util.Property;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
@@ -46,19 +45,22 @@
 import com.android.systemui.recents.RecentsConfiguration;
 import com.android.systemui.recents.events.EventBus;
 import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent;
+import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
 import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent;
 import com.android.systemui.recents.events.activity.HideHistoryButtonEvent;
 import com.android.systemui.recents.events.activity.HideHistoryEvent;
 import com.android.systemui.recents.events.activity.IterateRecentsEvent;
 import com.android.systemui.recents.events.activity.LaunchTaskEvent;
+import com.android.systemui.recents.events.activity.LaunchTaskStartedEvent;
 import com.android.systemui.recents.events.activity.PackagesChangedEvent;
 import com.android.systemui.recents.events.activity.ShowHistoryButtonEvent;
 import com.android.systemui.recents.events.activity.ShowHistoryEvent;
 import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent;
 import com.android.systemui.recents.events.ui.AllTaskViewsDismissedEvent;
-import com.android.systemui.recents.events.ui.DismissTaskEvent;
+import com.android.systemui.recents.events.ui.DeleteTaskDataEvent;
 import com.android.systemui.recents.events.ui.DismissTaskViewEvent;
 import com.android.systemui.recents.events.ui.StackViewScrolledEvent;
+import com.android.systemui.recents.events.ui.TaskViewDismissedEvent;
 import com.android.systemui.recents.events.ui.UpdateFreeformTaskViewVisibilityEvent;
 import com.android.systemui.recents.events.ui.UserInteractionEvent;
 import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent;
@@ -75,7 +77,6 @@
 import com.android.systemui.recents.model.TaskStack;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -90,9 +91,6 @@
         TaskView.TaskViewCallbacks, TaskStackViewScroller.TaskStackViewScrollerCallbacks,
         ViewPool.ViewPoolConsumer<TaskView, Task> {
 
-    private final static String TAG = "TaskStackView";
-    private final static boolean DEBUG = false;
-
     private final static String KEY_SAVED_STATE_SUPER = "saved_instance_state_super";
     private final static String KEY_SAVED_STATE_LAYOUT_FOCUSED_STATE =
             "saved_instance_state_layout_focused_state";
@@ -104,6 +102,8 @@
     private static final float HIDE_HISTORY_BUTTON_SCROLL_THRESHOLD = 0.3f;
 
     private static final int DEFAULT_SYNC_STACK_DURATION = 200;
+    private static final int DRAG_SCALE_DURATION = 175;
+    private static final float DRAG_SCALE_FACTOR = 1.05f;
 
     public static final Property<Drawable, Integer> DRAWABLE_ALPHA =
             new IntProperty<Drawable>("drawableAlpha") {
@@ -122,34 +122,33 @@
     TaskStackLayoutAlgorithm mLayoutAlgorithm;
     TaskStackViewScroller mStackScroller;
     TaskStackViewTouchHandler mTouchHandler;
+    TaskStackAnimationHelper mAnimationHelper;
     GradientDrawable mFreeformWorkspaceBackground;
     ObjectAnimator mFreeformWorkspaceBackgroundAnimator;
     ViewPool<TaskView, Task> mViewPool;
+
+    ArrayList<TaskView> mTaskViews = new ArrayList<>();
     ArrayList<TaskViewTransform> mCurrentTaskTransforms = new ArrayList<>();
+    TaskViewAnimation mDeferredTaskViewUpdateAnimation = null;
+
     DozeTrigger mUIDozeTrigger;
     Task mFocusedTask;
-    // Optimizations
-    int mStackViewsAnimationDuration;
+
     int mTaskCornerRadiusPx;
-    boolean mStackViewsDirty = true;
-    boolean mStackViewsClipDirty = true;
+
+    boolean mTaskViewsClipDirty = true;
     boolean mAwaitingFirstLayout = true;
     boolean mEnterAnimationComplete = false;
-    boolean mStartEnterAnimationRequestedAfterLayout;
-    ViewAnimation.TaskViewEnterContext mStartEnterAnimationContext;
+    boolean mTouchExplorationEnabled;
+    boolean mScreenPinningEnabled;
 
     Rect mTaskStackBounds = new Rect();
     int[] mTmpVisibleRange = new int[2];
     Rect mTmpRect = new Rect();
-    RectF mTmpTaskRect = new RectF();
-    TaskViewTransform mTmpStackBackTransform = new TaskViewTransform();
-    TaskViewTransform mTmpStackFrontTransform = new TaskViewTransform();
     HashMap<Task, TaskView> mTmpTaskViewMap = new HashMap<>();
-    ArrayList<TaskView> mTaskViews = new ArrayList<>();
-    List<TaskView> mImmutableTaskViews = new ArrayList<>();
     List<TaskView> mTmpTaskViews = new ArrayList<>();
+    TaskViewTransform mTmpTransform = new TaskViewTransform();
     LayoutInflater mInflater;
-    boolean mTouchExplorationEnabled;
 
     Interpolator mFastOutSlowInInterpolator;
 
@@ -158,7 +157,8 @@
             new ValueAnimator.AnimatorUpdateListener() {
                 @Override
                 public void onAnimationUpdate(ValueAnimator animation) {
-                    requestUpdateStackViewsClip();
+                    mTaskViewsClipDirty = true;
+                    invalidate();
                 }
             };
 
@@ -186,10 +186,11 @@
         setStack(stack);
         mViewPool = new ViewPool<>(context, this);
         mInflater = LayoutInflater.from(context);
-        mLayoutAlgorithm = new TaskStackLayoutAlgorithm(context, this);
+        mLayoutAlgorithm = new TaskStackLayoutAlgorithm(context);
         mStackScroller = new TaskStackViewScroller(context, mLayoutAlgorithm);
         mStackScroller.setCallbacks(this);
         mTouchHandler = new TaskStackViewTouchHandler(context, this, mStackScroller);
+        mAnimationHelper = new TaskStackAnimationHelper(context, this);
         mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
                 com.android.internal.R.interpolator.fast_out_slow_in);
         mTaskCornerRadiusPx = res.getDimensionPixelSize(
@@ -224,6 +225,8 @@
     protected void onAttachedToWindow() {
         SystemServicesProxy ssp = Recents.getSystemServices();
         mTouchExplorationEnabled = ssp.isTouchExplorationEnabled();
+        mScreenPinningEnabled = ssp.getSystemSetting(getContext(),
+                Settings.System.LOCK_TO_APP_ENABLED) != 0;
         EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1);
         super.onAttachedToWindow();
     }
@@ -260,12 +263,11 @@
                 mTaskViews.add((TaskView) v);
             }
         }
-        mImmutableTaskViews = Collections.unmodifiableList(mTaskViews);
     }
 
     /** Gets the list of task views */
     List<TaskView> getTaskViews() {
-        return mImmutableTaskViews;
+        return mTaskViews;
     }
 
     /**
@@ -324,44 +326,16 @@
 
         // Reset the stack state
         mStack.reset();
-        mStackViewsDirty = true;
-        mStackViewsClipDirty = true;
+        mTaskViewsClipDirty = true;
         mAwaitingFirstLayout = true;
         mEnterAnimationComplete = false;
-        if (mUIDozeTrigger != null) {
-            mUIDozeTrigger.stopDozing();
-            mUIDozeTrigger.resetTrigger();
-        }
+        mUIDozeTrigger.stopDozing();
+        mUIDozeTrigger.resetTrigger();
         mStackScroller.reset();
         mLayoutAlgorithm.reset();
         requestLayout();
     }
 
-    /** Requests that the views be synchronized with the model */
-    void requestSynchronizeStackViewsWithModel() {
-        requestSynchronizeStackViewsWithModel(0);
-    }
-    void requestSynchronizeStackViewsWithModel(int duration) {
-        if (!mStackViewsDirty) {
-            invalidate();
-            mStackViewsDirty = true;
-        }
-        if (mAwaitingFirstLayout) {
-            // Skip the animation if we are awaiting first layout
-            mStackViewsAnimationDuration = 0;
-        } else {
-            mStackViewsAnimationDuration = Math.max(mStackViewsAnimationDuration, duration);
-        }
-    }
-
-    /** Requests that the views clipping be updated. */
-    void requestUpdateStackViewsClip() {
-        if (!mStackViewsClipDirty) {
-            invalidate();
-            mStackViewsClipDirty = true;
-        }
-    }
-
     /** Returns the stack algorithm for this task stack. */
     public TaskStackLayoutAlgorithm getStackAlgorithm() {
         return mLayoutAlgorithm;
@@ -395,15 +369,15 @@
         TaskViewTransform frontTransform = null;
         for (int i = taskCount - 1; i >= 0; i--) {
             Task task = tasks.get(i);
+            TaskViewTransform transform = mLayoutAlgorithm.getStackTransform(task, stackScroll,
+                    taskTransforms.get(i), frontTransform);
+
+            // For freeform tasks, only calculate the stack transform and skip the calculation of
+            // the visible stack indices
             if (task.isFreeformTask()) {
                 continue;
             }
 
-            TaskViewTransform transform = mLayoutAlgorithm.getStackTransform(task, stackScroll,
-                    taskTransforms.get(i), frontTransform);
-            if (DEBUG) {
-                Log.d(TAG, "updateStackTransform: " + i + ", " + transform.visible);
-            }
             if (transform.visible) {
                 if (frontMostVisibleIndex < 0) {
                     frontMostVisibleIndex = i;
@@ -429,144 +403,155 @@
         return frontMostVisibleIndex != -1 && backMostVisibleIndex != -1;
     }
 
-    /** Synchronizes the views with the model */
-    boolean synchronizeStackViewsWithModel() {
-        if (mStackViewsDirty) {
-            // Get all the task transforms
-            ArrayList<Task> tasks = mStack.getStackTasks();
-            float stackScroll = mStackScroller.getStackScroll();
-            int[] visibleStackRange = mTmpVisibleRange;
-            boolean isValidVisibleStackRange = updateStackTransforms(mCurrentTaskTransforms, tasks,
-                    stackScroll, visibleStackRange);
-            boolean hasStackBackTransform = false;
-            boolean hasStackFrontTransform = false;
-            if (DEBUG) {
-                Log.d(TAG, "visibleRange: " + visibleStackRange[0] + " to " + visibleStackRange[1]);
-            }
+    /**
+     * Updates the children {@link TaskView}s to match the tasks in the current {@link TaskStack}.
+     * This call does not update the {@link TaskView}s to their position in the layout except when
+     * they are initially picked up from the pool, when they will be placed in a suitable initial
+     * position.
+     */
+    private void bindTaskViewsWithStack() {
+        final float stackScroll = mStackScroller.getStackScroll();
+        final int[] visibleStackRange = mTmpVisibleRange;
 
-            // Return all the invisible children to the pool
-            mTmpTaskViewMap.clear();
-            List<TaskView> taskViews = getTaskViews();
-            int lastFocusedTaskIndex = -1;
-            int taskViewCount = taskViews.size();
-            for (int i = taskViewCount - 1; i >= 0; i--) {
-                TaskView tv = taskViews.get(i);
-                Task task = tv.getTask();
-                int taskIndex = mStack.indexOfStackTask(task);
-                if (task.isFreeformTask() ||
-                        visibleStackRange[1] <= taskIndex && taskIndex <= visibleStackRange[0]) {
-                    mTmpTaskViewMap.put(task, tv);
-                } else {
-                    if (mTouchExplorationEnabled) {
-                        lastFocusedTaskIndex = taskIndex;
-                        resetFocusedTask(task);
-                    }
-                    if (DEBUG) {
-                        Log.d(TAG, "returning to pool: " + task.key);
-                    }
-                    mViewPool.returnViewToPool(tv);
+        // Get all the task transforms
+        final ArrayList<Task> tasks = mStack.getStackTasks();
+        final boolean isValidVisibleStackRange = updateStackTransforms(mCurrentTaskTransforms, tasks,
+                stackScroll, visibleStackRange);
+
+        // Return all the invisible children to the pool
+        mTmpTaskViewMap.clear();
+        final List<TaskView> taskViews = getTaskViews();
+        final int taskViewCount = taskViews.size();
+        int lastFocusedTaskIndex = -1;
+        for (int i = taskViewCount - 1; i >= 0; i--) {
+            final TaskView tv = taskViews.get(i);
+            final Task task = tv.getTask();
+            final int taskIndex = mStack.indexOfStackTask(task);
+
+            if (task.isFreeformTask() ||
+                    visibleStackRange[1] <= taskIndex && taskIndex <= visibleStackRange[0]) {
+                mTmpTaskViewMap.put(task, tv);
+            } else {
+                if (mTouchExplorationEnabled) {
+                    lastFocusedTaskIndex = taskIndex;
+                    resetFocusedTask(task);
                 }
+                mViewPool.returnViewToPool(tv);
             }
-
-            // Pick up all the freeform tasks
-            int firstVisStackIndex = isValidVisibleStackRange ? visibleStackRange[0] : 0;
-            for (int i = mStack.getStackTaskCount() - 1; i >= firstVisStackIndex; i--) {
-                Task task = tasks.get(i);
-                if (!task.isFreeformTask()) {
-                    continue;
-                }
-                TaskViewTransform transform = mLayoutAlgorithm.getStackTransform(task, stackScroll,
-                        mCurrentTaskTransforms.get(i), null);
-                TaskView tv = mTmpTaskViewMap.get(task);
-                if (tv == null) {
-                    if (DEBUG) {
-                        Log.d(TAG, "picking up from pool: " + task.key);
-                    }
-                    tv = mViewPool.pickUpViewFromPool(task, task);
-                } else {
-                    // Reattach it in the right z order
-                    int taskIndex = mStack.indexOfStackTask(task);
-                    int insertIndex = findTaskViewInsertIndex(task, taskIndex);
-                    if (insertIndex != getTaskViews().indexOf(tv)){
-                        detachViewFromParent(tv);
-                        attachViewToParent(tv, insertIndex, tv.getLayoutParams());
-                    }
-                }
-
-                // Animate the task into place
-                tv.updateViewPropertiesToTaskTransform(transform, 0,
-                        mStackViewsAnimationDuration, mFastOutSlowInInterpolator,
-                        mRequestUpdateClippingListener);
-
-                // Update the task views list after adding the new task view
-                updateTaskViewsList();
-            }
-
-            // Pick up all the newly visible children and update all the existing children
-            for (int i = visibleStackRange[0];
-                    isValidVisibleStackRange && i >= visibleStackRange[1]; i--) {
-                Task task = tasks.get(i);
-                TaskViewTransform transform = mCurrentTaskTransforms.get(i);
-                TaskView tv = mTmpTaskViewMap.get(task);
-
-                if (tv == null) {
-                    tv = mViewPool.pickUpViewFromPool(task, task);
-                    if (mStackViewsAnimationDuration > 0) {
-                        // For items in the list, put them in start animating them from the
-                        // approriate ends of the list where they are expected to appear
-                        if (Float.compare(transform.p, 0f) <= 0) {
-                            if (!hasStackBackTransform) {
-                                hasStackBackTransform = true;
-                                mLayoutAlgorithm.getStackTransform(
-                                        mLayoutAlgorithm.getStackBackTaskProgress(0f), 0f,
-                                        mTmpStackBackTransform, null);
-                            }
-                            tv.updateViewPropertiesToTaskTransform(mTmpStackBackTransform, 0, 0,
-                                    mFastOutSlowInInterpolator, mRequestUpdateClippingListener);
-                        } else {
-                            if (!hasStackFrontTransform) {
-                                hasStackFrontTransform = true;
-                                mLayoutAlgorithm.getStackTransform(
-                                        mLayoutAlgorithm.getStackFrontTaskProgress(0f), 0f,
-                                        mTmpStackFrontTransform, null);
-                            }
-                            tv.updateViewPropertiesToTaskTransform(mTmpStackFrontTransform, 0, 0,
-                                    mFastOutSlowInInterpolator, mRequestUpdateClippingListener);
-                        }
-                    }
-                }
-
-                // Animate the task into place, the clip for stack tasks will be calculated in
-                // clipTaskViews()
-                tv.updateViewPropertiesToTaskTransform(transform,
-                        tv.getViewBounds().getClipBottom(), mStackViewsAnimationDuration,
-                        mFastOutSlowInInterpolator, mRequestUpdateClippingListener);
-            }
-
-            // Update the focus if the previous focused task was returned to the view pool
-            if (lastFocusedTaskIndex != -1) {
-                if (lastFocusedTaskIndex < visibleStackRange[1]) {
-                    setFocusedTask(visibleStackRange[1], false /* animated */,
-                            true /* requestViewFocus */);
-                } else {
-                    setFocusedTask(visibleStackRange[0], false /* animated */,
-                            true /* requestViewFocus */);
-                }
-            }
-
-            // Reset the request-synchronize params
-            mStackViewsAnimationDuration = 0;
-            mStackViewsDirty = false;
-            mStackViewsClipDirty = true;
-            return true;
         }
-        return false;
+
+        // Pick up all the newly visible children
+        int lastVisStackIndex = isValidVisibleStackRange ? visibleStackRange[1] : 0;
+        for (int i = mStack.getStackTaskCount() - 1; i >= lastVisStackIndex; i--) {
+            final Task task = tasks.get(i);
+            final TaskViewTransform transform = mCurrentTaskTransforms.get(i);
+
+            // Skip the invisible non-freeform stack tasks
+            if (i > visibleStackRange[0] && !task.isFreeformTask()) {
+                continue;
+            }
+
+            TaskView tv = mTmpTaskViewMap.get(task);
+            if (tv == null) {
+                tv = mViewPool.pickUpViewFromPool(task, task);
+                if (task.isFreeformTask()) {
+                    tv.updateViewPropertiesToTaskTransform(transform, TaskViewAnimation.IMMEDIATE,
+                            mRequestUpdateClippingListener);
+                } else {
+                    if (Float.compare(transform.p, 0f) <= 0) {
+                        tv.updateViewPropertiesToTaskTransform(
+                                mLayoutAlgorithm.getBackOfStackTransform(),
+                                TaskViewAnimation.IMMEDIATE, mRequestUpdateClippingListener);
+                    } else {
+                        tv.updateViewPropertiesToTaskTransform(
+                                mLayoutAlgorithm.getFrontOfStackTransform(),
+                                TaskViewAnimation.IMMEDIATE, mRequestUpdateClippingListener);
+                    }
+                }
+            } else {
+                // Reattach it in the right z order
+                final int taskIndex = mStack.indexOfStackTask(task);
+                final int insertIndex = findTaskViewInsertIndex(task, taskIndex);
+                if (insertIndex != getTaskViews().indexOf(tv)){
+                    detachViewFromParent(tv);
+                    attachViewToParent(tv, insertIndex, tv.getLayoutParams());
+                    updateTaskViewsList();
+                }
+            }
+        }
+
+        // Update the focus if the previous focused task was returned to the view pool
+        if (lastFocusedTaskIndex != -1) {
+            if (lastFocusedTaskIndex < visibleStackRange[1]) {
+                setFocusedTask(visibleStackRange[1], false /* scrollToTask */,
+                        true /* requestViewFocus */);
+            } else {
+                setFocusedTask(visibleStackRange[0], false /* scrollToTask */,
+                        true /* requestViewFocus */);
+            }
+        }
+    }
+
+    /**
+     * Cancels any existing {@link TaskView} animations, and updates each {@link TaskView} to its
+     * current position as defined by the {@link TaskStackLayoutAlgorithm}.
+     */
+    private void updateTaskViewsToLayout(TaskViewAnimation animation) {
+        // If we had a deferred animation, cancel that
+        mDeferredTaskViewUpdateAnimation = null;
+
+        // Cancel all task view animations
+        cancelAllTaskViewAnimations();
+
+        // Fetch the current set of TaskViews
+        bindTaskViewsWithStack();
+
+        // Animate them to their final transforms with the given animation
+        List<TaskView> taskViews = getTaskViews();
+        int taskViewCount = taskViews.size();
+        for (int i = 0; i < taskViewCount; i++) {
+            final TaskView tv = taskViews.get(i);
+            final int taskIndex = mStack.indexOfStackTask(tv.getTask());
+            final TaskViewTransform transform = mCurrentTaskTransforms.get(taskIndex);
+
+            updateTaskViewToTransform(tv, transform, animation);
+        }
+    }
+
+    /**
+     * Posts an update to synchronize the {@link TaskView}s with the stack on the next frame.
+     */
+    private void updateTaskViewsToLayoutOnNextFrame(TaskViewAnimation animation) {
+        mDeferredTaskViewUpdateAnimation = animation;
+        postInvalidateOnAnimation();
+    }
+
+    /**
+     * Called to update a specific {@link TaskView} to a given {@link TaskViewTransform} with a
+     * given set of {@link TaskViewAnimation} properties.
+     */
+    public void updateTaskViewToTransform(TaskView taskView, TaskViewTransform transform,
+            TaskViewAnimation animation) {
+        taskView.updateViewPropertiesToTaskTransform(transform, animation,
+                mRequestUpdateClippingListener);
+    }
+
+    /**
+     * Cancels all {@link TaskView} animations.
+     */
+    private void cancelAllTaskViewAnimations() {
+        List<TaskView> taskViews = getTaskViews();
+        int taskViewCount = taskViews.size();
+        for (int i = 0; i < taskViewCount; i++) {
+            final TaskView tv = taskViews.get(i);
+            tv.cancelTransformAnimation();
+        }
     }
 
     /**
      * Updates the clip for each of the task views from back to front.
      */
-    void clipTaskViews(boolean forceUpdate) {
+    private void clipTaskViews() {
         RecentsConfiguration config = Recents.getConfiguration();
 
         // Update the clip on each task child
@@ -581,6 +566,7 @@
                 // Find the next view to clip against
                 for (int j = i + 1; j < taskViewCount; j++) {
                     tmpTv = taskViews.get(j);
+
                     if (tmpTv.shouldClipViewInStack()) {
                         frontTv = tmpTv;
                         break;
@@ -599,12 +585,12 @@
                     }
                 }
             }
-            tv.getViewBounds().setClipBottom(clipBottom, forceUpdate);
+            tv.getViewBounds().setClipBottom(clipBottom);
             if (!config.useHardwareLayers) {
                 tv.mThumbnailView.updateThumbnailVisibility(clipBottom - tv.getPaddingBottom());
             }
         }
-        mStackViewsClipDirty = false;
+        mTaskViewsClipDirty = false;
     }
 
     /** Updates the min and max virtual scroll bounds */
@@ -635,16 +621,7 @@
      *
      * @return whether or not the stack will scroll as a part of this focus change
      */
-    private boolean setFocusedTask(int taskIndex, boolean scrollToTask, final boolean animated) {
-        return setFocusedTask(taskIndex, scrollToTask, animated, true);
-    }
-
-    /**
-     * Sets the focused task to the provided (bounded taskIndex).
-     *
-     * @return whether or not the stack will scroll as a part of this focus change
-     */
-    private boolean setFocusedTask(int taskIndex, boolean scrollToTask, final boolean animated,
+    private boolean setFocusedTask(int taskIndex, boolean scrollToTask,
             final boolean requestViewFocus) {
         // Find the next task to focus
         int newFocusedTaskIndex = mStack.getStackTaskCount() > 0 ?
@@ -665,7 +642,7 @@
                 public void run() {
                     TaskView tv = getChildViewForTask(newFocusedTask);
                     if (tv != null) {
-                        tv.setFocusedState(true, animated, requestViewFocus);
+                        tv.setFocusedState(true, requestViewFocus);
                     }
                 }
             };
@@ -680,10 +657,7 @@
 
                     // Cancel any running enter animations at this point when we scroll as well
                     if (!mEnterAnimationComplete) {
-                        final List<TaskView> taskViews = getTaskViews();
-                        for (TaskView tv : taskViews) {
-                            tv.cancelEnterRecentsAnimation();
-                        }
+                        cancelAllTaskViewAnimations();
                     }
                 } else {
                     focusTaskRunnable.run();
@@ -758,7 +732,8 @@
             }
         }
         if (newIndex != -1) {
-            boolean willScroll = setFocusedTask(newIndex, true, animated);
+            boolean willScroll = setFocusedTask(newIndex, true /* scrollToTask */,
+                    true /* requestViewFocus */);
             if (willScroll && cancelWindowAnimations) {
                 // As we iterate to the next/previous task, cancel any current/lagging window
                 // transition animations
@@ -774,7 +749,7 @@
         if (task != null) {
             TaskView tv = getChildViewForTask(task);
             if (tv != null) {
-                tv.setFocusedState(false, false /* animated */, false /* requestViewFocus */);
+                tv.setFocusedState(false, false /* requestViewFocus */);
             }
         }
         mFocusedTask = null;
@@ -879,12 +854,18 @@
 
     @Override
     public void computeScroll() {
-        mStackScroller.computeScroll();
-        // Synchronize the views
-        synchronizeStackViewsWithModel();
-        clipTaskViews(false /* forceUpdate */);
-        // Notify accessibility
-        sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED);
+        if (mStackScroller.computeScroll()) {
+            // Notify accessibility
+            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED);
+        }
+        if (mDeferredTaskViewUpdateAnimation != null) {
+            updateTaskViewsToLayout(mDeferredTaskViewUpdateAnimation);
+            mTaskViewsClipDirty = true;
+            mDeferredTaskViewUpdateAnimation = null;
+        }
+        if (mTaskViewsClipDirty) {
+            clipTaskViews();
+        }
     }
 
     /** Computes the stack and task rects */
@@ -931,13 +912,12 @@
         // Compute our stack/task rects
         computeRects(mTaskStackBounds);
 
-        // If this is the first layout, then scroll to the front of the stack and synchronize the
-        // stack views immediately to load all the views
+        // If this is the first layout, then scroll to the front of the stack, then update the
+        // TaskViews with the stack so that we can lay them out
         if (mAwaitingFirstLayout) {
             mStackScroller.setStackScrollToInitialState();
-            requestSynchronizeStackViewsWithModel();
-            synchronizeStackViewsWithModel();
         }
+        bindTaskViewsWithStack();
 
         // Measure each of the TaskViews
         mTmpTaskViews.clear();
@@ -987,53 +967,25 @@
                     taskRect.right + mTmpRect.right, taskRect.bottom + mTmpRect.bottom);
         }
 
-        if (mAwaitingFirstLayout) {
-            mAwaitingFirstLayout = false;
-            onFirstLayout();
-        }
-
-        requestSynchronizeStackViewsWithModel();
         if (changed) {
             if (mStackScroller.isScrollOutOfBounds()) {
                 mStackScroller.boundScroll();
             }
-            synchronizeStackViewsWithModel();
-            requestUpdateStackViewsClip();
-            clipTaskViews(true /* forceUpdate */);
+        }
+        updateTaskViewsToLayout(TaskViewAnimation.IMMEDIATE);
+        clipTaskViews();
+
+        if (mAwaitingFirstLayout || !mEnterAnimationComplete) {
+            mAwaitingFirstLayout = false;
+            onFirstLayout();
+            return;
         }
     }
 
     /** Handler for the first layout. */
     void onFirstLayout() {
-        int offscreenY = mLayoutAlgorithm.mStackRect.bottom;
-
-        // Find the launch target task
-        Task launchTargetTask = mStack.getLaunchTarget();
-        List<TaskView> taskViews = getTaskViews();
-        int taskViewCount = taskViews.size();
-
-        // Prepare the first view for its enter animation
-        for (int i = taskViewCount - 1; i >= 0; i--) {
-            TaskView tv = taskViews.get(i);
-            Task task = tv.getTask();
-            boolean hideTask = false;
-            boolean occludesLaunchTarget = false;
-            if (launchTargetTask != null) {
-                occludesLaunchTarget = launchTargetTask.group.isTaskAboveTask(task,
-                        launchTargetTask);
-                hideTask = launchTargetTask.isFreeformTask() && task.isFreeformTask();
-            }
-            tv.prepareEnterRecentsAnimation(task.isLaunchTarget, hideTask, occludesLaunchTarget,
-                    offscreenY);
-        }
-
-        // If the enter animation started already and we haven't completed a layout yet, do the
-        // enter animation now
-        if (mStartEnterAnimationRequestedAfterLayout) {
-            startEnterRecentsAnimation(mStartEnterAnimationContext);
-            mStartEnterAnimationRequestedAfterLayout = false;
-            mStartEnterAnimationContext = null;
-        }
+        // Setup the view for the enter animation
+        mAnimationHelper.prepareForEnterAnimation();
 
         // Animate in the freeform workspace
         animateFreeformWorkspaceBackgroundAlpha(
@@ -1046,7 +998,7 @@
         RecentsActivityLaunchState launchState = config.getLaunchState();
         int focusedTaskIndex = launchState.getInitialFocusTaskIndex(mStack.getStackTaskCount());
         if (focusedTaskIndex != -1) {
-            setFocusedTask(focusedTaskIndex, false /* scrollToTask */, false /* animated */,
+            setFocusedTask(focusedTaskIndex, false /* scrollToTask */,
                     false /* requestViewFocus */);
         }
 
@@ -1057,101 +1009,6 @@
         } else {
             EventBus.getDefault().send(new HideHistoryButtonEvent());
         }
-
-        // Start dozing
-        mUIDozeTrigger.startDozing();
-    }
-
-    /** Requests this task stacks to start it's enter-recents animation */
-    public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) {
-        // If we are still waiting to layout, then just defer until then
-        if (mAwaitingFirstLayout) {
-            mStartEnterAnimationRequestedAfterLayout = true;
-            mStartEnterAnimationContext = ctx;
-            return;
-        }
-
-        if (mStack.getStackTaskCount() > 0) {
-            // Find the launch target task
-            Task launchTargetTask = mStack.getLaunchTarget();
-            List<TaskView> taskViews = getTaskViews();
-            int taskViewCount = taskViews.size();
-
-            // Animate all the task views into view
-            for (int i = taskViewCount - 1; i >= 0; i--) {
-                TaskView tv = taskViews.get(i);
-                Task task = tv.getTask();
-                ctx.currentTaskTransform = new TaskViewTransform();
-                ctx.currentStackViewIndex = i;
-                ctx.currentStackViewCount = taskViewCount;
-                ctx.currentTaskRect = mLayoutAlgorithm.mTaskRect;
-                ctx.currentTaskOccludesLaunchTarget = (launchTargetTask != null) &&
-                        launchTargetTask.group.isTaskAboveTask(task, launchTargetTask);
-                ctx.updateListener = mRequestUpdateClippingListener;
-                mLayoutAlgorithm.getStackTransform(task, mStackScroller.getStackScroll(),
-                        ctx.currentTaskTransform, null);
-                tv.startEnterRecentsAnimation(ctx);
-            }
-
-            // Add a runnable to the post animation ref counter to clear all the views
-            ctx.postAnimationTrigger.addLastDecrementRunnable(new Runnable() {
-                @Override
-                public void run() {
-                    // Poke the dozer to restart the trigger after the animation completes
-                    mUIDozeTrigger.poke();
-
-                    // Update the focused state here -- since we only set the focused task without
-                    // requesting view focus in onFirstLayout(), actually request view focus and
-                    // animate the focused state if we are alt-tabbing now, after the window enter
-                    // animation is completed
-                    if (mFocusedTask != null) {
-                        RecentsConfiguration config = Recents.getConfiguration();
-                        RecentsActivityLaunchState launchState = config.getLaunchState();
-                        setFocusedTask(mStack.indexOfStackTask(mFocusedTask),
-                                false /* scrollToTask */, launchState.launchedWithAltTab);
-                    }
-                }
-            });
-        }
-    }
-
-    /** Requests this task stack to start it's exit-recents animation. */
-    public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) {
-        // Stop any scrolling
-        mStackScroller.stopScroller();
-        mStackScroller.stopBoundScrollAnimation();
-        // Animate all the task views out of view
-        ctx.offscreenTranslationY = mLayoutAlgorithm.mStackRect.bottom;
-        // Dismiss the freeform workspace background
-        int taskViewExitToHomeDuration = getResources().getInteger(
-                R.integer.recents_task_exit_to_home_duration);
-        animateFreeformWorkspaceBackgroundAlpha(0, taskViewExitToHomeDuration,
-                mFastOutSlowInInterpolator);
-
-        List<TaskView> taskViews = getTaskViews();
-        int taskViewCount = taskViews.size();
-        for (int i = 0; i < taskViewCount; i++) {
-            TaskView tv = taskViews.get(i);
-            tv.startExitToHomeAnimation(ctx);
-        }
-    }
-
-    /** Animates a task view in this stack as it launches. */
-    public void startLaunchTaskAnimation(TaskView tv, Runnable r, boolean lockToTask) {
-        Task launchTargetTask = tv.getTask();
-        List<TaskView> taskViews = getTaskViews();
-        int taskViewCount = taskViews.size();
-        for (int i = 0; i < taskViewCount; i++) {
-            TaskView t = taskViews.get(i);
-            if (t == tv) {
-                t.setClipViewInStack(false);
-                t.startLaunchTaskAnimation(r, true, true, lockToTask);
-            } else {
-                boolean occludesLaunchTarget = launchTargetTask.group.isTaskAboveTask(t.getTask(),
-                        launchTargetTask);
-                t.startLaunchTaskAnimation(null, false, occludesLaunchTarget, lockToTask);
-            }
-        }
     }
 
     public boolean isTransformedTouchPointInView(float x, float y, TaskView tv) {
@@ -1189,11 +1046,14 @@
      * Launches the freeform tasks.
      */
     public boolean launchFreeformTasks() {
-        Task frontTask = mStack.getStackFrontMostTask();
-        if (frontTask != null && frontTask.isFreeformTask()) {
-            EventBus.getDefault().send(new LaunchTaskEvent(getChildViewForTask(frontTask),
-                    frontTask, null, INVALID_STACK_ID, false));
-            return true;
+        ArrayList<Task> tasks = mStack.getFreeformTasks();
+        if (!tasks.isEmpty()) {
+            Task frontTask = tasks.get(tasks.size() - 1);
+            if (frontTask != null && frontTask.isFreeformTask()) {
+                EventBus.getDefault().send(new LaunchTaskEvent(getChildViewForTask(frontTask),
+                        frontTask, null, INVALID_STACK_ID, false));
+                return true;
+            }
         }
         return false;
     }
@@ -1206,7 +1066,8 @@
         updateLayout(true);
 
         // Animate all the tasks into place
-        requestSynchronizeStackViewsWithModel(DEFAULT_SYNC_STACK_DURATION);
+        updateTaskViewsToLayout(new TaskViewAnimation(DEFAULT_SYNC_STACK_DURATION,
+                mFastOutSlowInInterpolator));
     }
 
     @Override
@@ -1253,9 +1114,6 @@
                 mStackScroller.setStackScroll(mStackScroller.getStackScroll() + stackScrollOffset);
                 mStackScroller.boundScroll();
             }
-
-            // Animate all the tasks into place
-            requestSynchronizeStackViewsWithModel(DEFAULT_SYNC_STACK_DURATION);
         } else {
             // Remove the view associated with this task, we can't rely on updateTransforms
             // to work here because the task is no longer in the list
@@ -1266,18 +1124,17 @@
 
             // Update the min/max scroll and animate other task views into their new positions
             updateLayout(true);
-
-            // Animate all the tasks into place
-            requestSynchronizeStackViewsWithModel(DEFAULT_SYNC_STACK_DURATION);
         }
 
-        // Update the new front most task
-        if (newFrontMostTask != null) {
+        // Animate all the tasks into place
+        updateTaskViewsToLayout(new TaskViewAnimation(DEFAULT_SYNC_STACK_DURATION,
+                mFastOutSlowInInterpolator));
+
+        // Update the new front most task's action button
+        if (mScreenPinningEnabled && newFrontMostTask != null) {
             TaskView frontTv = getChildViewForTask(newFrontMostTask);
             if (frontTv != null) {
-                frontTv.onTaskBound(newFrontMostTask);
-                frontTv.fadeInActionButton(getResources().getInteger(
-                        R.integer.recents_task_enter_from_app_duration));
+                frontTv.showActionButton(true /* fadeIn */, DEFAULT_SYNC_STACK_DURATION);
             }
         }
 
@@ -1304,7 +1161,7 @@
 
     @Override
     public void prepareViewToEnterPool(TaskView tv) {
-        Task task = tv.getTask();
+        final Task task = tv.getTask();
 
         // Report that this tasks's data is no longer being used
         Recents.getTaskLoader().unloadTaskData(task);
@@ -1314,22 +1171,17 @@
         // Update the task views list after removing the task view
         updateTaskViewsList();
 
-        // Reset the view properties
+        // Reset the view properties and view state
         tv.resetViewProperties();
-
-        // Reset the focused view state
-        tv.setFocusedState(false, false /* animated */, false /* requestViewFocus */);
-
-        // Reset the clip state of the task view
+        tv.setFocusedState(false, false /* requestViewFocus */);
         tv.setClipViewInStack(false);
+        if (mScreenPinningEnabled) {
+            tv.hideActionButton(false /* fadeOut */, 0 /* duration */, false /* scaleDown */, null);
+        }
     }
 
     @Override
     public void prepareViewToLeavePool(TaskView tv, Task task, boolean isNewView) {
-        // It is possible for a view to be returned to the view pool before it is laid out,
-        // which means that we will need to relayout the view when it is first used next.
-        boolean requiresRelayout = tv.getWidth() <= 0 && !isNewView;
-
         // Rebind the task and request that this task's data be filled into the TaskView
         tv.onTaskBound(task);
 
@@ -1348,9 +1200,6 @@
             addView(tv, insertIndex);
         } else {
             attachViewToParent(tv, insertIndex, tv.getLayoutParams());
-            if (requiresRelayout) {
-                tv.requestLayout();
-            }
         }
         // Update the task views list after adding the new task view
         updateTaskViewsList();
@@ -1360,7 +1209,12 @@
         tv.setTouchEnabled(true);
         tv.setClipViewInStack(true);
         if (mFocusedTask == task) {
-            tv.setFocusedState(true, false /* animated */, false /* requestViewFocus */);
+            tv.setFocusedState(true, false /* requestViewFocus */);
+        }
+
+        // Restore the action button visibility if it is the front most task view
+        if (mScreenPinningEnabled && tv.getTask() == mStack.getStackFrontMostTask()) {
+            tv.showActionButton(false /* fadeIn */, 0 /* fadeInDuration */);
         }
     }
 
@@ -1373,16 +1227,15 @@
 
     @Override
     public void onTaskViewClipStateChanged(TaskView tv) {
-        requestUpdateStackViewsClip();
+        clipTaskViews();
     }
 
     /**** TaskStackViewScroller.TaskStackViewScrollerCallbacks ****/
 
     @Override
-    public void onScrollChanged(float prevScroll, float curScroll) {
+    public void onScrollChanged(float prevScroll, float curScroll, TaskViewAnimation animation) {
         mUIDozeTrigger.poke();
-        requestSynchronizeStackViewsWithModel();
-        postInvalidateOnAnimation();
+        updateTaskViewsToLayoutOnNextFrame(animation);
 
         if (shouldShowHistoryButton() &&
                 prevScroll > SHOW_HISTORY_BUTTON_SCROLL_THRESHOLD &&
@@ -1409,12 +1262,7 @@
                 final TaskView tv = getChildViewForTask(t);
                 if (tv != null) {
                     // For visible children, defer removing the task until after the animation
-                    tv.startDeleteTaskAnimation(new Runnable() {
-                        @Override
-                        public void run() {
-                            removeTaskViewFromStack(tv);
-                        }
-                    }, 0);
+                    tv.dismissTask();
                 } else {
                     // Otherwise, remove the task from the stack immediately
                     mStack.removeTask(t);
@@ -1428,17 +1276,24 @@
         mUIDozeTrigger.stopDozing();
     }
 
-    public final void onBusEvent(DismissTaskViewEvent event) {
-        removeTaskViewFromStack(event.taskView);
-        EventBus.getDefault().send(new DismissTaskEvent(event.task));
+    public final void onBusEvent(LaunchTaskStartedEvent event) {
+        mAnimationHelper.startLaunchTaskAnimation(event.taskView, event.screenPinningRequested,
+                event.getAnimationTrigger());
     }
 
-    public final void onBusEvent(FocusNextTaskViewEvent event) {
-        setRelativeFocusedTask(true, false /* stackTasksOnly */, true /* animated */);
-    }
+    public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) {
+        // Stop any scrolling
+        mStackScroller.stopScroller();
+        mStackScroller.stopBoundScrollAnimation();
 
-    public final void onBusEvent(FocusPreviousTaskViewEvent event) {
-        setRelativeFocusedTask(false, false /* stackTasksOnly */, true /* animated */);
+        // Start the task animations
+        mAnimationHelper.startExitToHomeAnimation(event.animated, event.getAnimationTrigger());
+
+        // Dismiss the freeform workspace background
+        int taskViewExitToHomeDuration = getResources().getInteger(
+                R.integer.recents_task_exit_to_home_duration);
+        animateFreeformWorkspaceBackgroundAlpha(0, taskViewExitToHomeDuration,
+                mFastOutSlowInInterpolator);
     }
 
     public final void onBusEvent(DismissFocusedTaskViewEvent event) {
@@ -1451,6 +1306,25 @@
         }
     }
 
+    public final void onBusEvent(final DismissTaskViewEvent event) {
+        // For visible children, defer removing the task until after the animation
+        mAnimationHelper.startDeleteTaskAnimation(event.task, event.taskView,
+                event.getAnimationTrigger());
+    }
+
+    public final void onBusEvent(TaskViewDismissedEvent event) {
+        removeTaskViewFromStack(event.taskView);
+        EventBus.getDefault().send(new DeleteTaskDataEvent(event.task));
+    }
+
+    public final void onBusEvent(FocusNextTaskViewEvent event) {
+        setRelativeFocusedTask(true, false /* stackTasksOnly */, true /* animated */);
+    }
+
+    public final void onBusEvent(FocusPreviousTaskViewEvent event) {
+        setRelativeFocusedTask(false, false /* stackTasksOnly */, true /* animated */);
+    }
+
     public final void onBusEvent(UserInteractionEvent event) {
         // Poke the doze trigger on user interaction
         mUIDozeTrigger.poke();
@@ -1468,6 +1342,14 @@
             mStackScroller.animateScroll(mStackScroller.getStackScroll(),
                     mLayoutAlgorithm.mInitialScrollP, null);
         }
+
+        // Enlarge the dragged view slightly
+        float finalScale = event.taskView.getScaleX() * DRAG_SCALE_FACTOR;
+        mLayoutAlgorithm.getStackTransform(event.task, getScroller().getStackScroll(),
+                mTmpTransform, null);
+        mTmpTransform.scale = finalScale;
+        updateTaskViewToTransform(event.taskView, mTmpTransform,
+                new TaskViewAnimation(DRAG_SCALE_DURATION, mFastOutSlowInInterpolator));
     }
 
     public final void onBusEvent(DragStartInitializeDropTargetsEvent event) {
@@ -1513,8 +1395,6 @@
                 }
             });
         }
-        event.getAnimationTrigger().increment();
-        event.taskView.animate().withEndAction(event.getAnimationTrigger().decrementAsRunnable());
 
         // We translated the view but we need to animate it back from the current layout-space rect
         // to its final layout-space rect
@@ -1528,8 +1408,15 @@
         event.taskView.setLeftTopRightBottom(taskViewRect.left, taskViewRect.top,
                 taskViewRect.right, taskViewRect.bottom);
 
-        // Animate the tack view back into position
-        requestSynchronizeStackViewsWithModel(250);
+        // Animate all the TaskViews back into position
+        mLayoutAlgorithm.getStackTransform(event.task, getScroller().getStackScroll(),
+                mTmpTransform, null);
+        event.getAnimationTrigger().increment();
+        updateTaskViewsToLayout(new TaskViewAnimation(DEFAULT_SYNC_STACK_DURATION,
+                mFastOutSlowInInterpolator));
+        updateTaskViewToTransform(event.taskView, mTmpTransform,
+                new TaskViewAnimation(DEFAULT_SYNC_STACK_DURATION, mFastOutSlowInInterpolator,
+                        event.getAnimationTrigger().decrementOnAnimationEnd()));
     }
 
     public final void onBusEvent(StackViewScrolledEvent event) {
@@ -1541,11 +1428,35 @@
             // Cancel the previous task's window transition before animating the focused state
             EventBus.getDefault().send(new CancelEnterRecentsWindowAnimationEvent(null));
         }
-        mLayoutAlgorithm.animateFocusState(mLayoutAlgorithm.getDefaultFocusState());
     }
 
     public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) {
         mEnterAnimationComplete = true;
+
+        if (mStack.getStackTaskCount() > 0) {
+            // Start the task enter animations
+            mAnimationHelper.startEnterAnimation(event.getAnimationTrigger());
+
+            // Add a runnable to the post animation ref counter to clear all the views
+            event.addPostAnimationCallback(new Runnable() {
+                @Override
+                public void run() {
+                    // Start the dozer to trigger to trigger any UI that shows after a timeout
+                    mUIDozeTrigger.startDozing();
+
+                    // Update the focused state here -- since we only set the focused task without
+                    // requesting view focus in onFirstLayout(), actually request view focus and
+                    // animate the focused state if we are alt-tabbing now, after the window enter
+                    // animation is completed
+                    if (mFocusedTask != null) {
+                        RecentsConfiguration config = Recents.getConfiguration();
+                        RecentsActivityLaunchState launchState = config.getLaunchState();
+                        setFocusedTask(mStack.indexOfStackTask(mFocusedTask),
+                                false /* scrollToTask */, launchState.launchedWithAltTab);
+                    }
+                }
+            });
+        }
     }
 
     public final void onBusEvent(UpdateFreeformTaskViewVisibilityEvent event) {
@@ -1561,48 +1472,11 @@
     }
 
     public final void onBusEvent(ShowHistoryEvent event) {
-        // The history view's animation will be deferred until all the stack task views are animated
-        // away
-        int historyTransitionDuration =
-                getResources().getInteger(R.integer.recents_history_transition_duration);
-        List<TaskView> taskViews = getTaskViews();
-        int taskViewCount = taskViews.size();
-        for (int i = taskViewCount - 1; i >= 0; i--) {
-            TaskView tv = taskViews.get(i);
-            tv.animate()
-                    .alpha(0f)
-                    .setDuration(historyTransitionDuration)
-                    .setUpdateListener(null)
-                    .setListener(null)
-                    .withLayer()
-                    .withEndAction(event.getAnimationTrigger().decrementAsRunnable())
-                    .start();
-            event.getAnimationTrigger().increment();
-        }
+        mAnimationHelper.startShowHistoryAnimation(event.getAnimationTrigger());
     }
 
     public final void onBusEvent(HideHistoryEvent event) {
-        // The stack task view animations will be deferred until the history view has been animated
-        // away
-        final int historyTransitionDuration =
-                getResources().getInteger(R.integer.recents_history_transition_duration);
-        List<TaskView> taskViews = getTaskViews();
-        int taskViewCount = taskViews.size();
-        for (int i = taskViewCount - 1; i >= 0; i--) {
-            final TaskView tv = taskViews.get(i);
-            event.addPostAnimationCallback(new Runnable() {
-                @Override
-                public void run() {
-                    tv.animate()
-                            .alpha(1f)
-                            .setDuration(historyTransitionDuration)
-                            .setUpdateListener(null)
-                            .setListener(null)
-                            .withLayer()
-                            .start();
-                }
-            });
-        }
+        mAnimationHelper.startHideHistoryAnimation(event.getAnimationTrigger());
     }
 
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewScroller.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewScroller.java
index 56942a8..32f02ac 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewScroller.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewScroller.java
@@ -34,7 +34,7 @@
     private static final boolean DEBUG = false;
 
     public interface TaskStackViewScrollerCallbacks {
-        void onScrollChanged(float prevScroll, float curScroll);
+        void onScrollChanged(float prevScroll, float curScroll, TaskViewAnimation animation);
     }
 
     Context mContext;
@@ -57,7 +57,6 @@
         mLayoutAlgorithm = layoutAlgorithm;
         mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
                 com.android.internal.R.interpolator.linear_out_slow_in);
-        setStackScroll(getStackScroll());
     }
 
     /** Resets the task scroller. */
@@ -75,12 +74,22 @@
         return mStackScrollP;
     }
 
-    /** Sets the current stack scroll */
+    /**
+     * Sets the current stack scroll immediately.
+     */
     public void setStackScroll(float s) {
+        setStackScroll(s, TaskViewAnimation.IMMEDIATE);
+    }
+
+    /**
+     * Sets the current stack scroll, but indicates to the callback the preferred animation to
+     * update to this new scroll.
+     */
+    public void setStackScroll(float s, TaskViewAnimation animation) {
         float prevStackScroll = mStackScrollP;
         mStackScrollP = s;
         if (mCb != null) {
-            mCb.onScrollChanged(prevStackScroll, mStackScrollP);
+            mCb.onScrollChanged(prevStackScroll, mStackScrollP, animation);
         }
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java
index 1a6f129..c748efc 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackViewTouchHandler.java
@@ -33,8 +33,8 @@
 import com.android.systemui.recents.Recents;
 import com.android.systemui.recents.events.EventBus;
 import com.android.systemui.recents.events.activity.HideRecentsEvent;
-import com.android.systemui.recents.events.ui.DismissTaskViewEvent;
 import com.android.systemui.recents.events.ui.StackViewScrolledEvent;
+import com.android.systemui.recents.events.ui.TaskViewDismissedEvent;
 import com.android.systemui.recents.misc.SystemServicesProxy;
 import com.android.systemui.recents.misc.Utilities;
 import com.android.systemui.statusbar.FlingAnimationUtils;
@@ -295,6 +295,7 @@
             Rect freeformRect = mSv.mLayoutAlgorithm.mFreeformRect;
             if (freeformRect.top <= y && y <= freeformRect.bottom) {
                 if (mSv.launchFreeformTasks()) {
+                    // TODO: Animate Recents away as we launch the freeform tasks
                     return;
                 }
             }
@@ -367,7 +368,7 @@
         // Re-enable touch events from this task view
         tv.setTouchEnabled(true);
         // Remove the task view from the stack
-        EventBus.getDefault().send(new DismissTaskViewEvent(tv.getTask(), tv));
+        EventBus.getDefault().send(new TaskViewDismissedEvent(tv.getTask(), tv));
         // Keep track of deletions by keyboard
         MetricsLogger.histogram(tv.getContext(), "overview_task_dismissed_source",
                 Constants.Metrics.DismissSourceSwipeGesture);
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java
index a3e8b2d..e8652f5 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java
@@ -31,7 +31,9 @@
 import android.graphics.PorterDuffColorFilter;
 import android.graphics.Rect;
 import android.util.AttributeSet;
-import android.util.Log;
+import android.util.FloatProperty;
+import android.util.IntProperty;
+import android.util.Property;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewOutlineProvider;
@@ -42,35 +44,64 @@
 import com.android.systemui.R;
 import com.android.systemui.recents.Recents;
 import com.android.systemui.recents.RecentsActivity;
-import com.android.systemui.recents.RecentsActivityLaunchState;
 import com.android.systemui.recents.RecentsConfiguration;
 import com.android.systemui.recents.events.EventBus;
 import com.android.systemui.recents.events.activity.LaunchTaskEvent;
 import com.android.systemui.recents.events.ui.DismissTaskViewEvent;
+import com.android.systemui.recents.events.ui.TaskViewDismissedEvent;
 import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent;
 import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent;
+import com.android.systemui.recents.misc.ReferenceCountedTrigger;
 import com.android.systemui.recents.misc.SystemServicesProxy;
 import com.android.systemui.recents.misc.Utilities;
 import com.android.systemui.recents.model.Task;
 import com.android.systemui.recents.model.TaskStack;
 import com.android.systemui.statusbar.phone.PhoneStatusBar;
 
+import java.util.ArrayList;
+
 import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
 
 /* A task view */
 public class TaskView extends FrameLayout implements Task.TaskCallbacks,
-        View.OnClickListener, View.OnLongClickListener {
-
-    private final static String TAG = "TaskView";
-    private final static boolean DEBUG = false;
+        TaskStackAnimationHelper.Callbacks, View.OnClickListener, View.OnLongClickListener {
 
     /** The TaskView callbacks */
     interface TaskViewCallbacks {
         void onTaskViewClipStateChanged(TaskView tv);
     }
 
+    /**
+     * The dim overlay is generally calculated from the task progress, but occasionally (like when
+     * launching) needs to be animated independently of the task progress.
+     */
+    public static final Property<TaskView, Integer> DIM =
+            new IntProperty<TaskView>("dim") {
+                @Override
+                public void setValue(TaskView tv, int dim) {
+                    tv.setDim(dim);
+                }
+
+                @Override
+                public Integer get(TaskView tv) {
+                    return tv.getDim();
+                }
+            };
+
+    public static final Property<TaskView, Float> TASK_PROGRESS =
+            new FloatProperty<TaskView>("taskProgress") {
+                @Override
+                public void setValue(TaskView tv, float p) {
+                    tv.setTaskProgress(p);
+                }
+
+                @Override
+                public Float get(TaskView tv) {
+                    return tv.getTaskProgress();
+                }
+            };
+
     float mTaskProgress;
-    ObjectAnimator mTaskProgressAnimator;
     float mMaxDimScale;
     int mDimAlpha;
     AccelerateInterpolator mDimInterpolator = new AccelerateInterpolator(3f);
@@ -80,9 +111,11 @@
 
     Task mTask;
     boolean mTaskDataLoaded;
-    boolean mClipViewInStack;
+    boolean mClipViewInStack = true;
     AnimateableViewBounds mViewBounds;
-    private AnimatorSet mClipAnimation;
+
+    private AnimatorSet mTransformAnimation;
+    private ArrayList<Animator> mTmpAnimators = new ArrayList<>();
 
     View mContent;
     TaskViewThumbnail mThumbnailView;
@@ -93,18 +126,6 @@
     Point mDownTouchPos = new Point();
 
     Interpolator mFastOutSlowInInterpolator;
-    Interpolator mFastOutLinearInInterpolator;
-    Interpolator mQuintOutInterpolator;
-
-    // Optimizations
-    ValueAnimator.AnimatorUpdateListener mUpdateDimListener =
-            new ValueAnimator.AnimatorUpdateListener() {
-                @Override
-                public void onAnimationUpdate(ValueAnimator animation) {
-                    setTaskProgress((Float) animation.getAnimatedValue());
-                }
-            };
-
 
     public TaskView(Context context) {
         this(context, null);
@@ -123,21 +144,15 @@
         RecentsConfiguration config = Recents.getConfiguration();
         Resources res = context.getResources();
         mMaxDimScale = res.getInteger(R.integer.recents_max_task_stack_view_dim) / 255f;
-        mClipViewInStack = true;
         mViewBounds = new AnimateableViewBounds(this, res.getDimensionPixelSize(
                 R.dimen.recents_task_view_rounded_corners_radius));
         mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
                 com.android.internal.R.interpolator.fast_out_slow_in);
-        mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
-                com.android.internal.R.interpolator.fast_out_linear_in);
-        mQuintOutInterpolator = AnimationUtils.loadInterpolator(context,
-                com.android.internal.R.interpolator.decelerate_quint);
-        setTaskProgress(getTaskProgress());
-        setDim(getDim());
         if (config.fakeShadows) {
             setBackground(new FakeShadowDrawable(res, config));
         }
         setOutlineProvider(mViewBounds);
+        setOnLongClickListener(this);
     }
 
     /** Set callback */
@@ -175,8 +190,10 @@
             public void getOutline(View view, Outline outline) {
                 // Set the outline to match the FAB background
                 outline.setOval(0, 0, mActionButtonView.getWidth(), mActionButtonView.getHeight());
+                outline.setAlpha(0.35f);
             }
         });
+        mActionButtonView.setOnClickListener(this);
         mActionButtonTranslationZ = mActionButtonView.getTranslationZ();
     }
 
@@ -224,300 +241,69 @@
         invalidateOutline();
     }
 
-    /** Synchronizes this view's properties with the task's transform */
-    void updateViewPropertiesToTaskTransform(TaskViewTransform toTransform, int clipBottom,
-            int duration, Interpolator interpolator,
-            ValueAnimator.AnimatorUpdateListener updateCallback) {
+    void updateViewPropertiesToTaskTransform(TaskViewTransform toTransform,
+            TaskViewAnimation toAnimation, ValueAnimator.AnimatorUpdateListener updateCallback) {
         RecentsConfiguration config = Recents.getConfiguration();
-        Utilities.cancelAnimationWithoutCallbacks(mClipAnimation);
+        Utilities.cancelAnimation(mTransformAnimation);
 
-        // Apply the transform
-        toTransform.applyToTaskView(this, duration, interpolator, false,
-                !config.fakeShadows, updateCallback);
-
-        // Update the clipping
-        if (duration > 0) {
-            mClipAnimation = new AnimatorSet();
-            mClipAnimation.playTogether(
-                    ObjectAnimator.ofInt(mViewBounds, AnimateableViewBounds.CLIP_BOTTOM,
-                            mViewBounds.getClipBottom(), clipBottom),
-                    ObjectAnimator.ofInt(this, TaskViewTransform.LEFT, getLeft(),
-                            (int) toTransform.rect.left),
-                    ObjectAnimator.ofInt(this, TaskViewTransform.TOP, getTop(),
-                            (int) toTransform.rect.top),
-                    ObjectAnimator.ofInt(this, TaskViewTransform.RIGHT, getRight(),
-                            (int) toTransform.rect.right),
-                    ObjectAnimator.ofInt(this, TaskViewTransform.BOTTOM, getBottom(),
-                            (int) toTransform.rect.bottom),
-                    ObjectAnimator.ofFloat(mThumbnailView, TaskViewThumbnail.BITMAP_SCALE,
-                            mThumbnailView.getBitmapScale(), toTransform.thumbnailScale));
-            mClipAnimation.setStartDelay(toTransform.startDelay);
-            mClipAnimation.setDuration(duration);
-            mClipAnimation.setInterpolator(interpolator);
-            mClipAnimation.start();
-        } else {
-            mViewBounds.setClipBottom(clipBottom, false /* forceUpdate */);
+        // Compose the animations for the transform
+        mTmpAnimators.clear();
+        boolean requiresHwLayers = toTransform.applyToTaskView(this, mTmpAnimators, toAnimation,
+                !config.fakeShadows);
+        if (toAnimation.isImmediate()) {
             mThumbnailView.setBitmapScale(toTransform.thumbnailScale);
-            setLeftTopRightBottom((int) toTransform.rect.left, (int) toTransform.rect.top,
-                    (int) toTransform.rect.right, (int) toTransform.rect.bottom);
-        }
-        if (!config.useHardwareLayers) {
-            mThumbnailView.updateThumbnailVisibility(clipBottom - getPaddingBottom());
-        }
-
-        // Update the task progress
-        Utilities.cancelAnimationWithoutCallbacks(mTaskProgressAnimator);
-        if (duration <= 0) {
             setTaskProgress(toTransform.p);
+            if (toAnimation.listener != null) {
+                toAnimation.listener.onAnimationEnd(null);
+            }
         } else {
-            mTaskProgressAnimator = ObjectAnimator.ofFloat(this, "taskProgress", toTransform.p);
-            mTaskProgressAnimator.setDuration(duration);
-            mTaskProgressAnimator.addUpdateListener(mUpdateDimListener);
-            mTaskProgressAnimator.start();
+            if (Float.compare(mThumbnailView.getBitmapScale(), toTransform.thumbnailScale) != 0) {
+                mTmpAnimators.add(ObjectAnimator.ofFloat(mThumbnailView,
+                        TaskViewThumbnail.BITMAP_SCALE, mThumbnailView.getBitmapScale(),
+                        toTransform.thumbnailScale));
+            }
+            if (Float.compare(getTaskProgress(), toTransform.p) != 0) {
+                mTmpAnimators.add(ObjectAnimator.ofFloat(this, TASK_PROGRESS, getTaskProgress(),
+                        toTransform.p));
+            }
+            ValueAnimator updateCallbackAnim = ValueAnimator.ofInt(0, 1);
+            updateCallbackAnim.addUpdateListener(updateCallback);
+            mTmpAnimators.add(updateCallbackAnim);
+
+            // Create the animator
+            mTransformAnimation = toAnimation.createAnimator(mTmpAnimators);
+            if (requiresHwLayers) {
+                setLayerType(View.LAYER_TYPE_HARDWARE, null);
+                mTransformAnimation.addListener(new AnimatorListenerAdapter() {
+                    @Override
+                    public void onAnimationEnd(Animator animation) {
+                        setLayerType(View.LAYER_TYPE_NONE, null);
+                    }
+                });
+            }
+            mTransformAnimation.start();
         }
     }
 
     /** Resets this view's properties */
     void resetViewProperties() {
+        Utilities.cancelAnimation(mTransformAnimation);
         setDim(0);
         setVisibility(View.VISIBLE);
         getViewBounds().reset();
         TaskViewTransform.reset(this);
-        if (mActionButtonView != null) {
-            mActionButtonView.setScaleX(1f);
-            mActionButtonView.setScaleY(1f);
-            mActionButtonView.setAlpha(1f);
-            mActionButtonView.setTranslationZ(mActionButtonTranslationZ);
-        }
+
+        mActionButtonView.setScaleX(1f);
+        mActionButtonView.setScaleY(1f);
+        mActionButtonView.setAlpha(1f);
+        mActionButtonView.setTranslationZ(mActionButtonTranslationZ);
     }
 
-    /** Prepares this task view for the enter-recents animations.  This is called earlier in the
-     * first layout because the actual animation into recents may take a long time. */
-    void prepareEnterRecentsAnimation(boolean isTaskViewLaunchTargetTask, boolean hideTask,
-            boolean occludesLaunchTarget, int offscreenY) {
-        RecentsConfiguration config = Recents.getConfiguration();
-        RecentsActivityLaunchState launchState = config.getLaunchState();
-        int initialDim = getDim();
-        if (hideTask) {
-            setVisibility(View.INVISIBLE);
-        } else if (launchState.launchedHasConfigurationChanged) {
-            // Just load the views as-is
-        } else if (launchState.launchedFromAppWithThumbnail) {
-            if (isTaskViewLaunchTargetTask) {
-                // Set the dim to 0 so we can animate it in
-                initialDim = 0;
-                // Hide the action button
-                mActionButtonView.setAlpha(0f);
-            } else if (occludesLaunchTarget) {
-                // Move the task view off screen (below) so we can animate it in
-                setTranslationY(offscreenY);
-            }
-
-        } else if (launchState.launchedFromHome) {
-            // Move the task view off screen (below) so we can animate it in
-            setTranslationY(offscreenY);
-            setTranslationZ(0);
-            setScaleX(1f);
-            setScaleY(1f);
-        }
-        // Apply the current dim
-        setDim(initialDim);
-    }
-
-    /** Animates this task view as it enters recents */
-    void startEnterRecentsAnimation(final ViewAnimation.TaskViewEnterContext ctx) {
-        RecentsConfiguration config = Recents.getConfiguration();
-        RecentsActivityLaunchState launchState = config.getLaunchState();
-        Resources res = mContext.getResources();
-        final TaskViewTransform transform = ctx.currentTaskTransform;
-        final int taskViewEnterFromAppDuration = res.getInteger(
-                R.integer.recents_task_enter_from_app_duration);
-        final int taskViewEnterFromHomeDuration = res.getInteger(
-                R.integer.recents_task_enter_from_home_duration);
-        final int taskViewEnterFromHomeStaggerDelay = res.getInteger(
-                R.integer.recents_task_enter_from_home_stagger_delay);
-        final int taskViewAffiliateGroupEnterOffset = res.getDimensionPixelSize(
-                R.dimen.recents_task_view_affiliate_group_enter_offset);
-
-        if (launchState.launchedFromAppWithThumbnail) {
-            if (mTask.isLaunchTarget) {
-                ctx.postAnimationTrigger.increment();
-                // Immediately start the dim animation
-                animateDimToProgress(taskViewEnterFromAppDuration,
-                        ctx.postAnimationTrigger.decrementOnAnimationEnd());
-                // Animate the action button in
-                fadeInActionButton(taskViewEnterFromAppDuration);
-            } else {
-                // Animate the task up if it was occluding the launch target
-                if (ctx.currentTaskOccludesLaunchTarget) {
-                    setTranslationY(taskViewAffiliateGroupEnterOffset);
-                    setAlpha(0f);
-                    animate().alpha(1f)
-                            .translationY(0)
-                            .setUpdateListener(null)
-                            .setListener(new AnimatorListenerAdapter() {
-                                private boolean hasEnded;
-
-                                // We use the animation listener instead of withEndAction() to
-                                // ensure that onAnimationEnd() is called when the animator is
-                                // cancelled
-                                @Override
-                                public void onAnimationEnd(Animator animation) {
-                                    if (hasEnded) return;
-                                    ctx.postAnimationTrigger.decrement();
-                                    hasEnded = true;
-                                }
-                            })
-                            .setInterpolator(mFastOutSlowInInterpolator)
-                            .setDuration(taskViewEnterFromHomeDuration)
-                            .start();
-                    ctx.postAnimationTrigger.increment();
-                }
-            }
-
-        } else if (launchState.launchedFromHome) {
-            // Animate the tasks up
-            int frontIndex = (ctx.currentStackViewCount - ctx.currentStackViewIndex - 1);
-            int delay = frontIndex * taskViewEnterFromHomeStaggerDelay;
-
-            setScaleX(transform.scale);
-            setScaleY(transform.scale);
-            if (!config.fakeShadows) {
-                animate().translationZ(transform.translationZ);
-            }
-            animate()
-                    .translationY(0)
-                    .setStartDelay(delay)
-                    .setUpdateListener(ctx.updateListener)
-                    .setListener(new AnimatorListenerAdapter() {
-                        private boolean hasEnded;
-
-                        // We use the animation listener instead of withEndAction() to ensure that
-                        // onAnimationEnd() is called when the animator is cancelled
-                        @Override
-                        public void onAnimationEnd(Animator animation) {
-                            if (hasEnded) return;
-                            ctx.postAnimationTrigger.decrement();
-                            hasEnded = true;
-                        }
-                    })
-                    .setInterpolator(mQuintOutInterpolator)
-                    .setDuration(taskViewEnterFromHomeDuration +
-                            frontIndex * taskViewEnterFromHomeStaggerDelay)
-                    .start();
-            ctx.postAnimationTrigger.increment();
-        }
-    }
-
-    public void cancelEnterRecentsAnimation() {
-        animate().cancel();
-    }
-
-    public void fadeInActionButton(int duration) {
-        // Hide the action button
-        mActionButtonView.setAlpha(0f);
-
-        // Animate the action button in
-        mActionButtonView.animate().alpha(1f)
-                .setDuration(duration)
-                .setInterpolator(PhoneStatusBar.ALPHA_IN)
-                .start();
-    }
-
-    /** Animates this task view as it leaves recents by pressing home. */
-    void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) {
-        int taskViewExitToHomeDuration = getResources().getInteger(
-                R.integer.recents_task_exit_to_home_duration);
-        animate()
-                .translationY(ctx.offscreenTranslationY)
-                .setStartDelay(0)
-                .setUpdateListener(null)
-                .setListener(null)
-                .setInterpolator(mFastOutLinearInInterpolator)
-                .setDuration(taskViewExitToHomeDuration)
-                .withEndAction(ctx.postAnimationTrigger.decrementAsRunnable())
-                .start();
-        ctx.postAnimationTrigger.increment();
-    }
-
-    /** Animates this task view as it exits recents */
-    void startLaunchTaskAnimation(final Runnable postAnimRunnable, boolean isLaunchingTask,
-            boolean occludesLaunchTarget, boolean lockToTask) {
-        final int taskViewExitToAppDuration = mContext.getResources().getInteger(
-                R.integer.recents_task_exit_to_app_duration);
-        final int taskViewAffiliateGroupEnterOffset = mContext.getResources().getDimensionPixelSize(
-                R.dimen.recents_task_view_affiliate_group_enter_offset);
-
-        if (isLaunchingTask) {
-            // Animate the dim
-            if (mDimAlpha > 0) {
-                ObjectAnimator anim = ObjectAnimator.ofInt(this, "dim", 0);
-                anim.setDuration(taskViewExitToAppDuration);
-                anim.setInterpolator(mFastOutLinearInInterpolator);
-                anim.start();
-            }
-
-            // Animate the action button away
-            if (!lockToTask) {
-                float toScale = 0.9f;
-                mActionButtonView.animate()
-                        .scaleX(toScale)
-                        .scaleY(toScale);
-            }
-            mActionButtonView.animate()
-                    .alpha(0f)
-                    .setStartDelay(0)
-                    .setDuration(taskViewExitToAppDuration)
-                    .setInterpolator(mFastOutLinearInInterpolator)
-                    .withEndAction(postAnimRunnable)
-                    .start();
-        } else {
-            // Hide the dismiss button
-            mHeaderView.startLaunchTaskDismissAnimation(postAnimRunnable);
-            // If this is another view in the task grouping and is in front of the launch task,
-            // animate it away first
-            if (occludesLaunchTarget) {
-                animate().alpha(0f)
-                    .translationY(getTranslationY() + taskViewAffiliateGroupEnterOffset)
-                    .setStartDelay(0)
-                    .setUpdateListener(null)
-                    .setListener(null)
-                    .setInterpolator(mFastOutLinearInInterpolator)
-                    .setDuration(taskViewExitToAppDuration)
-                    .start();
-            }
-        }
-    }
-
-    /** Animates the deletion of this task view */
-    void startDeleteTaskAnimation(final Runnable r, int delay) {
-        int taskViewRemoveAnimDuration = getResources().getInteger(
-                R.integer.recents_animate_task_view_remove_duration);
-        int taskViewRemoveAnimTranslationXPx = getResources().getDimensionPixelSize(
-                R.dimen.recents_task_view_remove_anim_translation_x);
-
-        // Disabling clipping with the stack while the view is animating away
-        setClipViewInStack(false);
-
-        animate().translationX(taskViewRemoveAnimTranslationXPx)
-            .alpha(0f)
-            .setStartDelay(delay)
-            .setUpdateListener(null)
-            .setListener(null)
-            .setInterpolator(mFastOutSlowInInterpolator)
-            .setDuration(taskViewRemoveAnimDuration)
-            .withEndAction(new Runnable() {
-                @Override
-                public void run() {
-                    if (r != null) {
-                        r.run();
-                    }
-
-                    // Re-enable clipping with the stack (we will reuse this view)
-                    setClipViewInStack(true);
-                }
-            })
-            .start();
+    /**
+     * Cancels any current transform animations.
+     */
+    public void cancelTransformAnimation() {
+        Utilities.cancelAnimation(mTransformAnimation);
     }
 
     /** Enables/disables handling touch on this task view. */
@@ -544,12 +330,14 @@
     void dismissTask() {
         // Animate out the view and call the callback
         final TaskView tv = this;
-        startDeleteTaskAnimation(new Runnable() {
+        DismissTaskViewEvent dismissEvent = new DismissTaskViewEvent(tv, mTask);
+        dismissEvent.addPostAnimationCallback(new Runnable() {
             @Override
             public void run() {
-                EventBus.getDefault().send(new DismissTaskViewEvent(mTask, tv));
+                EventBus.getDefault().send(new TaskViewDismissedEvent(mTask, tv));
             }
-        }, 0);
+        });
+        EventBus.getDefault().send(dismissEvent);
     }
 
     /**
@@ -600,12 +388,8 @@
             }
         } else {
             float dimAlpha = mDimAlpha / 255.0f;
-            if (mThumbnailView != null) {
-                mThumbnailView.setDimAlpha(dimAlpha);
-            }
-            if (mHeaderView != null) {
-                mHeaderView.setDimAlpha(dim);
-            }
+            mThumbnailView.setDimAlpha(dimAlpha);
+            mHeaderView.setDimAlpha(dim);
         }
     }
 
@@ -615,18 +399,18 @@
     }
 
     /** Animates the dim to the task progress. */
-    void animateDimToProgress(int duration, Animator.AnimatorListener postAnimRunnable) {
+    void animateDimToProgress(int duration, Animator.AnimatorListener animListener) {
         // Animate the dim into view as well
         int toDim = getDimFromTaskProgress();
         if (toDim != getDim()) {
-            ObjectAnimator anim = ObjectAnimator.ofInt(TaskView.this, "dim", toDim);
+            ObjectAnimator anim = ObjectAnimator.ofInt(this, DIM, getDim(), toDim);
             anim.setDuration(duration);
-            if (postAnimRunnable != null) {
-                anim.addListener(postAnimRunnable);
+            if (animListener != null) {
+                anim.addListener(animListener);
             }
             anim.start();
         } else {
-            postAnimRunnable.onAnimationEnd(null);
+            animListener.onAnimationEnd(null);
         }
     }
 
@@ -644,19 +428,10 @@
         setDim(getDimFromTaskProgress());
     }
 
-    /**** View focus state ****/
-
     /**
      * Explicitly sets the focused state of this task.
      */
-    public void setFocusedState(boolean isFocused, boolean animated, boolean requestViewFocus) {
-        if (DEBUG) {
-            Log.d(TAG, "setFocusedState: " + mTask.title + " focused: " + isFocused +
-                    " animated: " + animated + " requestViewFocus: " + requestViewFocus +
-                    " isFocused(): " + isFocused() +
-                    " isAccessibilityFocused(): " + isAccessibilityFocused());
-        }
-
+    public void setFocusedState(boolean isFocused, boolean requestViewFocus) {
         SystemServicesProxy ssp = Recents.getSystemServices();
         if (isFocused) {
             if (requestViewFocus && !isFocused()) {
@@ -672,45 +447,131 @@
         }
     }
 
-    /**** TaskCallbacks Implementation ****/
+    /**
+     * Shows the action button.
+     * @param fadeIn whether or not to animate the action button in.
+     * @param fadeInDuration the duration of the action button animation, only used if
+     *                       {@param fadeIn} is true.
+     */
+    public void showActionButton(boolean fadeIn, int fadeInDuration) {
+        mActionButtonView.setVisibility(View.VISIBLE);
 
-    /** Binds this task view to the task */
-    public void onTaskBound(Task t) {
-        mTask = t;
-        mTask.addCallback(this);
+        if (fadeIn) {
+            if (mActionButtonView.getAlpha() < 1f) {
+                mActionButtonView.animate()
+                        .alpha(1f)
+                        .scaleX(1f)
+                        .scaleY(1f)
+                        .setDuration(fadeInDuration)
+                        .setInterpolator(PhoneStatusBar.ALPHA_IN)
+                        .withLayer()
+                        .start();
+            }
+        } else {
+            mActionButtonView.setScaleX(1f);
+            mActionButtonView.setScaleY(1f);
+            mActionButtonView.setAlpha(1f);
+            mActionButtonView.setTranslationZ(mActionButtonTranslationZ);
+        }
+    }
 
-        // Hide the action button if lock to app is disabled for this view
-        int lockButtonVisibility = (!t.lockToTaskEnabled || !t.lockToThisTask) ? GONE : VISIBLE;
-        if (mActionButtonView.getVisibility() != lockButtonVisibility) {
-            mActionButtonView.setVisibility(lockButtonVisibility);
-            requestLayout();
+    /**
+     * Immediately hides the action button.
+     *
+     * @param fadeOut whether or not to animate the action button out.
+     */
+    public void hideActionButton(boolean fadeOut, int fadeOutDuration, boolean scaleDown,
+            final Animator.AnimatorListener animListener) {
+        if (fadeOut) {
+            if (mActionButtonView.getAlpha() > 0f) {
+                if (scaleDown) {
+                    float toScale = 0.9f;
+                    mActionButtonView.animate()
+                            .scaleX(toScale)
+                            .scaleY(toScale);
+                }
+                mActionButtonView.animate()
+                        .alpha(0f)
+                        .setDuration(fadeOutDuration)
+                        .setInterpolator(PhoneStatusBar.ALPHA_OUT)
+                        .withEndAction(new Runnable() {
+                            @Override
+                            public void run() {
+                                if (animListener != null) {
+                                    animListener.onAnimationEnd(null);
+                                }
+                                mActionButtonView.setVisibility(View.INVISIBLE);
+                            }
+                        })
+                        .withLayer()
+                        .start();
+            }
+        } else {
+            mActionButtonView.setAlpha(0f);
+            mActionButtonView.setVisibility(View.INVISIBLE);
+            if (animListener != null) {
+                animListener.onAnimationEnd(null);
+            }
+        }
+    }
+
+    /**** TaskStackAnimationHelper.Callbacks Implementation ****/
+
+    @Override
+    public void onPrepareLaunchTargetForEnterAnimation() {
+        // These values will be animated in when onStartLaunchTargetEnterAnimation() is called
+        setDim(0);
+        mActionButtonView.setAlpha(0f);
+    }
+
+    @Override
+    public void onStartLaunchTargetEnterAnimation(int duration, boolean screenPinningEnabled,
+            ReferenceCountedTrigger postAnimationTrigger) {
+        postAnimationTrigger.increment();
+        animateDimToProgress(duration, postAnimationTrigger.decrementOnAnimationEnd());
+
+        if (screenPinningEnabled) {
+            showActionButton(true /* fadeIn */, duration /* fadeInDuration */);
         }
     }
 
     @Override
-    public void onTaskDataLoaded(Task task) {
-        if (mThumbnailView != null && mHeaderView != null) {
-            // Bind each of the views to the new task data
-            mThumbnailView.rebindToTask(mTask);
-            mHeaderView.rebindToTask(mTask);
-
-            // Rebind any listeners
-            mActionButtonView.setOnClickListener(this);
-            setOnLongClickListener(this);
+    public void onStartLaunchTargetLaunchAnimation(int duration, boolean screenPinningRequested,
+            ReferenceCountedTrigger postAnimationTrigger) {
+        if (mDimAlpha > 0) {
+            ObjectAnimator anim = ObjectAnimator.ofInt(this, DIM, getDim(), 0);
+            anim.setDuration(duration);
+            anim.setInterpolator(PhoneStatusBar.ALPHA_OUT);
+            anim.start();
         }
+
+        postAnimationTrigger.increment();
+        hideActionButton(true /* fadeOut */, duration,
+                !screenPinningRequested /* scaleDown */,
+                postAnimationTrigger.decrementOnAnimationEnd());
+    }
+
+    /**** TaskCallbacks Implementation ****/
+
+    public void onTaskBound(Task t) {
+        mTask = t;
+        mTask.addCallback(this);
+    }
+
+    @Override
+    public void onTaskDataLoaded(Task task) {
+        // Bind each of the views to the new task data
+        mThumbnailView.rebindToTask(mTask);
+        mHeaderView.rebindToTask(mTask);
         mTaskDataLoaded = true;
     }
 
     @Override
     public void onTaskDataUnloaded() {
-        if (mThumbnailView != null && mHeaderView != null) {
-            // Unbind each of the views from the task data and remove the task callback
-            mTask.removeCallback(this);
-            mThumbnailView.unbindFromTask();
-            mHeaderView.unbindFromTask();
-            // Unbind any listeners
-            mActionButtonView.setOnClickListener(null);
-        }
+        // Unbind each of the views from the task data and remove the task callback
+        mTask.removeCallback(this);
+        mThumbnailView.unbindFromTask();
+        mHeaderView.unbindFromTask();
         mTaskDataLoaded = false;
     }
 
@@ -746,17 +607,6 @@
             // Start listening for drag events
             setClipViewInStack(false);
 
-            // Enlarge the view slightly
-            final float finalScale = getScaleX() * 1.05f;
-            animate()
-                    .scaleX(finalScale)
-                    .scaleY(finalScale)
-                    .setDuration(175)
-                    .setUpdateListener(null)
-                    .setListener(null)
-                    .setInterpolator(mFastOutSlowInInterpolator)
-                    .start();
-
             mDownTouchPos.x += ((1f - getScaleX()) * getWidth()) / 2;
             mDownTouchPos.y += ((1f - getScaleY()) * getHeight()) / 2;
 
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewAnimation.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewAnimation.java
new file mode 100644
index 0000000..363ad66
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewAnimation.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.recents.views;
+
+import android.animation.Animator;
+import android.animation.AnimatorSet;
+import android.view.animation.Interpolator;
+import android.view.animation.LinearInterpolator;
+
+import java.util.List;
+
+/**
+ * The animation properties to animate a {@link TaskView} to a given {@link TaskViewTransform}.
+ */
+public class TaskViewAnimation {
+
+    public static final TaskViewAnimation IMMEDIATE = new TaskViewAnimation(0,
+            new LinearInterpolator());
+
+    public final int startDelay;
+    public final int duration;
+    public final Interpolator interpolator;
+    public final Animator.AnimatorListener listener;
+
+    public TaskViewAnimation(int duration, Interpolator interpolator) {
+        this(0 /* startDelay */, duration, interpolator, null);
+    }
+
+    public TaskViewAnimation(int duration, Interpolator interpolator,
+            Animator.AnimatorListener listener) {
+        this(0 /* startDelay */, duration, interpolator, listener);
+    }
+
+    public TaskViewAnimation(int startDelay, int duration, Interpolator interpolator,
+            Animator.AnimatorListener listener) {
+        this.startDelay = startDelay;
+        this.duration = duration;
+        this.interpolator = interpolator;
+        this.listener = listener;
+    }
+
+    /**
+     * Creates a new {@link AnimatorSet} that will animate the given animators with the current
+     * animation properties.
+     */
+    public AnimatorSet createAnimator(List<Animator> animators) {
+        AnimatorSet anim = new AnimatorSet();
+        anim.setStartDelay(startDelay);
+        anim.setDuration(duration);
+        anim.setInterpolator(interpolator);
+        if (listener != null) {
+            anim.addListener(listener);
+        }
+        anim.playTogether(animators);
+        return anim;
+    }
+
+    /**
+     * Returns whether this animation has any duration.
+     */
+    public boolean isImmediate() {
+        return duration <= 0;
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java
index 9a2ffe7..e8b7574 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewHeader.java
@@ -291,22 +291,6 @@
         mMoveTaskButton.setOnClickListener(null);
     }
 
-    /** Animates this task bar dismiss button when launching a task. */
-    void startLaunchTaskDismissAnimation(final Runnable postAnimationRunanble) {
-        if (mDismissButton.getVisibility() == View.VISIBLE) {
-            int taskViewExitToAppDuration = mContext.getResources().getInteger(
-                    R.integer.recents_task_exit_to_app_duration);
-            mDismissButton.animate().cancel();
-            mDismissButton.animate()
-                    .alpha(0f)
-                    .setStartDelay(0)
-                    .setInterpolator(mFastOutSlowInInterpolator)
-                    .setDuration(taskViewExitToAppDuration)
-                    .withEndAction(postAnimationRunanble)
-                    .start();
-        }
-    }
-
     /** Animates this task bar if the user does not interact with the stack after a certain time. */
     void startNoUserInteractionAnimation() {
         if (mDismissButton.getVisibility() != View.VISIBLE) {
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewTransform.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewTransform.java
index 3ee50ac..14bab64 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewTransform.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskViewTransform.java
@@ -16,16 +16,19 @@
 
 package com.android.systemui.recents.views;
 
-import android.animation.ValueAnimator;
+import android.animation.Animator;
+import android.animation.ObjectAnimator;
+import android.animation.PropertyValuesHolder;
 import android.graphics.RectF;
 import android.util.IntProperty;
 import android.util.Property;
 import android.view.View;
-import android.view.ViewPropertyAnimator;
-import android.view.animation.Interpolator;
 
+import java.util.ArrayList;
 
-/* The transform state for a task view */
+/**
+ * The visual properties for a {@link TaskView}.
+ */
 public class TaskViewTransform {
 
     public static final Property<View, Integer> LEFT =
@@ -80,9 +83,6 @@
                 }
             };
 
-    // TODO: Move this out of the transform
-    public int startDelay = 0;
-
     public float translationZ = 0;
     public float scale = 1f;
     public float alpha = 1f;
@@ -94,15 +94,10 @@
     // This is a window-space rect used for positioning the task in the stack and freeform workspace
     public RectF rect = new RectF();
 
-    public TaskViewTransform() {
-        // Do nothing
-    }
-
     /**
      * Resets the current transform.
      */
     public void reset() {
-        startDelay = 0;
         translationZ = 0;
         scale = 1f;
         alpha = 1f;
@@ -116,50 +111,34 @@
     public boolean hasAlphaChangedFrom(float v) {
         return (Float.compare(alpha, v) != 0);
     }
+
     public boolean hasScaleChangedFrom(float v) {
         return (Float.compare(scale, v) != 0);
     }
+
     public boolean hasTranslationZChangedFrom(float v) {
         return (Float.compare(translationZ, v) != 0);
     }
 
-    /** Applies this transform to a view. */
-    public void applyToTaskView(TaskView v, int duration, Interpolator interp, boolean allowLayers,
-            boolean allowShadows, ValueAnimator.AnimatorUpdateListener updateCallback) {
-        // Check to see if any properties have changed, and update the task view
-        if (duration > 0) {
-            ViewPropertyAnimator anim = v.animate();
-            boolean requiresLayers = false;
+    public boolean hasRectChangedFrom(View v) {
+        return ((int) rect.left != v.getLeft()) || ((int) rect.right != v.getRight()) ||
+                ((int) rect.top != v.getTop()) || ((int) rect.bottom != v.getBottom());
+    }
 
-            // Animate to the final state
-            if (allowShadows && hasTranslationZChangedFrom(v.getTranslationZ())) {
-                anim.translationZ(translationZ);
-            }
-            if (hasScaleChangedFrom(v.getScaleX())) {
-                anim.scaleX(scale)
-                    .scaleY(scale);
-                requiresLayers = true;
-            }
-            if (hasAlphaChangedFrom(v.getAlpha())) {
-                // Use layers if we animate alpha
-                anim.alpha(alpha);
-                requiresLayers = true;
-            }
-            if (requiresLayers && allowLayers) {
-                anim.withLayer();
-            }
-            if (updateCallback != null) {
-                anim.setUpdateListener(updateCallback);
-            } else {
-                anim.setUpdateListener(null);
-            }
-            anim.setListener(null);
-            anim.setStartDelay(startDelay)
-                    .setDuration(duration)
-                    .setInterpolator(interp)
-                    .start();
-        } else {
-            // Set the changed properties
+    /**
+     * Applies this transform to a view.
+     *
+     * @return whether hardware layers are required for this animation.
+     */
+    public boolean applyToTaskView(TaskView v, ArrayList<Animator> animators,
+            TaskViewAnimation taskAnimation, boolean allowShadows) {
+        // Return early if not visible
+        boolean requiresHwLayers = false;
+        if (!visible) {
+            return requiresHwLayers;
+        }
+
+        if (taskAnimation.isImmediate()) {
             if (allowShadows && hasTranslationZChangedFrom(v.getTranslationZ())) {
                 v.setTranslationZ(translationZ);
             }
@@ -170,29 +149,45 @@
             if (hasAlphaChangedFrom(v.getAlpha())) {
                 v.setAlpha(alpha);
             }
+            if (hasRectChangedFrom(v)) {
+                v.setLeftTopRightBottom((int) rect.left, (int) rect.top, (int) rect.right,
+                        (int) rect.bottom);
+            }
+        } else {
+            if (allowShadows && hasTranslationZChangedFrom(v.getTranslationZ())) {
+                animators.add(ObjectAnimator.ofFloat(v, View.TRANSLATION_Z, v.getTranslationZ(),
+                        translationZ));
+            }
+            if (hasScaleChangedFrom(v.getScaleX())) {
+                animators.add(ObjectAnimator.ofPropertyValuesHolder(v,
+                        PropertyValuesHolder.ofFloat(View.SCALE_X, v.getScaleX(), scale),
+                        PropertyValuesHolder.ofFloat(View.SCALE_Y, v.getScaleX(), scale)));
+            }
+            if (hasAlphaChangedFrom(v.getAlpha())) {
+                animators.add(ObjectAnimator.ofFloat(v, View.ALPHA, v.getAlpha(), alpha));
+                requiresHwLayers = true;
+            }
+            if (hasRectChangedFrom(v)) {
+                animators.add(ObjectAnimator.ofPropertyValuesHolder(v,
+                        PropertyValuesHolder.ofInt(LEFT, v.getLeft(), (int) rect.left),
+                        PropertyValuesHolder.ofInt(TOP, v.getTop(), (int) rect.top),
+                        PropertyValuesHolder.ofInt(RIGHT, v.getRight(), (int) rect.right),
+                        PropertyValuesHolder.ofInt(BOTTOM, v.getBottom(), (int) rect.bottom)));
+            }
         }
+        return requiresHwLayers;
     }
 
     /** Reset the transform on a view. */
     public static void reset(TaskView v) {
-        // Cancel any running animations and reset the translation in case something else (like a
-        // dismiss animation) changes it
-        v.animate().cancel();
         v.setTranslationX(0f);
         v.setTranslationY(0f);
         v.setTranslationZ(0f);
         v.setScaleX(1f);
         v.setScaleY(1f);
         v.setAlpha(1f);
-        v.getViewBounds().setClipBottom(0, false /* forceUpdate */);
+        v.getViewBounds().setClipBottom(0);
         v.setLeftTopRightBottom(0, 0, 0, 0);
         v.mThumbnailView.setBitmapScale(1f);
     }
-
-    @Override
-    public String toString() {
-        return "TaskViewTransform delay: " + startDelay + " z: " + translationZ +
-                " scale: " + scale + " alpha: " + alpha + " visible: " + visible +
-                " rect: " + rect + " p: " + p;
-    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/ViewAnimation.java b/packages/SystemUI/src/com/android/systemui/recents/views/ViewAnimation.java
deleted file mode 100644
index e1d80fd..0000000
--- a/packages/SystemUI/src/com/android/systemui/recents/views/ViewAnimation.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.recents.views;
-
-import android.animation.ValueAnimator;
-import android.graphics.Rect;
-import com.android.systemui.recents.misc.ReferenceCountedTrigger;
-
-/* Common code related to view animations */
-public class ViewAnimation {
-
-    /* The animation context for a task view animation into Recents */
-    public static class TaskViewEnterContext {
-        // A trigger to run some logic when all the animations complete.  This works around the fact
-        // that it is difficult to coordinate ViewPropertyAnimators
-        public ReferenceCountedTrigger postAnimationTrigger;
-        // An update listener to notify as the enter animation progresses (used for the home transition)
-        ValueAnimator.AnimatorUpdateListener updateListener;
-
-        // These following properties are updated for each task view we start the enter animation on
-
-        // Whether or not the current task occludes the launch target
-        boolean currentTaskOccludesLaunchTarget;
-        // The task rect for the current stack
-        Rect currentTaskRect;
-        // The transform of the current task view
-        TaskViewTransform currentTaskTransform;
-        // The view index of the current task view
-        int currentStackViewIndex;
-        // The total number of task views
-        int currentStackViewCount;
-
-        public TaskViewEnterContext(ReferenceCountedTrigger t) {
-            postAnimationTrigger = t;
-        }
-    }
-
-    /* The animation context for a task view animation out of Recents */
-    public static class TaskViewExitContext {
-        // A trigger to run some logic when all the animations complete.  This works around the fact
-        // that it is difficult to coordinate ViewPropertyAnimators
-        ReferenceCountedTrigger postAnimationTrigger;
-
-        // The translationY to apply to a TaskView to move it off the bottom of the task stack
-        int offscreenTranslationY;
-
-        public TaskViewExitContext(ReferenceCountedTrigger t) {
-            postAnimationTrigger = t;
-        }
-    }
-
-}
diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java b/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java
index 6ff7a3e..189e651 100644
--- a/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java
+++ b/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java
@@ -17,7 +17,8 @@
 package com.android.systemui.stackdivider;
 
 import android.content.res.Configuration;
-import android.view.IDockDividerVisibilityListener;
+import android.os.RemoteException;
+import android.view.IDockedStackListener;
 import android.view.LayoutInflater;
 import android.view.View;
 
@@ -49,7 +50,7 @@
         putComponent(Divider.class, this);
         mDockDividerVisibilityListener = new DockDividerVisibilityListener();
         SystemServicesProxy ssp = Recents.getSystemServices();
-        ssp.registerDockDividerVisibilityListener(mDockDividerVisibilityListener);
+        ssp.registerDockedStackListener(mDockDividerVisibilityListener);
     }
 
     @Override
@@ -94,10 +95,15 @@
         });
     }
 
-    class DockDividerVisibilityListener extends IDockDividerVisibilityListener.Stub {
+    class DockDividerVisibilityListener extends IDockedStackListener.Stub {
+
         @Override
-        public void onDockDividerVisibilityChanged(boolean visible) {
+        public void onDividerVisibilityChanged(boolean visible) throws RemoteException {
             updateVisibility(visible);
         }
+
+        @Override
+        public void onDockedStackExistsChanged(boolean exists) throws RemoteException {
+        }
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerHandleView.java b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerHandleView.java
new file mode 100644
index 0000000..5ef56f3
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerHandleView.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.stackdivider;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
+import android.annotation.Nullable;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.util.AttributeSet;
+import android.util.Property;
+import android.view.animation.AnimationUtils;
+import android.view.animation.Interpolator;
+import android.widget.ImageButton;
+
+import com.android.systemui.R;
+
+/**
+ * View for the handle in the docked stack divider.
+ */
+public class DividerHandleView extends ImageButton {
+
+    private final static Property<DividerHandleView, Integer> WIDTH_PROPERTY
+            = new Property<DividerHandleView, Integer>(Integer.class, "width") {
+
+        @Override
+        public Integer get(DividerHandleView object) {
+            return object.mCurrentWidth;
+        }
+
+        @Override
+        public void set(DividerHandleView object, Integer value) {
+            object.mCurrentWidth = value;
+            object.invalidate();
+        }
+    };
+
+    private final static Property<DividerHandleView, Integer> HEIGHT_PROPERTY
+            = new Property<DividerHandleView, Integer>(Integer.class, "height") {
+
+        @Override
+        public Integer get(DividerHandleView object) {
+            return object.mCurrentHeight;
+        }
+
+        @Override
+        public void set(DividerHandleView object, Integer value) {
+            object.mCurrentHeight = value;
+            object.invalidate();
+        }
+    };
+
+    private final Paint mPaint = new Paint();
+    private final int mWidth;
+    private final int mHeight;
+    private final int mCircleDiameter;
+    private final Interpolator mFastOutSlowInInterpolator;
+    private int mCurrentWidth;
+    private int mCurrentHeight;
+    private AnimatorSet mAnimator;
+
+    public DividerHandleView(Context context, @Nullable AttributeSet attrs) {
+        super(context, attrs);
+        mPaint.setColor(getResources().getColor(R.color.docked_divider_handle, null));
+        mPaint.setAntiAlias(true);
+        mWidth = getResources().getDimensionPixelSize(R.dimen.docked_divider_handle_width);
+        mHeight = getResources().getDimensionPixelSize(R.dimen.docked_divider_handle_height);
+        mCurrentWidth = mWidth;
+        mCurrentHeight = mHeight;
+        mCircleDiameter = (mWidth + mHeight) / 3;
+        mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(getContext(),
+                android.R.interpolator.fast_out_slow_in);
+    }
+
+    public void setTouching(boolean touching, boolean animate) {
+        if (mAnimator != null) {
+            mAnimator.cancel();
+            mAnimator = null;
+        }
+        if (!animate) {
+            if (touching) {
+                mCurrentWidth = mCircleDiameter;
+                mCurrentHeight = mCircleDiameter;
+            } else {
+                mCurrentWidth = mWidth;
+                mCurrentHeight = mHeight;
+            }
+            invalidate();
+        } else {
+            animateToTarget(touching ? mCircleDiameter : mWidth,
+                    touching ? mCircleDiameter : mHeight, touching);
+        }
+    }
+
+    private void animateToTarget(int targetWidth, int targetHeight, boolean touching) {
+        ObjectAnimator widthAnimator = ObjectAnimator.ofInt(this, WIDTH_PROPERTY,
+                mCurrentWidth, targetWidth);
+        ObjectAnimator heightAnimator = ObjectAnimator.ofInt(this, HEIGHT_PROPERTY,
+                mCurrentHeight, targetHeight);
+        mAnimator = new AnimatorSet();
+        mAnimator.playTogether(widthAnimator, heightAnimator);
+        mAnimator.setDuration(touching
+                ? DividerView.TOUCH_ANIMATION_DURATION
+                : DividerView.TOUCH_RELEASE_ANIMATION_DURATION);
+        mAnimator.setInterpolator(touching
+                ? DividerView.TOUCH_RESPONSE_INTERPOLATOR
+                : mFastOutSlowInInterpolator);
+        mAnimator.addListener(new AnimatorListenerAdapter() {
+            @Override
+            public void onAnimationEnd(Animator animation) {
+                mAnimator = null;
+            }
+        });
+        mAnimator.start();
+    }
+
+    @Override
+    protected void onDraw(Canvas canvas) {
+        int left = getWidth() / 2 - mCurrentWidth / 2;
+        int top = getHeight() / 2 - mCurrentHeight / 2;
+        int radius = Math.min(mCurrentWidth, mCurrentHeight) / 2;
+        canvas.drawRoundRect(left, top, left + mCurrentWidth, top + mCurrentHeight,
+                radius, radius, mPaint);
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerSnapAlgorithm.java b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerSnapAlgorithm.java
index 5af172c..e43d531 100644
--- a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerSnapAlgorithm.java
+++ b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerSnapAlgorithm.java
@@ -17,25 +17,42 @@
 package com.android.systemui.stackdivider;
 
 import android.content.Context;
-import android.util.DisplayMetrics;
-import android.view.DisplayInfo;
+import android.graphics.Rect;
 
 import com.android.systemui.statusbar.FlingAnimationUtils;
 
 import java.util.ArrayList;
 
-import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
-
 /**
  * Calculates the snap targets and the snap position given a position and a velocity. All positions
  * here are to be interpreted as the left/top edge of the divider rectangle.
  */
 public class DividerSnapAlgorithm {
 
+    /**
+     * 3 snap targets: left/top has 16:9 ratio (for videos), 1:1, and right/bottom has 16:9 ratio
+     */
+    private static final int SNAP_MODE_16_9 = 0;
+
+    /**
+     * 3 snap targets: fixed ratio, 1:1, (1 - fixed ratio)
+     */
+    private static final int SNAP_FIXED_RATIO = 1;
+
+    /**
+     * 1 snap target: 1:1
+     */
+    private static final int SNAP_ONLY_1_1 = 2;
+
     private final Context mContext;
     private final FlingAnimationUtils mFlingAnimationUtils;
+    private final int mDisplayWidth;
+    private final int mDisplayHeight;
     private final int mDividerSize;
-    private final ArrayList<SnapTarget> mTargets;
+    private final ArrayList<SnapTarget> mTargets = new ArrayList<>();
+    private final Rect mInsets = new Rect();
+    private final int mSnapMode;
+    private final float mFixedRatio;
 
     /** The first target which is still splitting the screen */
     private final SnapTarget mFirstSplitTarget;
@@ -47,11 +64,19 @@
     private final SnapTarget mDismissEndTarget;
 
     public DividerSnapAlgorithm(Context ctx, FlingAnimationUtils flingAnimationUtils,
-            int dividerSize, boolean isHorizontalDivision) {
+            int displayWidth, int displayHeight, int dividerSize, boolean isHorizontalDivision,
+            Rect insets) {
         mContext = ctx;
         mFlingAnimationUtils = flingAnimationUtils;
         mDividerSize = dividerSize;
-        mTargets = calculateTargets(isHorizontalDivision);
+        mDisplayWidth = displayWidth;
+        mDisplayHeight = displayHeight;
+        mInsets.set(insets);
+        mSnapMode = ctx.getResources().getInteger(
+                com.android.internal.R.integer.config_dockedStackDividerSnapMode);
+        mFixedRatio = ctx.getResources().getFraction(
+                com.android.internal.R.fraction.docked_stack_divider_fixed_ratio, 1, 1);
+        calculateTargets(isHorizontalDivision);
         mFirstSplitTarget = mTargets.get(1);
         mLastSplitTarget = mTargets.get(mTargets.size() - 2);
         mDismissStartTarget = mTargets.get(0);
@@ -75,6 +100,40 @@
         }
     }
 
+    public float calculateDismissingFraction(int position) {
+        if (position < mFirstSplitTarget.position) {
+            return 1f - (float) position / mFirstSplitTarget.position;
+        } else if (position > mLastSplitTarget.position) {
+            return (float) (position - mLastSplitTarget.position)
+                    / (mDismissEndTarget.position - mLastSplitTarget.position);
+        }
+        return 0f;
+    }
+
+    public SnapTarget getClosestDismissTarget(int position) {
+        if (position - mDismissStartTarget.position < mDismissEndTarget.position - position) {
+            return mDismissStartTarget;
+        } else {
+            return mDismissEndTarget;
+        }
+    }
+
+    public SnapTarget getFirstSplitTarget() {
+        return mFirstSplitTarget;
+    }
+
+    public SnapTarget getLastSplitTarget() {
+        return mLastSplitTarget;
+    }
+
+    public SnapTarget getDismissStartTarget() {
+        return mDismissStartTarget;
+    }
+
+    public SnapTarget getDismissEndTarget() {
+        return mDismissEndTarget;
+    }
+
     private SnapTarget snap(int position) {
         int minIndex = -1;
         int minDistance = Integer.MAX_VALUE;
@@ -89,22 +148,61 @@
         return mTargets.get(minIndex);
     }
 
-    private ArrayList<SnapTarget> calculateTargets(boolean isHorizontalDivision) {
-        ArrayList<SnapTarget> targets = new ArrayList<>();
-        DisplayMetrics info = mContext.getResources().getDisplayMetrics();
+    private void calculateTargets(boolean isHorizontalDivision) {
+        mTargets.clear();
         int dividerMax = isHorizontalDivision
-                ? info.heightPixels
-                : info.widthPixels;
+                ? mDisplayHeight
+                : mDisplayWidth;
+        mTargets.add(new SnapTarget(-mDividerSize, SnapTarget.FLAG_DISMISS_START));
+        switch (mSnapMode) {
+            case SNAP_MODE_16_9:
+                addRatio16_9Targets(isHorizontalDivision);
+                break;
+            case SNAP_FIXED_RATIO:
+                addFixedDivisionTargets(isHorizontalDivision);
+                break;
+            case SNAP_ONLY_1_1:
+                addMiddleTarget(isHorizontalDivision);
+                break;
+        }
+        mTargets.add(new SnapTarget(dividerMax, SnapTarget.FLAG_DISMISS_END));
+    }
 
-        // TODO: Better calculation
-        targets.add(new SnapTarget(-mDividerSize, SnapTarget.FLAG_DISMISS_START));
-        targets.add(new SnapTarget((int) (0.3415f * dividerMax) - mDividerSize / 2,
+    private void addFixedDivisionTargets(boolean isHorizontalDivision) {
+        int start = isHorizontalDivision ? mInsets.top : mInsets.left;
+        int end = isHorizontalDivision
+                ? mDisplayHeight - mInsets.bottom
+                : mDisplayWidth - mInsets.right;
+        mTargets.add(new SnapTarget((int) (start + mFixedRatio * (end - start)) - mDividerSize / 2,
                 SnapTarget.FLAG_NONE));
-        targets.add(new SnapTarget(dividerMax / 2 - mDividerSize / 2, SnapTarget.FLAG_NONE));
-        targets.add(new SnapTarget((int) (0.6585f * dividerMax) - mDividerSize / 2,
+        addMiddleTarget(isHorizontalDivision);
+        mTargets.add(new SnapTarget((int) (start + (1 - mFixedRatio) * (end - start))
+                - mDividerSize / 2, SnapTarget.FLAG_NONE));
+    }
+
+    private void addRatio16_9Targets(boolean isHorizontalDivision) {
+        int start = isHorizontalDivision ? mInsets.top : mInsets.left;
+        int end = isHorizontalDivision
+                ? mDisplayHeight - mInsets.bottom
+                : mDisplayWidth - mInsets.right;
+        int startOther = isHorizontalDivision ? mInsets.left : mInsets.top;
+        int endOther = isHorizontalDivision
+                ? mDisplayWidth - mInsets.right
+                : mDisplayHeight - mInsets.bottom;
+        float size = 9.0f / 16.0f * (endOther - startOther);
+        int sizeInt = (int) Math.floor(size);
+        mTargets.add(new SnapTarget(start + sizeInt, SnapTarget.FLAG_NONE));
+        addMiddleTarget(isHorizontalDivision);
+        mTargets.add(new SnapTarget(end - sizeInt - mDividerSize, SnapTarget.FLAG_NONE));
+    }
+
+    private void addMiddleTarget(boolean isHorizontalDivision) {
+        int start = isHorizontalDivision ? mInsets.top : mInsets.left;
+        int end = isHorizontalDivision
+                ? mDisplayHeight - mInsets.bottom
+                : mDisplayWidth - mInsets.right;
+        mTargets.add(new SnapTarget(start + (end - start) / 2 - mDividerSize / 2,
                 SnapTarget.FLAG_NONE));
-        targets.add(new SnapTarget(dividerMax, SnapTarget.FLAG_DISMISS_END));
-        return targets;
     }
 
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java
index 13642eb..109cf47 100644
--- a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java
+++ b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java
@@ -21,12 +21,14 @@
 import android.animation.ValueAnimator;
 import android.animation.ValueAnimator.AnimatorUpdateListener;
 import android.annotation.Nullable;
+import android.app.ActivityManager.StackId;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.graphics.Rect;
 import android.graphics.Region.Op;
 import android.hardware.display.DisplayManager;
 import android.util.AttributeSet;
+import android.util.MathUtils;
 import android.view.Display;
 import android.view.DisplayInfo;
 import android.view.MotionEvent;
@@ -34,8 +36,11 @@
 import android.view.VelocityTracker;
 import android.view.View;
 import android.view.View.OnTouchListener;
+import android.view.ViewConfiguration;
 import android.view.ViewTreeObserver.InternalInsetsInfo;
 import android.view.ViewTreeObserver.OnComputeInternalInsetsListener;
+import android.view.Window;
+import android.view.WindowInsets;
 import android.view.WindowManager;
 import android.view.animation.AnimationUtils;
 import android.view.animation.Interpolator;
@@ -56,15 +61,29 @@
 public class DividerView extends FrameLayout implements OnTouchListener,
         OnComputeInternalInsetsListener {
 
+    static final long TOUCH_ANIMATION_DURATION = 150;
+    static final long TOUCH_RELEASE_ANIMATION_DURATION = 200;
+    static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
+            new PathInterpolator(0.3f, 0f, 0.1f, 1f);
+
     private static final String TAG = "DividerView";
 
-    private ImageButton mHandle;
+    private static final int TASK_POSITION_SAME = Integer.MAX_VALUE;
+    private static final float DIM_START_FRACTION = 0.5f;
+    private static final float DIM_DAMP_FACTOR = 1.7f;
+
+    private static final PathInterpolator SLOWDOWN_INTERPOLATOR =
+            new PathInterpolator(0.5f, 1f, 0.5f, 1f);
+
+    private DividerHandleView mHandle;
     private View mBackground;
     private int mStartX;
     private int mStartY;
     private int mStartPosition;
     private int mDockSide;
     private final int[] mTempInt2 = new int[2];
+    private boolean mMoving;
+    private int mTouchSlop;
 
     private int mDividerInsets;
     private int mDisplayWidth;
@@ -73,15 +92,20 @@
     private int mDividerSize;
     private int mTouchElevation;
 
-    private final Rect mTmpRect = new Rect();
+    private final Rect mDockedRect = new Rect();
+    private final Rect mDockedTaskRect = new Rect();
+    private final Rect mOtherTaskRect = new Rect();
+    private final Rect mOtherRect = new Rect();
+    private final Rect mDockedInsetRect = new Rect();
+    private final Rect mOtherInsetRect = new Rect();
     private final Rect mLastResizeRect = new Rect();
     private final WindowManagerProxy mWindowManagerProxy = WindowManagerProxy.getInstance();
     private Interpolator mFastOutSlowInInterpolator;
-    private final Interpolator mTouchResponseInterpolator =
-            new PathInterpolator(0.3f, 0f, 0.1f, 1f);
     private DividerWindowManager mWindowManager;
     private VelocityTracker mVelocityTracker;
     private FlingAnimationUtils mFlingAnimationUtils;
+    private DividerSnapAlgorithm mSnapAlgorithm;
+    private final Rect mStableInsets = new Rect();
 
     public DividerView(Context context) {
         super(context);
@@ -103,7 +127,7 @@
     @Override
     protected void onFinishInflate() {
         super.onFinishInflate();
-        mHandle = (ImageButton) findViewById(R.id.docked_divider_handle);
+        mHandle = (DividerHandleView) findViewById(R.id.docked_divider_handle);
         mBackground = findViewById(R.id.docked_divider_background);
         mHandle.setOnTouchListener(this);
         mDividerWindowWidth = getResources().getDimensionPixelSize(
@@ -115,6 +139,7 @@
                 R.dimen.docked_stack_divider_lift_elevation);
         mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(getContext(),
                 android.R.interpolator.fast_out_slow_in);
+        mTouchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
         mFlingAnimationUtils = new FlingAnimationUtils(getContext(), 0.3f);
         updateDisplayInfo();
         boolean landscape = getResources().getConfiguration().orientation
@@ -124,6 +149,13 @@
         getViewTreeObserver().addOnComputeInternalInsetsListener(this);
     }
 
+    @Override
+    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
+        mStableInsets.set(insets.getStableInsetLeft(), insets.getStableInsetTop(),
+                insets.getStableInsetRight(), insets.getStableInsetBottom());
+        return super.onApplyWindowInsets(insets);
+    }
+
     public void setWindowManager(DividerWindowManager windowManager) {
         mWindowManager = windowManager;
     }
@@ -132,8 +164,11 @@
         return mWindowManagerProxy;
     }
 
-    public boolean startDragging() {
+    public boolean startDragging(boolean animate) {
+        mHandle.setTouching(true, animate);
         mDockSide = mWindowManagerProxy.getDockSide();
+        mSnapAlgorithm = new DividerSnapAlgorithm(getContext(), mFlingAnimationUtils, mDisplayWidth,
+                mDisplayHeight, mDividerSize, isHorizontalDivision(), mStableInsets);
         if (mDockSide != WindowManager.DOCKED_INVALID) {
             mWindowManagerProxy.setResizing(true);
             mWindowManager.setSlippery(false);
@@ -145,11 +180,16 @@
     }
 
     public void stopDragging(int position, float velocity) {
+        mHandle.setTouching(false, true /* animate */);
         fling(position, velocity);
         mWindowManager.setSlippery(true);
         releaseBackground();
     }
 
+    public DividerSnapAlgorithm getSnapAlgorithm() {
+        return mSnapAlgorithm;
+    }
+
     @Override
     public boolean onTouch(View v, MotionEvent event) {
         convertToScreenCoordinates(event);
@@ -161,19 +201,31 @@
                 mStartX = (int) event.getX();
                 mStartY = (int) event.getY();
                 getLocationOnScreen(mTempInt2);
-                boolean result = startDragging();
+                boolean result = startDragging(true /* animate */);
                 if (isHorizontalDivision()) {
                     mStartPosition = mTempInt2[1] + mDividerInsets;
                 } else {
                     mStartPosition = mTempInt2[0] + mDividerInsets;
                 }
+                mMoving = false;
                 return result;
             case MotionEvent.ACTION_MOVE:
                 mVelocityTracker.addMovement(event);
                 int x = (int) event.getX();
                 int y = (int) event.getY();
-                if (mDockSide != WindowManager.DOCKED_INVALID) {
-                    resizeStack(calculatePosition(x, y));
+                boolean exceededTouchSlop =
+                        isHorizontalDivision() && Math.abs(y - mStartY) > mTouchSlop
+                                || (!isHorizontalDivision() && Math.abs(x - mStartX) > mTouchSlop);
+                if (!mMoving && exceededTouchSlop) {
+                    mStartX = x;
+                    mStartY = y;
+                    mMoving = true;
+                }
+                if (mMoving && mDockSide != WindowManager.DOCKED_INVALID) {
+                    int position = calculatePosition(x, y);
+                    SnapTarget snapTarget = mSnapAlgorithm.calculateSnapTarget(position,
+                            0 /* velocity */);
+                    resizeStack(calculatePosition(x, y), snapTarget.position, snapTarget);
                 }
                 break;
             case MotionEvent.ACTION_UP:
@@ -187,6 +239,7 @@
                 int position = calculatePosition(x, y);
                 stopDragging(position, isHorizontalDivision() ? mVelocityTracker.getYVelocity()
                         : mVelocityTracker.getXVelocity());
+                mMoving = false;
                 break;
         }
         return true;
@@ -197,14 +250,16 @@
     }
 
     private void fling(int position, float velocity) {
-        final SnapTarget snapTarget = new DividerSnapAlgorithm(getContext(), mFlingAnimationUtils,
-                mDividerSize, isHorizontalDivision()).calculateSnapTarget(position, velocity);
+        final SnapTarget snapTarget = mSnapAlgorithm.calculateSnapTarget(position, velocity);
 
         ValueAnimator anim = ValueAnimator.ofInt(position, snapTarget.position);
         anim.addUpdateListener(new AnimatorUpdateListener() {
             @Override
             public void onAnimationUpdate(ValueAnimator animation) {
-                resizeStack((Integer) animation.getAnimatedValue());
+                resizeStack((Integer) animation.getAnimatedValue(),
+                        animation.getAnimatedFraction() == 1f
+                                ? TASK_POSITION_SAME
+                                : snapTarget.position, snapTarget);
             }
         });
         anim.addListener(new AnimatorListenerAdapter() {
@@ -236,6 +291,7 @@
         } else {
             mWindowManagerProxy.maximizeDockedStack();
         }
+        mWindowManagerProxy.setResizeDimLayer(false, -1, 0f);
     }
 
     private void liftBackground() {
@@ -245,29 +301,33 @@
             mBackground.animate().scaleX(1.4f);
         }
         mBackground.animate()
-                .setInterpolator(mTouchResponseInterpolator)
-                .setDuration(150)
-                .translationZ(mTouchElevation);
+                .setInterpolator(TOUCH_RESPONSE_INTERPOLATOR)
+                .setDuration(TOUCH_ANIMATION_DURATION)
+                .translationZ(mTouchElevation)
+                .start();
 
         // Lift handle as well so it doesn't get behind the background, even though it doesn't
         // cast shadow.
         mHandle.animate()
-                .setInterpolator(mTouchResponseInterpolator)
-                .setDuration(150)
-                .translationZ(mTouchElevation);
+                .setInterpolator(TOUCH_RESPONSE_INTERPOLATOR)
+                .setDuration(TOUCH_ANIMATION_DURATION)
+                .translationZ(mTouchElevation)
+                .start();
     }
 
     private void releaseBackground() {
         mBackground.animate()
                 .setInterpolator(mFastOutSlowInInterpolator)
-                .setDuration(200)
+                .setDuration(TOUCH_RELEASE_ANIMATION_DURATION)
                 .translationZ(0)
                 .scaleX(1f)
-                .scaleY(1f);
+                .scaleY(1f)
+                .start();
         mHandle.animate()
                 .setInterpolator(mFastOutSlowInInterpolator)
-                .setDuration(200)
-                .translationZ(0);
+                .setDuration(TOUCH_RELEASE_ANIMATION_DURATION)
+                .translationZ(0)
+                .start();
     }
 
     @Override
@@ -332,17 +392,184 @@
         }
     }
 
-    public void resizeStack(int position) {
-        calculateBoundsForPosition(position, mDockSide, mTmpRect);
-        if (mTmpRect.equals(mLastResizeRect)) {
+    private int invertDockSide(int dockSide) {
+        switch (dockSide) {
+            case WindowManager.DOCKED_LEFT:
+                return WindowManager.DOCKED_RIGHT;
+            case WindowManager.DOCKED_TOP:
+                return WindowManager.DOCKED_BOTTOM;
+            case WindowManager.DOCKED_RIGHT:
+                return WindowManager.DOCKED_LEFT;
+            case WindowManager.DOCKED_BOTTOM:
+                return WindowManager.DOCKED_TOP;
+            default:
+                return WindowManager.DOCKED_INVALID;
+        }
+    }
+
+    private void alignTopLeft(Rect containingRect, Rect rect) {
+        int width = rect.width();
+        int height = rect.height();
+        rect.set(containingRect.left, containingRect.top,
+                containingRect.left + width, containingRect.top + height);
+    }
+
+    private void alignBottomRight(Rect containingRect, Rect rect) {
+        int width = rect.width();
+        int height = rect.height();
+        rect.set(containingRect.right - width, containingRect.bottom - height,
+                containingRect.right, containingRect.bottom);
+    }
+
+    public void resizeStack(int position, int taskPosition, SnapTarget taskSnapTarget) {
+        calculateBoundsForPosition(position, mDockSide, mDockedRect);
+
+        if (mDockedRect.equals(mLastResizeRect)) {
             return;
         }
 
         // Make sure shadows are updated
         mBackground.invalidate();
 
-        mLastResizeRect.set(mTmpRect);
-        mWindowManagerProxy.resizeDockedStack(mTmpRect);
+        mLastResizeRect.set(mDockedRect);
+        if (taskPosition != TASK_POSITION_SAME) {
+            calculateBoundsForPosition(position, invertDockSide(mDockSide), mOtherRect);
+            int dockSideInverted = invertDockSide(mDockSide);
+            int taskPositionDocked =
+                    restrictDismissingTaskPosition(taskPosition, mDockSide, taskSnapTarget);
+            int taskPositionOther =
+                    restrictDismissingTaskPosition(taskPosition, dockSideInverted, taskSnapTarget);
+            calculateBoundsForPosition(taskPositionDocked, mDockSide, mDockedTaskRect);
+            calculateBoundsForPosition(taskPositionOther, dockSideInverted, mOtherTaskRect);
+            alignTopLeft(mDockedRect, mDockedTaskRect);
+            alignTopLeft(mOtherRect, mOtherTaskRect);
+            mDockedInsetRect.set(mDockedTaskRect);
+            mOtherInsetRect.set(mOtherTaskRect);
+            if (dockSideTopLeft(mDockSide)) {
+                alignTopLeft(mDockedRect, mDockedInsetRect);
+                alignBottomRight(mOtherRect, mOtherInsetRect);
+            } else {
+                alignBottomRight(mDockedRect, mDockedInsetRect);
+                alignTopLeft(mOtherRect, mOtherInsetRect);
+            }
+            applyDismissingParallax(mDockedTaskRect, mDockSide, taskSnapTarget, position,
+                    taskPositionDocked);
+            applyDismissingParallax(mOtherTaskRect, dockSideInverted, taskSnapTarget, position,
+                    taskPositionOther);
+            mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, mDockedInsetRect,
+                    mOtherTaskRect, mOtherInsetRect);
+        } else {
+            mWindowManagerProxy.resizeDockedStack(mDockedRect, null, null, null, null);
+        }
+        float fraction = mSnapAlgorithm.calculateDismissingFraction(position);
+        fraction = Math.max(0,
+                Math.min((fraction / DIM_START_FRACTION - 1f) / DIM_DAMP_FACTOR, 1f));
+        mWindowManagerProxy.setResizeDimLayer(fraction != 0f,
+                getStackIdForDismissTarget(mSnapAlgorithm.getClosestDismissTarget(position)),
+                fraction);
+    }
+
+    /**
+     * When the snap target is dismissing one side, make sure that the dismissing side doesn't get
+     * 0 size.
+     */
+    private int restrictDismissingTaskPosition(int taskPosition, int dockSide,
+            SnapTarget snapTarget) {
+        if (snapTarget.flag == SnapTarget.FLAG_DISMISS_START && dockSideTopLeft(dockSide)) {
+            return mSnapAlgorithm.getFirstSplitTarget().position;
+        } else if (snapTarget.flag == SnapTarget.FLAG_DISMISS_END
+                && dockSideBottomRight(dockSide)) {
+            return mSnapAlgorithm.getLastSplitTarget().position;
+        } else {
+            return taskPosition;
+        }
+    }
+
+    /**
+     * Applies a parallax to the task when dismissing.
+     */
+    private void applyDismissingParallax(Rect taskRect, int dockSide, SnapTarget snapTarget,
+            int position, int taskPosition) {
+        float fraction = Math.min(1, Math.max(0,
+                mSnapAlgorithm.calculateDismissingFraction(position)));
+        SnapTarget dismissTarget = null;
+        SnapTarget splitTarget = null;
+        if ((snapTarget.flag == SnapTarget.FLAG_DISMISS_START
+                || snapTarget == mSnapAlgorithm.getFirstSplitTarget())
+                && dockSideTopLeft(dockSide)) {
+            dismissTarget = mSnapAlgorithm.getDismissStartTarget();
+            splitTarget = mSnapAlgorithm.getFirstSplitTarget();
+        } else if ((snapTarget.flag == SnapTarget.FLAG_DISMISS_END
+                || snapTarget == mSnapAlgorithm.getLastSplitTarget())
+                && dockSideBottomRight(dockSide)) {
+            dismissTarget = mSnapAlgorithm.getDismissEndTarget();
+            splitTarget = mSnapAlgorithm.getLastSplitTarget();
+        }
+        if (dismissTarget != null && fraction > 0f
+                && isDismissing(splitTarget, position, dockSide)) {
+            fraction = calculateParallaxDismissingFraction(fraction);
+            int offsetPosition = (int) (taskPosition +
+                    fraction * (dismissTarget.position - splitTarget.position));
+            int width = taskRect.width();
+            int height = taskRect.height();
+            switch (dockSide) {
+                case WindowManager.DOCKED_LEFT:
+                    taskRect.left = offsetPosition - width;
+                    taskRect.right = offsetPosition;
+                    break;
+                case WindowManager.DOCKED_RIGHT:
+                    taskRect.left = offsetPosition + mDividerSize;
+                    taskRect.right = offsetPosition + width + mDividerSize;
+                    break;
+                case WindowManager.DOCKED_TOP:
+                    taskRect.top = offsetPosition - height;
+                    taskRect.bottom = offsetPosition;
+                    break;
+                case WindowManager.DOCKED_BOTTOM:
+                    taskRect.top = offsetPosition + mDividerSize;
+                    taskRect.bottom = offsetPosition + height + mDividerSize;
+                    break;
+            }
+        }
+    }
+
+    /**
+     * @return for a specified {@code fraction}, this returns an adjusted value that simulates a
+     *         slowing down parallax effect
+     */
+    private static float calculateParallaxDismissingFraction(float fraction) {
+        return SLOWDOWN_INTERPOLATOR.getInterpolation(fraction) / 3.5f;
+    }
+
+    private static boolean isDismissing(SnapTarget snapTarget, int position, int dockSide) {
+        if (dockSide == WindowManager.DOCKED_TOP || dockSide == WindowManager.DOCKED_LEFT) {
+            return position < snapTarget.position;
+        } else {
+            return position > snapTarget.position;
+        }
+    }
+
+    private int getStackIdForDismissTarget(SnapTarget dismissTarget) {
+        if (dismissTarget.flag == SnapTarget.FLAG_DISMISS_START &&
+                (mDockSide == WindowManager.DOCKED_LEFT || mDockSide == WindowManager.DOCKED_TOP)) {
+            return StackId.DOCKED_STACK_ID;
+        } else {
+            return StackId.FULLSCREEN_WORKSPACE_STACK_ID;
+        }
+    }
+
+    /**
+     * @return true if and only if {@code dockSide} is top or left
+     */
+    private static boolean dockSideTopLeft(int dockSide) {
+        return dockSide == WindowManager.DOCKED_TOP || dockSide == WindowManager.DOCKED_LEFT;
+    }
+
+    /**
+     * @return true if and only if {@code dockSide} is bottom or right
+     */
+    private static boolean dockSideBottomRight(int dockSide) {
+        return dockSide == WindowManager.DOCKED_BOTTOM || dockSide == WindowManager.DOCKED_RIGHT;
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerWindowManager.java b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerWindowManager.java
index 2251874..161f873 100644
--- a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerWindowManager.java
+++ b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerWindowManager.java
@@ -50,6 +50,9 @@
                         | FLAG_WATCH_OUTSIDE_TOUCH | FLAG_SPLIT_TOUCH | FLAG_SLIPPERY,
                 PixelFormat.TRANSLUCENT);
         mLp.setTitle(WINDOW_TITLE);
+        view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
         mWindowManager.addView(view, mLp);
         mView = view;
     }
diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/WindowManagerProxy.java b/packages/SystemUI/src/com/android/systemui/stackdivider/WindowManagerProxy.java
index ef47d8d..2791dfc 100644
--- a/packages/SystemUI/src/com/android/systemui/stackdivider/WindowManagerProxy.java
+++ b/packages/SystemUI/src/com/android/systemui/stackdivider/WindowManagerProxy.java
@@ -40,18 +40,41 @@
     private static final WindowManagerProxy sInstance = new WindowManagerProxy();
 
     @GuardedBy("mResizeRect")
-    private final Rect mResizeRect = new Rect();
-    private final Rect mTmpRect = new Rect();
+    private final Rect mDockedRect = new Rect();
+    private final Rect mTempDockedTaskRect = new Rect();
+    private final Rect mTempDockedInsetRect = new Rect();
+    private final Rect mTempOtherTaskRect = new Rect();
+    private final Rect mTempOtherInsetRect = new Rect();
+
+    private final Rect mTmpRect1 = new Rect();
+    private final Rect mTmpRect2 = new Rect();
+    private final Rect mTmpRect3 = new Rect();
+    private final Rect mTmpRect4 = new Rect();
+    private final Rect mTmpRect5 = new Rect();
+
+    private boolean mDimLayerVisible;
+    private int mDimLayerTargetStack;
+    private float mDimLayerAlpha;
+
     private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
 
     private final Runnable mResizeRunnable = new Runnable() {
         @Override
         public void run() {
-            synchronized (mResizeRect) {
-                mTmpRect.set(mResizeRect);
+            synchronized (mDockedRect) {
+                mTmpRect1.set(mDockedRect);
+                mTmpRect2.set(mTempDockedTaskRect);
+                mTmpRect3.set(mTempDockedInsetRect);
+                mTmpRect4.set(mTempOtherTaskRect);
+                mTmpRect5.set(mTempOtherInsetRect);
             }
             try {
-                ActivityManagerNative.getDefault().resizeStack(DOCKED_STACK_ID, mTmpRect, true);
+                ActivityManagerNative.getDefault()
+                        .resizeDockedStack(mTmpRect1,
+                                mTmpRect2.isEmpty() ? null : mTmpRect2,
+                                mTmpRect3.isEmpty() ? null : mTmpRect3,
+                                mTmpRect4.isEmpty() ? null : mTmpRect4,
+                                mTmpRect5.isEmpty() ? null : mTmpRect5);
             } catch (RemoteException e) {
                 Log.w(TAG, "Failed to resize stack: " + e);
             }
@@ -80,6 +103,18 @@
         }
     };
 
+    private final Runnable mDimLayerRunnable = new Runnable() {
+        @Override
+        public void run() {
+            try {
+                WindowManagerGlobal.getWindowManagerService().setResizeDimLayer(mDimLayerVisible,
+                        mDimLayerTargetStack, mDimLayerAlpha);
+            } catch (RemoteException e) {
+                Log.w(TAG, "Failed to resize stack: " + e);
+            }
+        }
+    };
+
     private WindowManagerProxy() {
     }
 
@@ -87,9 +122,30 @@
         return sInstance;
     }
 
-    public void resizeDockedStack(Rect rect) {
-        synchronized (mResizeRect) {
-            mResizeRect.set(rect);
+    public void resizeDockedStack(Rect docked, Rect tempDockedTaskRect, Rect tempDockedInsetRect,
+            Rect tempOtherTaskRect, Rect tempOtherInsetRect) {
+        synchronized (mDockedRect) {
+            mDockedRect.set(docked);
+            if (tempDockedTaskRect != null) {
+                mTempDockedTaskRect.set(tempDockedTaskRect);
+            } else {
+                mTempDockedTaskRect.setEmpty();
+            }
+            if (tempDockedInsetRect != null) {
+                mTempDockedInsetRect.set(tempDockedInsetRect);
+            } else {
+                mTempDockedInsetRect.setEmpty();
+            }
+            if (tempOtherTaskRect != null) {
+                mTempOtherTaskRect.set(tempOtherTaskRect);
+            } else {
+                mTempOtherTaskRect.setEmpty();
+            }
+            if (tempOtherInsetRect != null) {
+                mTempOtherInsetRect.set(tempOtherInsetRect);
+            } else {
+                mTempOtherInsetRect.setEmpty();
+            }
         }
         mExecutor.execute(mResizeRunnable);
     }
@@ -123,4 +179,11 @@
         }
         return DOCKED_INVALID;
     }
+
+    public void setResizeDimLayer(boolean visible, int targetStackId, float alpha) {
+        mDimLayerVisible = visible;
+        mDimLayerTargetStack = targetStackId;
+        mDimLayerAlpha = alpha;
+        mExecutor.execute(mDimLayerRunnable);
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
index 1d7651c..fdfce6c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
@@ -16,8 +16,6 @@
 
 package com.android.systemui.statusbar;
 
-import static  android.service.notification.NotificationListenerService.Ranking.IMPORTANCE_MAX;
-
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.animation.TimeInterpolator;
@@ -80,11 +78,8 @@
 import android.view.WindowManagerGlobal;
 import android.view.accessibility.AccessibilityManager;
 import android.view.animation.AnimationUtils;
-import android.widget.DateTimeView;
-import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.RemoteViews;
-import android.widget.SeekBar;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -116,6 +111,7 @@
 import java.util.List;
 import java.util.Locale;
 
+import static android.service.notification.NotificationListenerService.Ranking.IMPORTANCE_MAX;
 import static com.android.keyguard.KeyguardHostView.OnDismissAction;
 
 public abstract class BaseStatusBar extends SystemUI implements
@@ -126,9 +122,6 @@
     public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
     public static final boolean MULTIUSER_DEBUG = false;
 
-    // STOPSHIP disable once we resolve b/18102199
-    private static final boolean NOTIFICATION_CLICK_DEBUG = true;
-
     public static final boolean ENABLE_REMOTE_INPUT =
             SystemProperties.getBoolean("debug.enable_remote_input", true);
     public static final boolean ENABLE_CHILD_NOTIFICATIONS
@@ -141,15 +134,14 @@
     protected static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 1023;
     protected static final int MSG_SHOW_NEXT_AFFILIATED_TASK = 1024;
     protected static final int MSG_SHOW_PREV_AFFILIATED_TASK = 1025;
-    protected static final int MSG_SHOW_KEYBOARD_SHORTCUTS_MENU = 1026;
+    protected static final int MSG_TOGGLE_KEYBOARD_SHORTCUTS_MENU = 1026;
 
     protected static final boolean ENABLE_HEADS_UP = true;
-    // scores above this threshold should be displayed in heads up mode.
-    protected static final int INTERRUPTION_THRESHOLD = 10;
     protected static final String SETTING_HEADS_UP_TICKER = "ticker_gets_heads_up";
 
-    // Should match the value in PhoneWindowManager
+    // Should match the values in PhoneWindowManager
     public static final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
+    public static final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
 
     private static final String BANNER_ACTION_CANCEL =
             "com.android.systemui.statusbar.banner_action_cancel";
@@ -199,14 +191,10 @@
     protected IDreamManager mDreamManager;
     PowerManager mPowerManager;
     protected StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
-    protected int mRowMinHeightLegacy;
-    protected int mRowMinHeight;
-    protected int mRowMaxHeight;
 
     // public mode, private notifications, etc
     private boolean mLockscreenPublicMode = false;
     private final SparseBooleanArray mUsersAllowingPrivateNotifications = new SparseBooleanArray();
-    private NotificationColorUtil mNotificationColorUtil;
 
     private UserManager mUserManager;
 
@@ -236,6 +224,8 @@
 
     private TimeInterpolator mLinearOutSlowIn, mFastOutLinearIn;
 
+    private KeyboardShortcuts mKeyboardShortcuts;
+
     /**
      * The {@link StatusBarState} of the status bar.
      */
@@ -356,9 +346,6 @@
                 ViewGroup actionGroup = (ViewGroup) parent;
                 index = actionGroup.indexOfChild(view);
             }
-            if (NOTIFICATION_CLICK_DEBUG) {
-                Log.d(TAG, "Clicked on button " + index + " for " + key);
-            }
             try {
                 mBarService.onNotificationActionClick(key, index);
             } catch (RemoteException e) {
@@ -616,8 +603,6 @@
         mDevicePolicyManager = (DevicePolicyManager)mContext.getSystemService(
                 Context.DEVICE_POLICY_SERVICE);
 
-        mNotificationColorUtil = NotificationColorUtil.getInstance(mContext);
-
         mNotificationData = new NotificationData(this);
 
         mAccessibilityManager = (AccessibilityManager)
@@ -970,7 +955,7 @@
         ((ImageView) row.findViewById(android.R.id.icon)).setImageDrawable(pkgicon);
         ((TextView) row.findViewById(R.id.pkgname)).setText(appname);
 
-        final View settingsButton = guts.findViewById(R.id.notification_inspect_item);
+        final View settingsButton = guts.findViewById(R.id.more_settings);
         if (appUid >= 0) {
             final int appUidF = appUid;
             settingsButton.setOnClickListener(new View.OnClickListener() {
@@ -983,6 +968,14 @@
             settingsButton.setVisibility(View.GONE);
         }
 
+        row.findViewById(R.id.done).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                guts.saveImportance(sbn);
+                dismissPopups();
+            }
+        });
+
         guts.bindImportance(sbn, row, mNotificationData.getImportance(sbn.getKey()));
     }
 
@@ -1110,8 +1103,8 @@
     }
 
     @Override
-    public void showKeyboardShortcutsMenu() {
-        int msg = MSG_SHOW_KEYBOARD_SHORTCUTS_MENU;
+    public void toggleKeyboardShortcutsMenu() {
+        int msg = MSG_TOGGLE_KEYBOARD_SHORTCUTS_MENU;
         mHandler.removeMessages(msg);
         mHandler.sendEmptyMessage(msg);
     }
@@ -1134,7 +1127,7 @@
          return new H();
     }
 
-    static void sendCloseSystemWindows(Context context, String reason) {
+    protected void sendCloseSystemWindows(String reason) {
         if (ActivityManagerNative.isSystemReady()) {
             try {
                 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
@@ -1169,7 +1162,7 @@
 
     protected void showRecents(boolean triggeredFromAltTab) {
         if (mRecents != null) {
-            sendCloseSystemWindows(mContext, SYSTEM_DIALOG_REASON_RECENT_APPS);
+            sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
             mRecents.showRecents(triggeredFromAltTab, getStatusBarView());
         }
     }
@@ -1182,7 +1175,6 @@
 
     protected void toggleRecents() {
         if (mRecents != null) {
-            sendCloseSystemWindows(mContext, SYSTEM_DIALOG_REASON_RECENT_APPS);
             mRecents.toggleRecents(mDisplay, mLayoutDirection, getStatusBarView());
         }
     }
@@ -1193,8 +1185,8 @@
         }
     }
 
-    protected void showKeyboardShortcuts() {
-        Toast.makeText(mContext, "Show keyboard shortcuts screen", Toast.LENGTH_LONG).show();
+    protected void toggleKeyboardShortcuts() {
+        getKeyboardShortcuts().toggleKeyboardShortcuts(mContext);
     }
 
     protected void cancelPreloadingRecents() {
@@ -1317,8 +1309,8 @@
              case MSG_SHOW_PREV_AFFILIATED_TASK:
                   showRecentsPreviousAffiliatedTask();
                   break;
-             case MSG_SHOW_KEYBOARD_SHORTCUTS_MENU:
-                  showKeyboardShortcuts();
+             case MSG_TOGGLE_KEYBOARD_SHORTCUTS_MENU:
+                  toggleKeyboardShortcuts();
                   break;
             }
         }
@@ -1524,6 +1516,14 @@
         }
     }
 
+    protected KeyboardShortcuts getKeyboardShortcuts() {
+        if (mKeyboardShortcuts == null) {
+            mKeyboardShortcuts = new KeyboardShortcuts();
+        }
+
+        return mKeyboardShortcuts;
+    }
+
     public void startPendingIntentDismissingKeyguard(final PendingIntent intent) {
         if (!isDeviceProvisioned()) return;
 
@@ -1606,9 +1606,6 @@
                 }
             });
 
-            if (NOTIFICATION_CLICK_DEBUG) {
-                Log.d(TAG, "Clicked on content of " + notificationKey);
-            }
             final boolean keyguardShowing = mStatusBarKeyguardViewManager.isShowing();
             final boolean afterKeyguardGone = intent.isActivity()
                     && PreviewInflater.wouldLaunchResolverActivity(mContext, intent.getIntent(),
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
index deedae0..5a2758d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -65,7 +65,7 @@
     private static final int MSG_ASSIST_DISCLOSURE          = 22 << MSG_SHIFT;
     private static final int MSG_START_ASSIST               = 23 << MSG_SHIFT;
     private static final int MSG_CAMERA_LAUNCH_GESTURE      = 24 << MSG_SHIFT;
-    private static final int MSG_SHOW_KEYBOARD_SHORTCUTS    = 25 << MSG_SHIFT;
+    private static final int MSG_TOGGLE_KEYBOARD_SHORTCUTS  = 25 << MSG_SHIFT;
 
     public static final int FLAG_EXCLUDE_NONE = 0;
     public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
@@ -100,7 +100,7 @@
         public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey);
         public void toggleRecentApps();
         public void preloadRecentApps();
-        public void showKeyboardShortcutsMenu();
+        public void toggleKeyboardShortcutsMenu();
         public void cancelPreloadRecentApps();
         public void setWindowState(int window, int state);
         public void buzzBeepBlinked();
@@ -229,10 +229,10 @@
     }
 
     @Override
-    public void showKeyboardShortcutsMenu() {
+    public void toggleKeyboardShortcutsMenu() {
         synchronized (mList) {
-            mHandler.removeMessages(MSG_SHOW_KEYBOARD_SHORTCUTS);
-            mHandler.obtainMessage(MSG_SHOW_KEYBOARD_SHORTCUTS).sendToTarget();
+            mHandler.removeMessages(MSG_TOGGLE_KEYBOARD_SHORTCUTS);
+            mHandler.obtainMessage(MSG_TOGGLE_KEYBOARD_SHORTCUTS).sendToTarget();
         }
     }
 
@@ -380,8 +380,8 @@
                 case MSG_CANCEL_PRELOAD_RECENT_APPS:
                     mCallbacks.cancelPreloadRecentApps();
                     break;
-                case MSG_SHOW_KEYBOARD_SHORTCUTS:
-                    mCallbacks.showKeyboardShortcutsMenu();
+                case MSG_TOGGLE_KEYBOARD_SHORTCUTS:
+                    mCallbacks.toggleKeyboardShortcutsMenu();
                     break;
                 case MSG_SET_WINDOW_STATE:
                     mCallbacks.setWindowState(msg.arg1, msg.arg2);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java
new file mode 100644
index 0000000..3e0ea90
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.systemui.statusbar;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.graphics.drawable.ColorDrawable;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+
+import com.android.systemui.R;
+
+/**
+ * Contains functionality for handling keyboard shortcuts.
+ */
+public class KeyboardShortcuts {
+    private Dialog mKeyboardShortcutsDialog;
+
+    public KeyboardShortcuts() {}
+
+    public void toggleKeyboardShortcuts(Context context) {
+        if (mKeyboardShortcutsDialog == null) {
+            // Create dialog.
+            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
+            LayoutInflater inflater = (LayoutInflater) context.getSystemService(
+                    Context.LAYOUT_INFLATER_SERVICE);
+            final View keyboardShortcutsView = inflater.inflate(
+                    R.layout.keyboard_shortcuts_view, null);
+
+            populateKeyboardShortcuts(keyboardShortcutsView.findViewById(
+                    R.id.keyboard_shortcuts_wrapper));
+            dialogBuilder.setView(keyboardShortcutsView);
+            mKeyboardShortcutsDialog = dialogBuilder.create();
+            mKeyboardShortcutsDialog.setCanceledOnTouchOutside(true);
+
+            // Setup window.
+            Window keyboardShortcutsWindow = mKeyboardShortcutsDialog.getWindow();
+            keyboardShortcutsWindow.setType(
+                    WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
+            keyboardShortcutsWindow.setBackgroundDrawable(
+                    new ColorDrawable(android.graphics.Color.TRANSPARENT));
+            keyboardShortcutsWindow.setGravity(Gravity.TOP);
+            mKeyboardShortcutsDialog.show();
+        } else {
+            dismissKeyboardShortcutsDialog();
+        }
+    }
+
+    public void dismissKeyboardShortcutsDialog() {
+        if (mKeyboardShortcutsDialog != null) {
+            mKeyboardShortcutsDialog.dismiss();
+            mKeyboardShortcutsDialog = null;
+        }
+    }
+
+    /**
+     * @return {@code true} if the keyboard shortcuts have been successfully populated.
+     */
+    private boolean populateKeyboardShortcuts(View keyboardShortcutsLayout) {
+        // TODO: Populate shortcuts.
+        return true;
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java
index f7680a7..3cc1ab9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java
@@ -292,6 +292,15 @@
         return false;
     }
 
+    public boolean shouldSuppressScreenOn(String key) {
+        if (mRankingMap != null) {
+            mRankingMap.getRanking(key, mTmpRanking);
+            return (mTmpRanking.getSuppressedVisualEffects()
+                    & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_ON) != 0;
+        }
+        return false;
+    }
+
     public int getImportance(String key) {
         if (mRankingMap != null) {
             mRankingMap.getRanking(key, mTmpRanking);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java
index 6850f7e..20a6e7c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java
@@ -46,6 +46,10 @@
     private int mClipTopAmount;
     private int mActualHeight;
     private boolean mExposed;
+    private RadioButton mApplyToTopic;
+    private SeekBar mSeekBar;
+    private Notification.Topic mTopic;
+    private INotificationManager mINotificationManager;
 
     public NotificationGuts(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -98,67 +102,39 @@
 
     void bindImportance(final StatusBarNotification sbn, final ExpandableNotificationRow row,
             final int importance) {
-        final INotificationManager sINM = INotificationManager.Stub.asInterface(
+        mINotificationManager = INotificationManager.Stub.asInterface(
                 ServiceManager.getService(Context.NOTIFICATION_SERVICE));
-        final Notification.Topic topic = sbn.getNotification().getTopic() == null
+        mTopic = sbn.getNotification().getTopic() == null
                 ? new Notification.Topic(Notification.TOPIC_DEFAULT, mContext.getString(
                 com.android.internal.R.string.default_notification_topic_label))
                 : sbn.getNotification().getTopic();
         boolean doesAppUseTopics = false;
         try {
-            doesAppUseTopics = sINM.doesAppUseTopics(sbn.getPackageName(), sbn.getUid());
+            doesAppUseTopics =
+                    mINotificationManager.doesAppUseTopics(sbn.getPackageName(), sbn.getUid());
         } catch (RemoteException e) {}
         final boolean appUsesTopics = doesAppUseTopics;
 
-        final RadioButton applyToTopic = (RadioButton) row.findViewById(R.id.apply_to_topic);
-        applyToTopic.setChecked(true);
+        mApplyToTopic = (RadioButton) row.findViewById(R.id.apply_to_topic);
+        if (appUsesTopics) {
+            mApplyToTopic.setChecked(true);
+        }
         final View applyToApp = row.findViewById(R.id.apply_to_app);
         final TextView topicSummary = ((TextView) row.findViewById(R.id.summary));
         final TextView topicTitle = ((TextView) row.findViewById(R.id.title));
-        final SeekBar seekBar = (SeekBar) row.findViewById(R.id.seekbar);
-        final RadioGroup applyTo = (RadioGroup) row.findViewById(R.id.apply_to);
-        applyTo.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
-            @Override
-            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
-                try {
-                    switch (checkedId) {
-                        case R.id.apply_to_topic:
-                            sINM.setTopicImportance(sbn.getPackageName(), sbn.getUid(), topic,
-                                    seekBar.getProgress());
-                            break;
-                        default:
-                            sINM.setAppImportance(sbn.getPackageName(), sbn.getUid(),
-                                    seekBar.getProgress());
-                    }
-                } catch (RemoteException e) {
-                    // :(
-                }
-            }
-        });
-
-        seekBar.setMax(4);
-        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+        mSeekBar = (SeekBar) row.findViewById(R.id.seekbar);
+        mSeekBar.setMax(4);
+        mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
             @Override
             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                 updateTitleAndSummary(progress);
                 if (fromUser) {
                     if (appUsesTopics) {
-                        applyToTopic.setVisibility(View.VISIBLE);
-
-                        applyToTopic.setText(
-                                mContext.getString(R.string.apply_to_topic, topic.getLabel()));
+                        mApplyToTopic.setVisibility(View.VISIBLE);
+                        mApplyToTopic.setText(
+                                mContext.getString(R.string.apply_to_topic, mTopic.getLabel()));
                         applyToApp.setVisibility(View.VISIBLE);
                     }
-                    try {
-                        if (applyToTopic.isChecked()) {
-                            sINM.setTopicImportance(sbn.getPackageName(), sbn.getUid(), topic,
-                                    progress);
-                        } else {
-                            sINM.setAppImportance(sbn.getPackageName(), sbn.getUid(), progress);
-                        }
-                    } catch (RemoteException e) {
-                        // :(
-                    }
                 }
             }
 
@@ -202,7 +178,22 @@
                 }
             }
         });
-        seekBar.setProgress(importance);
+        mSeekBar.setProgress(importance);
+    }
+
+    void saveImportance(final StatusBarNotification sbn) {
+        int progress = mSeekBar.getProgress();
+        try {
+            if (mApplyToTopic.isChecked()) {
+                mINotificationManager.setTopicImportance(sbn.getPackageName(), sbn.getUid(), mTopic,
+                        progress);
+            } else {
+                mINotificationManager.setAppImportance(
+                        sbn.getPackageName(), sbn.getUid(), progress);
+            }
+        } catch (RemoteException e) {
+            // :(
+        }
     }
 
     public void setActualHeight(int actualHeight) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java b/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java
index f243b00..d7e47c2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java
@@ -30,11 +30,11 @@
 public class RemoteInputController {
 
     private final ArrayList<WeakReference<NotificationData.Entry>> mRemoteInputs = new ArrayList<>();
-    private final StatusBarWindowManager mStatusBarWindowManager;
+    private final ArrayList<Callback> mCallbacks = new ArrayList<>(3);
     private final HeadsUpManager mHeadsUpManager;
 
     public RemoteInputController(StatusBarWindowManager sbwm, HeadsUpManager headsUpManager) {
-        mStatusBarWindowManager = sbwm;
+        addCallback(sbwm);
         mHeadsUpManager = headsUpManager;
     }
 
@@ -59,8 +59,12 @@
     }
 
     private void apply(NotificationData.Entry entry) {
-        mStatusBarWindowManager.setRemoteInputActive(isRemoteInputActive());
         mHeadsUpManager.setRemoteInputActive(entry, isRemoteInputActive(entry));
+        boolean remoteInputActive = isRemoteInputActive();
+        int N = mCallbacks.size();
+        for (int i = 0; i < N; i++) {
+            mCallbacks.get(i).onRemoteInputActive(remoteInputActive);
+        }
     }
 
     /**
@@ -99,4 +103,12 @@
     }
 
 
+    public void addCallback(Callback callback) {
+        Preconditions.checkNotNull(callback);
+        mCallbacks.add(callback);
+    }
+
+    public interface Callback {
+        void onRemoteInputActive(boolean active);
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/car/CarNavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarNavigationBarView.java
new file mode 100644
index 0000000..5c0f38c
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarNavigationBarView.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.car;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.R.color;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.View;
+import android.widget.ImageButton;
+import android.widget.ImageView.ScaleType;
+import android.widget.LinearLayout;
+
+import com.android.systemui.R;
+import com.android.systemui.statusbar.phone.ActivityStarter;
+import com.android.systemui.statusbar.phone.NavigationBarView;
+import com.android.systemui.statusbar.phone.NavigationBarGestureHelper;
+import com.android.systemui.statusbar.policy.KeyButtonView;
+
+import java.net.URISyntaxException;
+
+/**
+ * A custom navigation bar for the automotive use case.
+ * <p>
+ * The navigation bar in the automotive use case is more like a list of shortcuts, which we
+ * expect to be customizable by the car OEMs. This implementation populates the nav_buttons layout
+ * from resources rather than the layout file so customization would then mean updating
+ * arrays_car.xml appropriately in an overlay.
+ */
+class CarNavigationBarView extends NavigationBarView {
+    private ActivityStarter mActivityStarter;
+
+    public CarNavigationBarView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    @Override
+    public void onFinishInflate() {
+        // Read up arrays_car.xml and populate the navigation bar here.
+        Context context = getContext();
+        Resources r = getContext().getResources();
+        TypedArray icons = r.obtainTypedArray(R.array.car_shortcut_icons);
+        TypedArray intents = r.obtainTypedArray(R.array.car_shortcut_intent_uris);
+        TypedArray longpressIntents =
+                r.obtainTypedArray(R.array.car_shortcut_longpress_intent_uris);
+
+        if (icons.length() != intents.length()) {
+            throw new RuntimeException("car_shortcut_icons and car_shortcut_intents do not match");
+        }
+
+        LinearLayout navButtons = (LinearLayout) findViewById(R.id.nav_buttons);
+        LinearLayout lightsOut = (LinearLayout) findViewById(R.id.lights_out);
+
+        for (int i = 0; i < icons.length(); i++) {
+            Drawable icon = icons.getDrawable(i);
+
+            try {
+                Intent intent = Intent.parseUri(intents.getString(i), Intent.URI_INTENT_SCHEME);
+                Intent longpress = null;
+                String longpressUri = longpressIntents.getString(i);
+                if (!longpressUri.isEmpty()) {
+                    longpress = Intent.parseUri(longpressUri, Intent.URI_INTENT_SCHEME);
+                }
+
+                // nav_buttons and lights_out should match exactly.
+                navButtons.addView(makeButton(context, icon, intent, longpress));
+                lightsOut.addView(makeButton(context, icon, intent, longpress));
+            } catch (URISyntaxException e) {
+                throw new RuntimeException("Malformed intent uri", e);
+            }
+        }
+    }
+
+    private ImageButton makeButton(Context context, Drawable icon,
+            final Intent intent, final Intent longpress) {
+        ImageButton button = new ImageButton(context);
+
+        button.setImageDrawable(icon);
+        button.setScaleType(ScaleType.CENTER);
+        button.setBackgroundColor(color.transparent);
+        LinearLayout.LayoutParams lp =
+                new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
+        button.setLayoutParams(lp);
+
+        button.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                if (mActivityStarter != null) {
+                    mActivityStarter.startActivity(intent, true);
+                }
+            }
+        });
+
+        // Long click handlers are optional.
+        if (longpress != null) {
+            button.setLongClickable(true);
+            button.setOnLongClickListener(new OnLongClickListener() {
+                @Override
+                public boolean onLongClick(View v) {
+                    if (mActivityStarter != null) {
+                        mActivityStarter.startActivity(longpress, true);
+                        return true;
+                    }
+                    return false;
+                }
+            });
+        } else {
+            button.setLongClickable(false);
+        }
+
+        return button;
+    }
+
+    public void setActivityStarter(ActivityStarter activityStarter) {
+        mActivityStarter = activityStarter;
+    }
+
+    @Override
+    public void setDisabledFlags(int disabledFlags, boolean force) {
+        // TODO: Populate.
+    }
+
+    @Override
+    public void reorient() {
+        // We expect the car head unit to always have a fixed rotation so we ignore this. The super
+        // class implentation expects mRotatedViews to be populated, so if you call into it, there
+        // is a possibility of a NullPointerException.
+    }
+
+    @Override
+    public View getCurrentView() {
+        return this;
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
new file mode 100644
index 0000000..a72b5d0
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.car;
+
+import android.content.Context;
+import android.graphics.PixelFormat;
+import android.view.View;
+import android.view.ViewGroup.LayoutParams;
+import android.view.WindowManager;
+
+import com.android.systemui.R;
+import com.android.systemui.statusbar.phone.PhoneStatusBar;
+
+/**
+ * A status bar (and navigation bar) tailored for the automotive use case.
+ */
+public class CarStatusBar extends PhoneStatusBar {
+    @Override
+    protected void addNavigationBar() {
+        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
+                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
+                WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
+                    WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
+                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
+                    | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
+                    | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
+                    | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
+                    | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
+                PixelFormat.TRANSLUCENT);
+        lp.setTitle("CarNavigationBar");
+        lp.windowAnimations = 0;
+        mWindowManager.addView(mNavigationBarView, lp);
+    }
+
+    @Override
+    protected void createNavigationBarView(Context context) {
+        if (mNavigationBarView != null) {
+            return;
+        }
+
+        CarNavigationBarView carNavBar =
+                (CarNavigationBarView) View.inflate(context, R.layout.car_navigation_bar, null);
+        carNavBar.setActivityStarter(this);
+        mNavigationBarView = carNavBar;
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarApps.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarApps.java
index 58c9722..d0c14f1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarApps.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarApps.java
@@ -746,7 +746,7 @@
         // Launch or bring the activity to front.
         final IActivityManager iAm = ActivityManagerNative.getDefault();
         try {
-            iAm.startActivityFromRecents(taskPersistentId, INVALID_STACK_ID, null /* options */);
+            iAm.startActivityFromRecents(taskPersistentId, null /* options */);
         } catch (RemoteException e) {
             Slog.e(TAG, "Exception when activating a recent task", e);
         } catch (IllegalArgumentException e) {
@@ -1104,6 +1104,10 @@
                 }
             });
         }
+
+        @Override
+        public void onActivityPinned() {
+        }
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java
index 79bd626..cc85d0f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java
@@ -29,6 +29,8 @@
 import com.android.systemui.R;
 import com.android.systemui.RecentsComponent;
 import com.android.systemui.stackdivider.Divider;
+import com.android.systemui.stackdivider.DividerSnapAlgorithm.SnapTarget;
+import com.android.systemui.stackdivider.DividerView;
 import com.android.systemui.tuner.TunerService;
 
 import static android.view.WindowManager.*;
@@ -189,7 +191,7 @@
                 mRecentsComponent.dockTopTask(mDragMode == DRAG_MODE_RECENTS, createMode,
                         initialBounds);
                 if (mDragMode == DRAG_MODE_DIVIDER) {
-                    mDivider.getView().startDragging();
+                    mDivider.getView().startDragging(false /* animate */);
                 }
                 mDockWindowTouchSlopExceeded = true;
                 MetricsLogger.action(mContext,
@@ -198,8 +200,10 @@
             }
         } else {
             if (mDragMode == DRAG_MODE_DIVIDER) {
-                mDivider.getView().resizeStack(
-                        !mIsVertical ? (int) event.getRawY() : (int) event.getRawX());
+                int position = !mIsVertical ? (int) event.getRawY() : (int) event.getRawX();
+                SnapTarget snapTarget = mDivider.getView().getSnapAlgorithm()
+                        .calculateSnapTarget(position, 0f /* velocity */);
+                mDivider.getView().resizeStack(position, snapTarget.position, snapTarget);
             } else if (mDragMode == DRAG_MODE_RECENTS) {
                 mRecentsComponent.onDraggingInRecents(event.getRawY());
             }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
index cddb1fc..55c7cb7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
@@ -36,11 +36,13 @@
 import android.util.Log;
 import android.view.Display;
 import android.view.Gravity;
+import android.view.IDockedStackListener.Stub;
 import android.view.MotionEvent;
 import android.view.Surface;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.WindowManager;
+import android.view.WindowManagerGlobal;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
@@ -67,7 +69,6 @@
     View mCurrentView = null;
     View[] mRotatedViews = new View[4];
 
-    int mBarSize;
     boolean mVertical;
     boolean mScreenOn;
 
@@ -76,6 +77,9 @@
     int mNavigationIconHints = 0;
 
     private Drawable mBackIcon, mBackLandIcon, mBackAltIcon, mBackAltLandIcon;
+    private Drawable mBackCarModeIcon, mBackLandCarModeIcon;
+    private Drawable mBackAltCarModeIcon, mBackAltLandCarModeIcon;
+    private Drawable mHomeDefaultIcon, mHomeCarModeIcon;
     private Drawable mRecentIcon;
     private Drawable mRecentLandIcon;
 
@@ -94,6 +98,7 @@
     private boolean mIsLayoutRtl;
     private boolean mLayoutTransitionsEnabled = true;
     private boolean mWakeAndUnlocking;
+    private boolean mCarMode = false;
 
     private class NavTransitionListener implements TransitionListener {
         private boolean mBackTransitioning;
@@ -155,8 +160,8 @@
                     final String how = "" + m.obj;
                     final int w = getWidth();
                     final int h = getHeight();
-                    final int vw = mCurrentView.getWidth();
-                    final int vh = mCurrentView.getHeight();
+                    final int vw = getCurrentView().getWidth();
+                    final int vh = getCurrentView().getHeight();
 
                     if (h != vh || w != vw) {
                         Log.w(TAG, String.format(
@@ -174,16 +179,15 @@
     public NavigationBarView(Context context, AttributeSet attrs) {
         super(context, attrs);
 
-        mDisplay = ((WindowManager)context.getSystemService(
+        mDisplay = ((WindowManager) context.getSystemService(
                 Context.WINDOW_SERVICE)).getDefaultDisplay();
 
         final Resources res = getContext().getResources();
-        mBarSize = res.getDimensionPixelSize(R.dimen.navigation_bar_size);
         mVertical = false;
         mShowMenu = false;
         mGestureHelper = new NavigationBarGestureHelper(context);
 
-        getIcons(res);
+        getIcons(context);
 
         mBarTransitions = new NavigationBarTransitions(this);
     }
@@ -227,42 +231,54 @@
         return mCurrentView;
     }
 
-    public View getRecentsButton() {
-        return mCurrentView.findViewById(R.id.recent_apps);
+    public KeyButtonView getRecentsButton() {
+        return (KeyButtonView) getCurrentView().findViewById(R.id.recent_apps);
     }
 
     public View getMenuButton() {
-        return mCurrentView.findViewById(R.id.menu);
+        return getCurrentView().findViewById(R.id.menu);
     }
 
     public View getBackButton() {
-        return mCurrentView.findViewById(R.id.back);
+        return getCurrentView().findViewById(R.id.back);
     }
 
     public KeyButtonView getHomeButton() {
-        return (KeyButtonView) mCurrentView.findViewById(R.id.home);
+        return (KeyButtonView) getCurrentView().findViewById(R.id.home);
     }
 
     public View getImeSwitchButton() {
-        return mCurrentView.findViewById(R.id.ime_switcher);
+        return getCurrentView().findViewById(R.id.ime_switcher);
     }
 
     public View getAppShelf() {
-        return mCurrentView.findViewById(R.id.app_shelf);
+        return getCurrentView().findViewById(R.id.app_shelf);
     }
 
-    private void getIcons(Resources res) {
-        mBackIcon = res.getDrawable(R.drawable.ic_sysbar_back);
+    private void getCarModeIcons(Context ctx) {
+        mBackCarModeIcon = ctx.getDrawable(R.drawable.ic_sysbar_back_carmode);
+        mBackLandCarModeIcon = mBackCarModeIcon;
+        mBackAltCarModeIcon = ctx.getDrawable(R.drawable.ic_sysbar_back_ime_carmode);
+        mBackAltLandCarModeIcon = mBackAltCarModeIcon;
+        mHomeCarModeIcon = ctx.getDrawable(R.drawable.ic_sysbar_home_carmode);
+    }
+
+    private void getIcons(Context ctx) {
+        mBackIcon = ctx.getDrawable(R.drawable.ic_sysbar_back);
         mBackLandIcon = mBackIcon;
-        mBackAltIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime);
+        mBackAltIcon = ctx.getDrawable(R.drawable.ic_sysbar_back_ime);
         mBackAltLandIcon = mBackAltIcon;
-        mRecentIcon = res.getDrawable(R.drawable.ic_sysbar_recent);
+
+        mHomeDefaultIcon = ctx.getDrawable(R.drawable.ic_sysbar_home);
+
+        mRecentIcon = ctx.getDrawable(R.drawable.ic_sysbar_recent);
         mRecentLandIcon = mRecentIcon;
+        getCarModeIcons(ctx);
     }
 
     @Override
     public void setLayoutDirection(int layoutDirection) {
-        getIcons(getContext().getResources());
+        getIcons(getContext());
 
         super.setLayoutDirection(layoutDirection);
     }
@@ -276,6 +292,18 @@
         setNavigationIconHints(hints, false);
     }
 
+    private Drawable getBackIconWithAlt(boolean carMode, boolean landscape) {
+        return landscape
+                ? carMode ? mBackAltLandCarModeIcon : mBackAltLandIcon
+                : carMode ? mBackAltCarModeIcon : mBackAltIcon;
+    }
+
+    private Drawable getBackIcon(boolean carMode, boolean landscape) {
+        return landscape
+                ? carMode ? mBackLandCarModeIcon : mBackLandIcon
+                : carMode ? mBackCarModeIcon : mBackIcon;
+    }
+
     public void setNavigationIconHints(int hints, boolean force) {
         if (!force && hints == mNavigationIconHints) return;
         final boolean backAlt = (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0;
@@ -290,11 +318,23 @@
 
         mNavigationIconHints = hints;
 
-        ((ImageView)getBackButton()).setImageDrawable(backAlt
-                ? (mVertical ? mBackAltLandIcon : mBackAltIcon)
-                : (mVertical ? mBackLandIcon : mBackIcon));
+        // We have to replace or restore the back and home button icons when exiting or entering
+        // carmode, respectively. Recents are not available in CarMode in nav bar so change
+        // to recent icon is not required.
+        Drawable backIcon = (backAlt)
+                ? getBackIconWithAlt(mCarMode, mVertical)
+                : getBackIcon(mCarMode, mVertical);
 
-        ((ImageView)getRecentsButton()).setImageDrawable(mVertical ? mRecentLandIcon : mRecentIcon);
+        ((ImageView) getBackButton()).setImageDrawable(backIcon);
+
+        ((ImageView) getRecentsButton()).setImageDrawable(
+                mVertical ? mRecentLandIcon : mRecentIcon);
+
+        if (mCarMode) {
+            ((ImageView) getHomeButton()).setImageDrawable(mHomeCarModeIcon);
+        } else {
+            ((ImageView) getHomeButton()).setImageDrawable(mHomeDefaultIcon);
+        }
 
         final boolean showImeButton = ((hints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) != 0);
         getImeSwitchButton().setVisibility(showImeButton ? View.VISIBLE : View.INVISIBLE);
@@ -324,7 +364,7 @@
             setSlippery(disableHome && disableRecent && disableBack && disableSearch);
         }
 
-        ViewGroup navButtons = (ViewGroup) mCurrentView.findViewById(R.id.nav_buttons);
+        ViewGroup navButtons = (ViewGroup) getCurrentView().findViewById(R.id.nav_buttons);
         if (navButtons != null) {
             LayoutTransition lt = navButtons.getLayoutTransition();
             if (lt != null) {
@@ -377,7 +417,7 @@
 
     private void updateLayoutTransitionsEnabled() {
         boolean enabled = !mWakeAndUnlocking && mLayoutTransitionsEnabled;
-        ViewGroup navButtons = (ViewGroup) mCurrentView.findViewById(R.id.nav_buttons);
+        ViewGroup navButtons = (ViewGroup) getCurrentView().findViewById(R.id.nav_buttons);
         LayoutTransition lt = navButtons.getLayoutTransition();
         if (lt != null) {
             if (enabled) {
@@ -455,6 +495,32 @@
         getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener);
 
         updateRTLOrder();
+
+        try {
+            WindowManagerGlobal.getWindowManagerService().registerDockedStackListener(new Stub() {
+                @Override
+                public void onDividerVisibilityChanged(boolean visible) throws RemoteException {
+                }
+
+                @Override
+                public void onDockedStackExistsChanged(final boolean exists) throws RemoteException {
+                    mHandler.post(new Runnable() {
+                        @Override
+                        public void run() {
+                            updateRecentsIcon(exists);
+                        }
+                    });
+                }
+            });
+        } catch (RemoteException e) {
+            Log.e(TAG, "Failed registering docked stack exists listener", e);
+        }
+    }
+
+    private void updateRecentsIcon(boolean dockedStackExists) {
+        getRecentsButton().setImageResource(dockedStackExists
+                ? R.drawable.ic_sysbar_docked
+                : R.drawable.ic_sysbar_recent);
     }
 
     public boolean isVertical() {
@@ -518,8 +584,33 @@
     @Override
     protected void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
+        boolean uiCarModeChanged = updateCarMode(newConfig);
         updateRTLOrder();
         updateTaskSwitchHelper();
+        if (uiCarModeChanged) {
+            // uiMode changed either from carmode or to carmode.
+            // replace the nav bar button icons based on which mode
+            // we are switching to.
+            setNavigationIconHints(mNavigationIconHints, true);
+        }
+    }
+
+    /**
+     * If the configuration changed, update the carmode and return that it was updated.
+     */
+    private boolean updateCarMode(Configuration newConfig) {
+        boolean uiCarModeChanged = false;
+        if (newConfig != null) {
+            int uiMode = newConfig.uiMode & Configuration.UI_MODE_TYPE_MASK;
+            if (mCarMode && uiMode != Configuration.UI_MODE_TYPE_CAR) {
+                mCarMode = false;
+                uiCarModeChanged = true;
+            } else if (uiMode == Configuration.UI_MODE_TYPE_CAR) {
+                mCarMode = true;
+                uiCarModeChanged = true;
+            }
+        }
+        return uiCarModeChanged;
     }
 
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
index 42fd872..ba20679 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -1318,7 +1318,6 @@
         mHeader.setExpansion(getHeaderExpansionFraction());
         setQsTranslation(height);
         requestScrollerTopPaddingUpdate(false /* animate */);
-        updateNotificationScrim(height);
         if (mKeyguardShowing) {
             updateHeaderKeyguard();
         }
@@ -1355,12 +1354,6 @@
         }
     }
 
-    private void updateNotificationScrim(float height) {
-        int startDistance = mQsMinExpansionHeight + mNotificationScrimWaitDistance;
-        float progress = (height - startDistance) / (mQsMaxExpansionHeight - startDistance);
-        progress = Math.max(0.0f, Math.min(progress, 1.0f));
-    }
-
     private float getHeaderExpansionFraction() {
         if (!mKeyguardShowing) {
             return getQsExpansionFraction();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelBar.java
index e1a400d..6aa072f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelBar.java
@@ -71,7 +71,6 @@
             Log.e(TAG, "setPanelHolder: null PanelHolder", new Throwable());
             return;
         }
-        ph.setBar(this);
         mPanelHolder = ph;
         final int N = ph.getChildCount();
         for (int i=0; i<N; i++) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelHolder.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelHolder.java
index d7f34d5..5095ebb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelHolder.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelHolder.java
@@ -28,7 +28,6 @@
     public static final boolean DEBUG_GESTURES = true;
 
     private int mSelectedPanelIndex = -1;
-    private PanelBar mBar;
 
     public PanelHolder(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -79,8 +78,4 @@
         }
         return false;
     }
-
-    public void setBar(PanelBar panelBar) {
-        mBar = panelBar;
-    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java
index 5e54ba7..7b2498f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java
@@ -58,7 +58,6 @@
 
     private float mPeekHeight;
     private float mHintDistance;
-    private int mEdgeTapAreaWidth;
     private float mInitialOffsetOnTouch;
     private boolean mCollapsedAndHeadsUpOnDown;
     private float mExpandedFraction = 0;
@@ -202,7 +201,6 @@
         final ViewConfiguration configuration = ViewConfiguration.get(getContext());
         mTouchSlop = configuration.getScaledTouchSlop();
         mHintDistance = res.getDimension(R.dimen.hint_move_distance);
-        mEdgeTapAreaWidth = res.getDimensionPixelSize(R.dimen.edge_tap_area_width);
         mUnlockFalsingThreshold = res.getDimensionPixelSize(R.dimen.unlock_falsing_threshold);
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index 80fcba60e..d688250 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -728,32 +728,7 @@
             boolean showNav = mWindowManagerService.hasNavigationBar();
             if (DEBUG) Log.v(TAG, "hasNavigationBar=" + showNav);
             if (showNav) {
-                // Optionally show app shortcuts in the nav bar "shelf" area.
-                if (shouldShowAppShelf()) {
-                    mNavigationBarView = (NavigationBarView) View.inflate(
-                            context, R.layout.navigation_bar_with_apps, null);
-                } else {
-                    mNavigationBarView = (NavigationBarView) View.inflate(
-                            context, R.layout.navigation_bar, null);
-                }
-                mNavigationBarView.setDisabledFlags(mDisabled1);
-                mNavigationBarView.setComponents(mRecents, getComponent(Divider.class));
-                mNavigationBarView.setOnVerticalChangedListener(
-                        new NavigationBarView.OnVerticalChangedListener() {
-                    @Override
-                    public void onVerticalChanged(boolean isVertical) {
-                        if (mAssistManager != null) {
-                            mAssistManager.onConfigurationChanged();
-                        }
-                        mNotificationPanel.setQsScrimEnabled(!isVertical);
-                    }
-                });
-                mNavigationBarView.setOnTouchListener(new View.OnTouchListener() {
-                    @Override
-                    public boolean onTouch(View v, MotionEvent event) {
-                        checkUserAutohide(v, event);
-                        return false;
-                    }});
+                createNavigationBarView(context);
             }
         } catch (RemoteException ex) {
             // no window manager? good luck with that
@@ -979,6 +954,35 @@
         return mStatusBarView;
     }
 
+    protected void createNavigationBarView(Context context) {
+    // Optionally show app shortcuts in the nav bar "shelf" area.
+        if (shouldShowAppShelf()) {
+            mNavigationBarView = (NavigationBarView) View.inflate(
+                    context, R.layout.navigation_bar_with_apps, null);
+        } else {
+            mNavigationBarView = (NavigationBarView) View.inflate(
+                    context, R.layout.navigation_bar, null);
+        }
+        mNavigationBarView.setDisabledFlags(mDisabled1);
+        mNavigationBarView.setComponents(mRecents, getComponent(Divider.class));
+        mNavigationBarView.setOnVerticalChangedListener(
+                new NavigationBarView.OnVerticalChangedListener() {
+            @Override
+            public void onVerticalChanged(boolean isVertical) {
+                if (mAssistManager != null) {
+                    mAssistManager.onConfigurationChanged();
+                }
+                mNotificationPanel.setQsScrimEnabled(!isVertical);
+            }
+        });
+        mNavigationBarView.setOnTouchListener(new View.OnTouchListener() {
+            @Override
+            public boolean onTouch(View v, MotionEvent event) {
+                checkUserAutohide(v, event);
+                return false;
+            }});
+    }
+
     /** Returns true if the app shelf should be shown in the nav bar. */
     private boolean shouldShowAppShelf() {
         // Allow adb to override the default shelf behavior:
@@ -1086,6 +1090,7 @@
         mKeyguardIndicationController.setStatusBarKeyguardViewManager(
                 mStatusBarKeyguardViewManager);
         mFingerprintUnlockController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager);
+        mRemoteInputController.addCallback(mStatusBarKeyguardViewManager);
         mKeyguardViewMediatorCallback = keyguardViewMediator.getViewMediatorCallback();
     }
 
@@ -1191,7 +1196,7 @@
     }
 
     // For small-screen devices (read: phones) that lack hardware navigation buttons
-    private void addNavigationBar() {
+    protected void addNavigationBar() {
         if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + mNavigationBarView);
         if (mNavigationBarView == null) return;
 
@@ -1269,19 +1274,26 @@
         }
 
         if (!isHeadsUped && notification.getNotification().fullScreenIntent != null) {
-            // Stop screensaver if the notification has a full-screen intent.
-            // (like an incoming phone call)
-            awakenDreams();
+            if (mNotificationData.shouldSuppressScreenOn(notification.getKey())) {
+                if (DEBUG) {
+                    Log.d(TAG, "No Fullscreen intent: suppressed by DND: " + notification.getKey());
+                }
+            } else {
+                // Stop screensaver if the notification has a full-screen intent.
+                // (like an incoming phone call)
+                awakenDreams();
 
-            // not immersive & a full-screen alert should be shown
-            if (DEBUG) Log.d(TAG, "Notification has fullScreenIntent; sending fullScreenIntent");
-            try {
-                EventLog.writeEvent(EventLogTags.SYSUI_FULLSCREEN_NOTIFICATION,
-                        notification.getKey());
-                notification.getNotification().fullScreenIntent.send();
-                shadeEntry.notifyFullScreenIntentLaunched();
-                MetricsLogger.count(mContext, "note_fullscreen", 1);
-            } catch (PendingIntent.CanceledException e) {
+                // not immersive & a full-screen alert should be shown
+                if (DEBUG)
+                    Log.d(TAG, "Notification has fullScreenIntent; sending fullScreenIntent");
+                try {
+                    EventLog.writeEvent(EventLogTags.SYSUI_FULLSCREEN_NOTIFICATION,
+                            notification.getKey());
+                    notification.getNotification().fullScreenIntent.send();
+                    shadeEntry.notifyFullScreenIntentLaunched();
+                    MetricsLogger.count(mContext, "note_fullscreen", 1);
+                } catch (PendingIntent.CanceledException e) {
+                }
             }
         }
         addNotificationViews(shadeEntry, ranking);
@@ -2980,6 +2992,7 @@
             if (DEBUG) Log.v(TAG, "onReceive: " + intent);
             String action = intent.getAction();
             if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
+                getKeyboardShortcuts().dismissKeyboardShortcutsDialog();
                 if (isCurrentProfile(getSendingUserId())) {
                     int flags = CommandQueue.FLAG_EXCLUDE_NONE;
                     String reason = intent.getStringExtra("reason");
@@ -4120,32 +4133,6 @@
         return false;
     }
 
-    // Recents
-
-    @Override
-    protected void showRecents(boolean triggeredFromAltTab) {
-        // Set the recents visibility flag
-        mSystemUiVisibility |= View.RECENT_APPS_VISIBLE;
-        notifyUiVisibilityChanged(mSystemUiVisibility);
-        super.showRecents(triggeredFromAltTab);
-    }
-
-    @Override
-    protected void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
-        // Unset the recents visibility flag
-        mSystemUiVisibility &= ~View.RECENT_APPS_VISIBLE;
-        notifyUiVisibilityChanged(mSystemUiVisibility);
-        super.hideRecents(triggeredFromAltTab, triggeredFromHomeKey);
-    }
-
-    @Override
-    protected void toggleRecents() {
-        // Toggle the recents visibility flag
-        mSystemUiVisibility ^= View.RECENT_APPS_VISIBLE;
-        notifyUiVisibilityChanged(mSystemUiVisibility);
-        super.toggleRecents();
-    }
-
     public void updateRecentsVisibility(boolean visible) {
         // Update the recents visibility flag
         if (visible) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
index c0887ca..ab37e6a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
@@ -51,7 +51,6 @@
     public PhoneStatusBarView(Context context, AttributeSet attrs) {
         super(context, attrs);
 
-        Resources res = getContext().getResources();
         mBarTransitions = new PhoneStatusBarTransitions(this);
     }
 
@@ -102,7 +101,6 @@
 
     @Override
     public PanelView selectPanelForTouch(MotionEvent touch) {
-        // No double swiping. If either panel is open, nothing else can be pulled down.
         return mNotificationPanel.getExpandedHeight() > 0
                 ? null
                 : mNotificationPanel;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
index e6d837a..5c856e8 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
@@ -18,30 +18,25 @@
 
 import android.app.ActivityManager;
 import android.app.PendingIntent;
-import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
-import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.Resources;
-import android.os.Binder;
 import android.os.HandlerThread;
 import android.os.Looper;
 import android.os.Process;
-import android.os.RemoteException;
 import android.provider.Settings;
-import android.service.quicksettings.IQSService;
-import android.service.quicksettings.Tile;
 import android.text.TextUtils;
 import android.util.Log;
 import com.android.systemui.R;
 import com.android.systemui.qs.QSTile;
+import com.android.systemui.qs.external.CustomTile;
+import com.android.systemui.qs.external.TileServices;
 import com.android.systemui.qs.tiles.AirplaneModeTile;
 import com.android.systemui.qs.tiles.BatteryTile;
 import com.android.systemui.qs.tiles.BluetoothTile;
 import com.android.systemui.qs.tiles.CastTile;
 import com.android.systemui.qs.tiles.CellularTile;
 import com.android.systemui.qs.tiles.ColorInversionTile;
-import com.android.systemui.qs.tiles.CustomTile;
 import com.android.systemui.qs.tiles.DndTile;
 import com.android.systemui.qs.tiles.FlashlightTile;
 import com.android.systemui.qs.tiles.HotspotTile;
@@ -76,7 +71,7 @@
 import java.util.Map;
 
 /** Platform implementation of the quick settings tile host **/
-public final class QSTileHost extends IQSService.Stub implements QSTile.Host, Tunable {
+public final class QSTileHost implements QSTile.Host, Tunable {
     private static final String TAG = "QSTileHost";
     private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
 
@@ -100,6 +95,7 @@
     private final KeyguardMonitor mKeyguard;
     private final SecurityController mSecurity;
     private final BatteryController mBattery;
+    private final TileServices mServices;
 
     private final List<Callback> mCallbacks = new ArrayList<>();
 
@@ -131,6 +127,8 @@
         ht.start();
         mLooper = ht.getLooper();
 
+        mServices = new TileServices(this, mLooper);
+
         TunerService.get(mContext).addTunable(this, TILES_SETTING);
     }
 
@@ -256,6 +254,10 @@
         return mSecurity;
     }
 
+    public TileServices getTileServices() {
+        return mServices;
+    }
+
     @Override
     public void onTuningChanged(String key, String newValue) {
         if (!TILES_SETTING.equals(key)) {
@@ -306,50 +308,6 @@
                 TextUtils.join(",", specs), ActivityManager.getCurrentUser());
     }
 
-    @Override
-    public void updateQsTile(Tile tile) throws RemoteException {
-        verifyCaller(tile.getComponentName().getPackageName());
-        CustomTile customTile = getTileForComponent(tile.getComponentName());
-        if (customTile != null) {
-            customTile.updateState(tile);
-            customTile.refreshState();
-        }
-    }
-
-    @Override
-    public void onShowDialog(Tile tile) throws RemoteException {
-        verifyCaller(tile.getComponentName().getPackageName());
-        CustomTile customTile = getTileForComponent(tile.getComponentName());
-        if (customTile != null) {
-            customTile.onDialogShown();
-            collapsePanels();
-        }
-    }
-
-    private void verifyCaller(String packageName) {
-        try {
-            int uid = mContext.getPackageManager().getPackageUid(packageName,
-                    Binder.getCallingUserHandle().getIdentifier());
-            if (Binder.getCallingUid() != uid) {
-                throw new SecurityException("Component outside caller's uid");
-            }
-        } catch (NameNotFoundException e) {
-            throw new SecurityException(e);
-        }
-    }
-
-    private CustomTile getTileForComponent(ComponentName component) {
-        // TODO: Build map for easier lookup.
-        for (QSTile<?> qsTile : mTiles.values()) {
-            if (qsTile instanceof CustomTile) {
-                if (((CustomTile) qsTile).getComponent().equals(component)) {
-                    return (CustomTile) qsTile;
-                }
-            }
-        }
-        return null;
-    }
-
     public QSTile<?> createTile(String tileSpec) {
         if (tileSpec.equals("wifi")) return WifiTile.isSupported(this)
                 ? new WifiTile(this) : null;
@@ -374,7 +332,10 @@
         // Intent tiles.
         else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec);
         else if (tileSpec.startsWith(CustomTile.PREFIX)) return CustomTile.create(this,tileSpec);
-        else throw new IllegalArgumentException("Bad tile spec: " + tileSpec);
+        else {
+            Log.w(TAG, "Bad tile spec: " + tileSpec);
+            return null;
+        }
     }
 
     public static List<String> loadTileSpecs(Context context, String tileList) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStatusBarHeader.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStatusBarHeader.java
index 1372cca..a91f6a2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStatusBarHeader.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStatusBarHeader.java
@@ -24,7 +24,6 @@
 import android.graphics.drawable.Animatable;
 import android.graphics.drawable.RippleDrawable;
 import android.util.AttributeSet;
-import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ImageView;
@@ -135,7 +134,6 @@
     @Override
     public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) {
         mNextAlarm = nextAlarm;
-        Log.d(TAG, "Got alarm update " + (nextAlarm != null));
         if (nextAlarm != null) {
             mAlarmStatus.setText(KeyguardStatusView.formatNextAlarm(getContext(), nextAlarm));
         }
@@ -179,10 +177,8 @@
 
     private void updateListeners() {
         if (mListening) {
-            Log.d(TAG, "Listening for Alarms");
             mNextAlarmController.addStateChangedCallback(this);
         } else {
-            Log.d(TAG, "Not listening for Alarms");
             mNextAlarmController.removeStateChangedCallback(this);
         }
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
index 05f6e57..f14f0d4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
@@ -31,6 +31,7 @@
 import com.android.keyguard.KeyguardUpdateMonitor;
 import com.android.keyguard.ViewMediatorCallback;
 import com.android.systemui.statusbar.CommandQueue;
+import com.android.systemui.statusbar.RemoteInputController;
 
 import static com.android.keyguard.KeyguardHostView.OnDismissAction;
 
@@ -40,7 +41,7 @@
  * which is in turn, reported to this class by the current
  * {@link com.android.keyguard.KeyguardViewBase}.
  */
-public class StatusBarKeyguardViewManager {
+public class StatusBarKeyguardViewManager implements RemoteInputController.Callback {
 
     // When hiding the Keyguard with timing supplied from WindowManager, better be early than late.
     private static final long HIDE_TIMING_CORRECTION_MS = -3 * 16;
@@ -69,12 +70,15 @@
     private KeyguardBouncer mBouncer;
     private boolean mShowing;
     private boolean mOccluded;
+    private boolean mRemoteInputActive;
 
     private boolean mFirstUpdate = true;
     private boolean mLastShowing;
     private boolean mLastOccluded;
     private boolean mLastBouncerShowing;
     private boolean mLastBouncerDismissible;
+    private boolean mLastRemoteInputActive;
+
     private OnDismissAction mAfterKeyguardGoneAction;
     private boolean mDeviceWillWakeUp;
     private boolean mDeferScrimFadeOut;
@@ -199,6 +203,12 @@
         mPhoneStatusBar.onScreenTurnedOn();
     }
 
+    @Override
+    public void onRemoteInputActive(boolean active) {
+        mRemoteInputActive = active;
+        updateStates();
+    }
+
     public void onScreenTurnedOff() {
         mScreenTurnedOn = false;
     }
@@ -429,18 +439,21 @@
         boolean occluded = mOccluded;
         boolean bouncerShowing = mBouncer.isShowing();
         boolean bouncerDismissible = !mBouncer.isFullscreenBouncer();
+        boolean remoteInputActive = mRemoteInputActive;
 
-        if ((bouncerDismissible || !showing) != (mLastBouncerDismissible || !mLastShowing)
+        if ((bouncerDismissible || !showing || remoteInputActive) !=
+                (mLastBouncerDismissible || !mLastShowing || mLastRemoteInputActive)
                 || mFirstUpdate) {
-            if (bouncerDismissible || !showing) {
+            if (bouncerDismissible || !showing || remoteInputActive) {
                 mContainer.setSystemUiVisibility(vis & ~View.STATUS_BAR_DISABLE_BACK);
             } else {
                 mContainer.setSystemUiVisibility(vis | View.STATUS_BAR_DISABLE_BACK);
             }
         }
 
-        boolean navBarVisible = (!(showing && !occluded) || bouncerShowing);
-        boolean lastNavBarVisible = (!(mLastShowing && !mLastOccluded) || mLastBouncerShowing);
+        boolean navBarVisible = (!(showing && !occluded) || bouncerShowing || remoteInputActive);
+        boolean lastNavBarVisible = (!(mLastShowing && !mLastOccluded) || mLastBouncerShowing
+                || mLastRemoteInputActive);
         if (navBarVisible != lastNavBarVisible || mFirstUpdate) {
             if (mPhoneStatusBar.getNavigationBarView() != null) {
                 if (navBarVisible) {
@@ -477,6 +490,7 @@
         mLastOccluded = occluded;
         mLastBouncerShowing = bouncerShowing;
         mLastBouncerDismissible = bouncerDismissible;
+        mLastRemoteInputActive = remoteInputActive;
 
         mPhoneStatusBar.onKeyguardViewManagerStatesUpdated();
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java
index abe51ac..9d2f0de 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java
@@ -30,6 +30,7 @@
 import com.android.keyguard.R;
 import com.android.systemui.keyguard.KeyguardViewMediator;
 import com.android.systemui.statusbar.BaseStatusBar;
+import com.android.systemui.statusbar.RemoteInputController;
 import com.android.systemui.statusbar.StatusBarState;
 
 import java.io.FileDescriptor;
@@ -39,7 +40,7 @@
 /**
  * Encapsulates all logic for the status bar window state management.
  */
-public class StatusBarWindowManager {
+public class StatusBarWindowManager implements RemoteInputController.Callback {
 
     private final Context mContext;
     private final WindowManager mWindowManager;
@@ -292,7 +293,8 @@
         apply(mCurrentState);
     }
 
-    public void setRemoteInputActive(boolean remoteInputActive) {
+    @Override
+    public void onRemoteInputActive(boolean remoteInputActive) {
         mCurrentState.remoteInputActive = remoteInputActive;
         apply(mCurrentState);
     }
diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java
index 1e3b0f1..47a4667 100644
--- a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java
+++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java
@@ -32,7 +32,7 @@
 import android.os.UserHandle;
 import android.provider.Settings;
 import android.util.ArrayMap;
-
+import android.util.ArraySet;
 import com.android.systemui.BatteryMeterDrawable;
 import com.android.systemui.DemoMode;
 import com.android.systemui.R;
@@ -41,9 +41,8 @@
 import com.android.systemui.settings.CurrentUserTracker;
 import com.android.systemui.statusbar.phone.SystemUIDialog;
 
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
+import java.util.Set;
 
 
 public class TunerService extends SystemUI {
@@ -54,7 +53,7 @@
     // Map of Uris we listen on to their settings keys.
     private final ArrayMap<Uri, String> mListeningUris = new ArrayMap<>();
     // Map of settings keys to the listener.
-    private final HashMap<String, List<Tunable>> mTunableLookup = new HashMap<>();
+    private final HashMap<String, Set<Tunable>> mTunableLookup = new HashMap<>();
 
     private ContentResolver mContentResolver;
     private int mCurrentUser;
@@ -85,7 +84,7 @@
 
     private void addTunable(Tunable tunable, String key) {
         if (!mTunableLookup.containsKey(key)) {
-            mTunableLookup.put(key, new ArrayList<Tunable>());
+            mTunableLookup.put(key, new ArraySet<Tunable>());
         }
         mTunableLookup.get(key).add(tunable);
         Uri uri = Settings.Secure.getUriFor(key);
@@ -99,7 +98,7 @@
     }
 
     public void removeTunable(Tunable tunable) {
-        for (List<Tunable> list : mTunableLookup.values()) {
+        for (Set<Tunable> list : mTunableLookup.values()) {
             list.remove(tunable);
         }
     }
@@ -116,7 +115,7 @@
 
     public void reloadSetting(Uri uri) {
         String key = mListeningUris.get(uri);
-        List<Tunable> tunables = mTunableLookup.get(key);
+        Set<Tunable> tunables = mTunableLookup.get(key);
         if (tunables == null) {
             return;
         }
@@ -153,8 +152,11 @@
     private static TunerService sInstance;
 
     public static TunerService get(Context context) {
-        SystemUIApplication sysUi = (SystemUIApplication) context.getApplicationContext();
-        TunerService service = sysUi.getComponent(TunerService.class);
+        TunerService service = null;
+        if (context.getApplicationContext() instanceof SystemUIApplication) {
+            SystemUIApplication sysUi = (SystemUIApplication) context.getApplicationContext();
+            service = sysUi.getComponent(TunerService.class);
+        }
         if (service == null) {
             // Can't get it as a component, must in the tuner, lets just create one for now.
             return getStaticService(context);
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialog.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialog.java
index 9d4ec10..3c63aae 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialog.java
@@ -648,7 +648,7 @@
         if (D.BUG) Log.d(TAG, "updateFooterH");
         final boolean wasVisible = mZenFooter.getVisibility() == View.VISIBLE;
         final boolean visible = mState.zenMode != Global.ZEN_MODE_OFF
-                && mAudioManager.isStreamAffectedByRingerMode(mActiveStream);
+                && (mAudioManager.isStreamAffectedByRingerMode(mActiveStream) || mExpanded);
         if (wasVisible != visible && !visible) {
             prepareForCollapse();
         }
diff --git a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java
index cd47ac1..38d8de0 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java
@@ -510,7 +510,7 @@
         GregorianCalendar weekRange = new GregorianCalendar();
         final long now = weekRange.getTimeInMillis();
         setToMidnight(weekRange);
-        weekRange.roll(Calendar.DATE, 6);
+        weekRange.add(Calendar.DATE, 6);
         final long nextAlarmMs = mController.getNextAlarm();
         if (nextAlarmMs > 0) {
             GregorianCalendar nextAlarm = new GregorianCalendar();
diff --git a/packages/SystemUI/tests/AndroidManifest.xml b/packages/SystemUI/tests/AndroidManifest.xml
index c21af24..2825601 100644
--- a/packages/SystemUI/tests/AndroidManifest.xml
+++ b/packages/SystemUI/tests/AndroidManifest.xml
@@ -19,10 +19,16 @@
 
     <uses-permission android:name="android.permission.INJECT_EVENTS" />
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
+    <uses-permission android:name="android.permission.MANAGE_USERS" />
 
     <application>
         <uses-library android:name="android.test.runner" />
         <activity android:name="com.android.systemui.screenshot.ScreenshotStubActivity" />
+
+        <service
+            android:name="com.android.systemui.qs.external.TileLifecycleManagerTests$FakeTileService"
+            android:process=":killable" />
     </application>
 
     <instrumentation android:name="android.test.InstrumentationTestRunner"
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTests.java b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTests.java
new file mode 100644
index 0000000..6ebf488
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileLifecycleManagerTests.java
@@ -0,0 +1,318 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.systemui.qs.external;
+
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.service.quicksettings.IQSService;
+import android.service.quicksettings.IQSTileService;
+import android.service.quicksettings.Tile;
+import android.test.AndroidTestCase;
+import android.util.ArraySet;
+import android.util.Log;
+
+public class TileLifecycleManagerTests extends AndroidTestCase {
+    public static final String TILE_UPDATE_BROADCAST = "com.android.systemui.tests.TILE_UPDATE";
+    public static final String EXTRA_CALLBACK = "callback";
+
+    private HandlerThread mThread;
+    private Handler mHandler;
+    private TileLifecycleManager mStateManager;
+    private final Object mBroadcastLock = new Object();
+    private final ArraySet<String> mCallbacks = new ArraySet<>();
+    private boolean mBound;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mThread = new HandlerThread("TestThread");
+        mThread.start();
+        mHandler = new Handler(mThread.getLooper());
+        mStateManager = new TileLifecycleManager(mHandler, getContext(),
+                new Intent(mContext, FakeTileService.class), new UserHandle(UserHandle.myUserId()));
+        mCallbacks.clear();
+        getContext().registerReceiver(mReceiver, new IntentFilter(TILE_UPDATE_BROADCAST));
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        if (mBound) {
+            unbindService();
+        }
+        mThread.quit();
+        getContext().unregisterReceiver(mReceiver);
+    }
+
+    public void testSync() {
+        syncWithHandler();
+    }
+
+    public void testBind() {
+        bindService();
+        waitForCallback("onCreate");
+    }
+
+    public void testUnbind() {
+        bindService();
+        waitForCallback("onCreate");
+        unbindService();
+        waitForCallback("onDestroy");
+    }
+
+    public void testTileServiceCallbacks() {
+        bindService();
+        waitForCallback("onCreate");
+
+        mStateManager.onTileAdded();
+        waitForCallback("onTileAdded");
+        mStateManager.onStartListening();
+        waitForCallback("onStartListening");
+        mStateManager.onClick(null);
+        waitForCallback("onClick");
+        mStateManager.onStopListening();
+        waitForCallback("onStopListening");
+        mStateManager.onTileRemoved();
+        waitForCallback("onTileRemoved");
+
+        unbindService();
+    }
+
+    public void testAddedBeforeBind() {
+        mStateManager.onTileAdded();
+
+        bindService();
+        waitForCallback("onCreate");
+        waitForCallback("onTileAdded");
+    }
+
+    public void testListeningBeforeBind() {
+        mStateManager.onTileAdded();
+        mStateManager.onStartListening();
+
+        bindService();
+        waitForCallback("onCreate");
+        waitForCallback("onTileAdded");
+        waitForCallback("onStartListening");
+    }
+
+    public void testClickBeforeBind() {
+        mStateManager.onTileAdded();
+        mStateManager.onStartListening();
+        mStateManager.onClick(null);
+
+        bindService();
+        waitForCallback("onCreate");
+        waitForCallback("onTileAdded");
+        waitForCallback("onStartListening");
+        waitForCallback("onClick");
+    }
+
+    public void testListeningNotListeningBeforeBind() {
+        mStateManager.onTileAdded();
+        mStateManager.onStartListening();
+        mStateManager.onStopListening();
+
+        bindService();
+        waitForCallback("onCreate");
+        unbindService();
+        waitForCallback("onDestroy");
+        assertFalse(mCallbacks.contains("onStartListening"));
+    }
+
+    public void testNoClickOfNotListeningAnymore() {
+        mStateManager.onTileAdded();
+        mStateManager.onStartListening();
+        mStateManager.onClick(null);
+        mStateManager.onStopListening();
+
+        bindService();
+        waitForCallback("onCreate");
+        unbindService();
+        waitForCallback("onDestroy");
+        assertFalse(mCallbacks.contains("onClick"));
+    }
+
+    public void testComponentEnabling() {
+        mStateManager.onTileAdded();
+        mStateManager.onStartListening();
+
+        PackageManager pm = getContext().getPackageManager();
+        pm.setComponentEnabledSetting(new ComponentName(getContext(), FakeTileService.class),
+                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
+
+        bindService();
+        assertTrue(mStateManager.mReceiverRegistered);
+
+        pm.setComponentEnabledSetting(new ComponentName(getContext(), FakeTileService.class),
+                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
+        waitForCallback("onCreate");
+    }
+
+    public void testKillProcess() {
+        mStateManager.onStartListening();
+        bindService();
+        waitForCallback("onCreate");
+        waitForCallback("onStartListening");
+
+        getContext().sendBroadcast(new Intent(FakeTileService.ACTION_KILL));
+
+        waitForCallback("onCreate");
+        waitForCallback("onStartListening");
+    }
+
+    private void bindService() {
+        mBound = true;
+        mStateManager.setBindService(true);
+    }
+
+    private void unbindService() {
+        mBound = false;
+        mStateManager.setBindService(false);
+    }
+
+    private void waitForCallback(String callback) {
+        for (int i = 0; i < 25; i++) {
+            if (mCallbacks.contains(callback)) {
+                mCallbacks.remove(callback);
+                return;
+            }
+            synchronized (mBroadcastLock) {
+                try {
+                    mBroadcastLock.wait(500);
+                } catch (InterruptedException e) {
+                }
+            }
+        }
+        if (mCallbacks.contains(callback)) {
+            mCallbacks.remove(callback);
+            return;
+        }
+        fail("Didn't receive callback: " + callback);
+    }
+
+    private void syncWithHandler() {
+        final Object lock = new Object();
+        synchronized (lock) {
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    synchronized (lock) {
+                        lock.notify();
+                    }
+                }
+            });
+            try {
+                lock.wait(5000);
+            } catch (InterruptedException e) {
+            }
+        }
+    }
+
+    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            mCallbacks.add(intent.getStringExtra(EXTRA_CALLBACK));
+            synchronized (mBroadcastLock) {
+                mBroadcastLock.notify();
+            }
+        }
+    };
+
+    public static class FakeTileService extends Service {
+        public static final String ACTION_KILL = "com.android.systemui.test.KILL";
+
+        @Override
+        public IBinder onBind(Intent intent) {
+            return new IQSTileService.Stub() {
+
+                @Override
+                public void setQSService(IQSService service) {
+
+                }
+
+                @Override
+                public void setQSTile(Tile tile) throws RemoteException {
+                }
+
+                @Override
+                public void onTileAdded() throws RemoteException {
+                    sendCallback("onTileAdded");
+                }
+
+                @Override
+                public void onTileRemoved() throws RemoteException {
+                    sendCallback("onTileRemoved");
+                }
+
+                @Override
+                public void onStartListening() throws RemoteException {
+                    sendCallback("onStartListening");
+                }
+
+                @Override
+                public void onStopListening() throws RemoteException {
+                    sendCallback("onStopListening");
+                }
+
+                @Override
+                public void onClick(IBinder iBinder) throws RemoteException {
+                    sendCallback("onClick");
+                }
+            };
+        }
+
+        @Override
+        public void onCreate() {
+            super.onCreate();
+            registerReceiver(mReceiver, new IntentFilter(ACTION_KILL));
+            sendCallback("onCreate");
+        }
+
+        @Override
+        public void onDestroy() {
+            super.onDestroy();
+            unregisterReceiver(mReceiver);
+            sendCallback("onDestroy");
+        }
+
+        private void sendCallback(String callback) {
+            Log.d("TileLifecycleManager", "Relaying: " + callback);
+            sendBroadcast(new Intent(TILE_UPDATE_BROADCAST)
+                    .putExtra(EXTRA_CALLBACK, callback));
+        }
+
+        private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                if (ACTION_KILL.equals(intent.getAction())) {
+                    Process.killProcess(Process.myPid());
+                }
+            }
+        };
+    }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServiceManagerTests.java b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServiceManagerTests.java
new file mode 100644
index 0000000..4586c28
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServiceManagerTests.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.systemui.qs.external;
+
+import android.content.ComponentName;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.service.quicksettings.TileService;
+import com.android.systemui.SysuiTestCase;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+
+public class TileServiceManagerTests extends SysuiTestCase {
+
+    private TileServices mTileServices;
+    private TileLifecycleManager mTileLifecycle;
+    private HandlerThread mThread;
+    private Handler mHandler;
+    private TileServiceManager mTileServiceManager;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mThread = new HandlerThread("TestThread");
+        mThread.start();
+        mHandler = new Handler(mThread.getLooper());
+        mTileServices = Mockito.mock(TileServices.class);
+        Mockito.when(mTileServices.getContext()).thenReturn(mContext);
+        mTileLifecycle = Mockito.mock(TileLifecycleManager.class);
+        ComponentName componentName = new ComponentName(mContext,
+                TileServiceManagerTests.class);
+        Mockito.when(mTileLifecycle.getComponent()).thenReturn(componentName);
+        mContext.getSharedPreferences(TileServiceManager.PREFS_FILE, 0).edit()
+                .putInt(componentName.flattenToString(), TileService.TILE_MODE_PASSIVE).commit();
+        mTileServiceManager = new TileServiceManager(mTileServices, mHandler, mTileLifecycle);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        mThread.quit();
+    }
+
+    public void testSetBindRequested() {
+        // Request binding.
+        mTileServiceManager.setBindRequested(true);
+        mTileServiceManager.setLastUpdate(0);
+        mTileServiceManager.calculateBindPriority(5);
+        Mockito.verify(mTileServices, Mockito.times(2)).recalculateBindAllowance();
+        assertEquals(5, mTileServiceManager.getBindPriority());
+
+        // Verify same state doesn't trigger recalculating for no reason.
+        mTileServiceManager.setBindRequested(true);
+        Mockito.verify(mTileServices, Mockito.times(2)).recalculateBindAllowance();
+
+        mTileServiceManager.setBindRequested(false);
+        mTileServiceManager.calculateBindPriority(5);
+        Mockito.verify(mTileServices, Mockito.times(3)).recalculateBindAllowance();
+        assertEquals(Integer.MIN_VALUE, mTileServiceManager.getBindPriority());
+    }
+
+    public void testPendingClickPriority() {
+        Mockito.when(mTileLifecycle.hasPendingClick()).thenReturn(true);
+        mTileServiceManager.calculateBindPriority(0);
+        assertEquals(Integer.MAX_VALUE, mTileServiceManager.getBindPriority());
+    }
+
+    public void testBind() {
+        // Trigger binding requested and allowed.
+        mTileServiceManager.setBindRequested(true);
+        mTileServiceManager.setBindAllowed(true);
+
+        ArgumentCaptor<Boolean> captor = ArgumentCaptor.forClass(Boolean.class);
+        Mockito.verify(mTileLifecycle, Mockito.times(1)).setBindService(captor.capture());
+        assertTrue((boolean) captor.getValue());
+
+        mTileServiceManager.setBindRequested(false);
+        mTileServiceManager.calculateBindPriority(0);
+        // Priority shouldn't disappear after the request goes away if we just bound, instead
+        // it sticks around to avoid thrashing a bunch of processes.
+        assertEquals(Integer.MAX_VALUE - 1, mTileServiceManager.getBindPriority());
+
+        mTileServiceManager.setBindAllowed(false);
+        captor = ArgumentCaptor.forClass(Boolean.class);
+        Mockito.verify(mTileLifecycle, Mockito.times(2)).setBindService(captor.capture());
+        assertFalse((boolean) captor.getValue());
+    }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServicesTests.java b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServicesTests.java
new file mode 100644
index 0000000..7a3ce87
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServicesTests.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.systemui.qs.external;
+
+import android.content.ComponentName;
+import android.os.Looper;
+import com.android.systemui.SysuiTestCase;
+import com.android.systemui.statusbar.phone.QSTileHost;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+
+import java.util.ArrayList;
+
+public class TileServicesTests extends SysuiTestCase {
+    private static int NUM_FAKES = TileServices.DEFAULT_MAX_BOUND * 2;
+
+    private TileServices mTileService;
+    private ArrayList<TileServiceManager> mManagers;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mManagers = new ArrayList<>();
+        QSTileHost host = new QSTileHost(mContext, null, null, null, null, null, null, null, null,
+                null, null, null, null, null, null);
+        mTileService = new TestTileServices(host, Looper.myLooper());
+    }
+
+    public void testRecalculateBindAllowance() {
+        // Add some fake tiles.
+        for (int i = 0; i < NUM_FAKES; i++) {
+            mTileService.getTileWrapper(Mockito.mock(CustomTile.class));
+        }
+        assertEquals(NUM_FAKES, mManagers.size());
+
+        for (int i = 0; i < NUM_FAKES; i++) {
+            Mockito.when(mManagers.get(i).getBindPriority()).thenReturn(i);
+        }
+        mTileService.recalculateBindAllowance();
+        for (int i = 0; i < NUM_FAKES; i++) {
+            Mockito.verify(mManagers.get(i), Mockito.times(1)).calculateBindPriority(
+                    Mockito.anyLong());
+            ArgumentCaptor<Boolean> captor = ArgumentCaptor.forClass(Boolean.class);
+            Mockito.verify(mManagers.get(i), Mockito.times(1)).setBindAllowed(captor.capture());
+
+            assertEquals("" + i + "th service", i >= (NUM_FAKES - TileServices.DEFAULT_MAX_BOUND),
+                    (boolean) captor.getValue());
+        }
+    }
+
+    public void testSetMemoryPressure() {
+        testRecalculateBindAllowance();
+        mTileService.setMemoryPressure(true);
+
+        for (int i = 0; i < NUM_FAKES; i++) {
+            ArgumentCaptor<Boolean> captor = ArgumentCaptor.forClass(Boolean.class);
+            Mockito.verify(mManagers.get(i), Mockito.times(2)).setBindAllowed(captor.capture());
+
+            assertEquals("" + i + "th service", i >= (NUM_FAKES - TileServices.REDUCED_MAX_BOUND),
+                    (boolean) captor.getValue());
+        }
+    }
+
+    public void testCalcFew() {
+        for (int i = 0; i < TileServices.DEFAULT_MAX_BOUND - 1; i++) {
+            mTileService.getTileWrapper(Mockito.mock(CustomTile.class));
+        }
+        mTileService.recalculateBindAllowance();
+
+        for (int i = 0; i < TileServices.DEFAULT_MAX_BOUND - 1; i++) {
+            // Shouldn't get bind prioirities calculated when there are less than the max services.
+            Mockito.verify(mManagers.get(i), Mockito.never()).calculateBindPriority(
+                    Mockito.anyLong());
+
+            // All should be bound since there are less than the max services.
+            ArgumentCaptor<Boolean> captor = ArgumentCaptor.forClass(Boolean.class);
+            Mockito.verify(mManagers.get(i), Mockito.times(1)).setBindAllowed(captor.capture());
+
+            assertTrue(captor.getValue());
+        }
+    }
+
+    private class TestTileServices extends TileServices {
+        public TestTileServices(QSTileHost host, Looper looper) {
+            super(host, looper);
+        }
+
+        @Override
+        protected TileServiceManager onCreateTileService(ComponentName component) {
+            TileServiceManager manager = Mockito.mock(TileServiceManager.class);
+            mManagers.add(manager);
+            return manager;
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java
index f329cff..3c91423 100644
--- a/services/core/java/com/android/server/BluetoothManagerService.java
+++ b/services/core/java/com/android/server/BluetoothManagerService.java
@@ -268,7 +268,7 @@
 
         int sysUiUid = -1;
         try {
-            sysUiUid = mContext.getPackageManager().getPackageUid("com.android.systemui",
+            sysUiUid = mContext.getPackageManager().getPackageUidAsUser("com.android.systemui",
                     UserHandle.USER_SYSTEM);
         } catch (PackageManager.NameNotFoundException e) {
             // Some platforms, such as wearables do not have a system ui.
diff --git a/services/core/java/com/android/server/DeviceIdleController.java b/services/core/java/com/android/server/DeviceIdleController.java
index f5ed83e..8d707d6 100644
--- a/services/core/java/com/android/server/DeviceIdleController.java
+++ b/services/core/java/com/android/server/DeviceIdleController.java
@@ -1326,7 +1326,7 @@
     void addPowerSaveTempWhitelistAppInternal(int callingUid, String packageName,
             long duration, int userId, boolean sync, String reason) {
         try {
-            int uid = getContext().getPackageManager().getPackageUid(packageName, userId);
+            int uid = getContext().getPackageManager().getPackageUidAsUser(packageName, userId);
             int appId = UserHandle.getAppId(uid);
             addPowerSaveTempWhitelistAppDirectInternal(callingUid, appId, duration, sync, reason);
         } catch (NameNotFoundException e) {
diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java
index 04abcca..15b5502 100644
--- a/services/core/java/com/android/server/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/InputMethodManagerService.java
@@ -2383,10 +2383,6 @@
             return;
         }
         synchronized (mMethodMap) {
-            if (mCurClient == null || client == null
-                || mCurClient.client.asBinder() != client.asBinder()) {
-                Slog.w(TAG, "Ignoring showInputMethodAndSubtypeEnablerFromClient of: " + client);
-            }
             executeOrSendMessage(mCurMethod, mCaller.obtainMessageO(
                     MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId));
         }
@@ -2716,9 +2712,7 @@
                 return true;
 
             case MSG_SHOW_IM_SUBTYPE_ENABLER:
-                args = (SomeArgs)msg.obj;
-                showInputMethodAndSubtypeEnabler((String)args.arg1);
-                args.recycle();
+                showInputMethodAndSubtypeEnabler((String)msg.obj);
                 return true;
 
             case MSG_SHOW_IM_CONFIG:
@@ -3005,7 +2999,11 @@
         if (!TextUtils.isEmpty(inputMethodId)) {
             intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId);
         }
-        mContext.startActivityAsUser(intent, null, UserHandle.CURRENT);
+        final int userId;
+        synchronized (mMethodMap) {
+            userId = mSettings.getCurrentUserId();
+        }
+        mContext.startActivityAsUser(intent, null, UserHandle.of(userId));
     }
 
     private void showConfigureInputMethods() {
diff --git a/services/core/java/com/android/server/PersistentDataBlockService.java b/services/core/java/com/android/server/PersistentDataBlockService.java
index e8b90d8..1249c8c 100644
--- a/services/core/java/com/android/server/PersistentDataBlockService.java
+++ b/services/core/java/com/android/server/PersistentDataBlockService.java
@@ -94,7 +94,7 @@
         PackageManager pm = mContext.getPackageManager();
         int allowedUid = -1;
         try {
-            allowedUid = pm.getPackageUid(allowedPackage, userHandle);
+            allowedUid = pm.getPackageUidAsUser(allowedPackage, userHandle);
         } catch (PackageManager.NameNotFoundException e) {
             // not expected
             Slog.e(TAG, "not able to find package " + allowedPackage, e);
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 4348913..9dda321 100755
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -1244,7 +1244,7 @@
                                 sInfo.applicationInfo.uid, sInfo.packageName, callingPid);
                         if (allowed != ActivityManager.APP_START_MODE_NORMAL) {
                             Slog.w(TAG, "Background execution not allowed: service "
-                                    + r.intent + " to " + name.flattenToShortString()
+                                    + service + " to " + name.flattenToShortString()
                                     + " from pid=" + callingPid + " uid=" + callingUid
                                     + " pkg=" + callingPackage);
                             return null;
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 3e8dc4e..bac2295 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -244,6 +244,7 @@
 
 import static android.Manifest.permission.INTERACT_ACROSS_USERS;
 import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
+import static android.Manifest.permission.MANAGE_ACTIVITY_STACKS;
 import static android.Manifest.permission.START_TASKS_FROM_RECENTS;
 import static android.app.ActivityManager.RESIZE_MODE_PRESERVE_WINDOW;
 import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
@@ -257,6 +258,7 @@
 import static android.content.pm.PackageManager.PERMISSION_GRANTED;
 import static android.provider.Settings.Global.ALWAYS_FINISH_ACTIVITIES;
 import static android.provider.Settings.Global.DEBUG_APP;
+import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT;
 import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES;
 import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RTL;
 import static android.provider.Settings.Global.WAIT_FOR_DEBUGGER;
@@ -1445,6 +1447,7 @@
     static final int SYSTEM_USER_UNLOCK_MSG = 61;
     static final int LOG_STACK_STATE = 62;
     static final int VR_MODE_CHANGE_MSG = 63;
+    static final int NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG = 64;
 
     static final int FIRST_ACTIVITY_STACK_MSG = 100;
     static final int FIRST_BROADCAST_QUEUE_MSG = 200;
@@ -1998,9 +2001,7 @@
             }
             case NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG: {
                 synchronized (ActivityManagerService.this) {
-                    int i = mTaskStackListeners.beginBroadcast();
-                    while (i > 0) {
-                        i--;
+                    for (int i = mTaskStackListeners.beginBroadcast() - 1; i >= 0; i--) {
                         try {
                             // Make a one-way callback to the listener
                             mTaskStackListeners.getBroadcastItem(i).onTaskStackChanged();
@@ -2012,6 +2013,20 @@
                 }
                 break;
             }
+            case NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG: {
+                synchronized (ActivityManagerService.this) {
+                    for (int i = mTaskStackListeners.beginBroadcast() - 1; i >= 0; i--) {
+                        try {
+                            // Make a one-way callback to the listener
+                            mTaskStackListeners.getBroadcastItem(i).onActivityPinned();
+                        } catch (RemoteException e){
+                            // Handled by the RemoteCallbackList
+                        }
+                    }
+                    mTaskStackListeners.finishBroadcast();
+                }
+                break;
+            }
             case NOTIFY_CLEARTEXT_NETWORK_MSG: {
                 final int uid = msg.arg1;
                 final byte[] firstPacket = (byte[]) msg.obj;
@@ -2743,9 +2758,15 @@
         return mAppBindArgs;
     }
 
-    final void setFocusedActivityLocked(ActivityRecord r, String reason) {
+    boolean setFocusedActivityLocked(ActivityRecord r, String reason) {
         if (r == null || mFocusedActivity == r) {
-            return;
+            return false;
+        }
+
+        if (!r.isFocusable()) {
+            if (DEBUG_FOCUS) Slog.d(TAG_FOCUS,
+                    "setFocusedActivityLocked: unfocusable r=" + r);
+            return false;
         }
 
         if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedActivityLocked: r=" + r);
@@ -2783,7 +2804,7 @@
                 finishVoiceTask(last.task.voiceSession);
             }
         }
-        if (mStackSupervisor.setFocusedStack(r, reason + " setFocusedActivity")) {
+        if (mStackSupervisor.moveActivityStackToFront(r, reason + " setFocusedActivity")) {
             mWindowManager.setFocusedApp(r.appToken, true);
         }
         applyUpdateLockStateLocked(r);
@@ -2799,23 +2820,35 @@
                 mFocusedActivity == null ? -1 : mFocusedActivity.userId,
                 mFocusedActivity == null ? "NULL" : mFocusedActivity.shortComponentName,
                 reason);
+        return true;
     }
 
-    final void clearFocusedActivity(ActivityRecord r) {
-        if (mFocusedActivity == r) {
-            ActivityStack stack = mStackSupervisor.getFocusedStack();
-            if (stack != null) {
-                ActivityRecord top = stack.topActivity();
-                if (top != null && top.userId != mLastFocusedUserId) {
-                    mHandler.removeMessages(FOREGROUND_PROFILE_CHANGED_MSG);
-                    mHandler.sendMessage(mHandler.obtainMessage(FOREGROUND_PROFILE_CHANGED_MSG,
-                                    top.userId, 0));
-                    mLastFocusedUserId = top.userId;
-                }
-            }
-            mFocusedActivity = null;
-            EventLogTags.writeAmFocusedActivity(-1, "NULL", "clearFocusedActivity");
+    final void resetFocusedActivityIfNeededLocked(ActivityRecord goingAway) {
+        if (mFocusedActivity != goingAway) {
+            return;
         }
+
+        final ActivityStack focusedStack = mStackSupervisor.getFocusedStack();
+        if (focusedStack != null) {
+            final ActivityRecord top = focusedStack.topActivity();
+            if (top != null && top.userId != mLastFocusedUserId) {
+                mHandler.removeMessages(FOREGROUND_PROFILE_CHANGED_MSG);
+                mHandler.sendMessage(
+                        mHandler.obtainMessage(FOREGROUND_PROFILE_CHANGED_MSG, top.userId, 0));
+                mLastFocusedUserId = top.userId;
+            }
+        }
+
+        // Try to move focus to another activity if possible.
+        if (setFocusedActivityLocked(
+                focusedStack.topRunningActivityLocked(), "resetFocusedActivityIfNeeded")) {
+            return;
+        }
+
+        if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "resetFocusedActivityIfNeeded: Setting focus to NULL "
+                + "prev mFocusedActivity=" + mFocusedActivity + " goingAway=" + goingAway);
+        mFocusedActivity = null;
+        EventLogTags.writeAmFocusedActivity(-1, "NULL", "resetFocusedActivityIfNeeded");
     }
 
     @Override
@@ -2827,7 +2860,7 @@
                 ActivityRecord r = stack.topRunningActivityLocked();
                 if (r != null) {
                     setFocusedActivityLocked(r, "setFocusedStack");
-                    mStackSupervisor.resumeTopActivitiesLocked(stack, null, null);
+                    mStackSupervisor.resumeFocusedStackTopActivityLocked();
                 }
             }
         }
@@ -2844,7 +2877,7 @@
                     ActivityRecord r = task.topRunningActivityLocked();
                     if (r != null) {
                         setFocusedActivityLocked(r, "setFocusedTask");
-                        mStackSupervisor.resumeTopActivitiesLocked(task.stack, null, null);
+                        mStackSupervisor.resumeFocusedStackTopActivityLocked();
                     }
                 }
             }
@@ -2856,7 +2889,8 @@
     /** Sets the task stack listener that gets callbacks when a task stack changes. */
     @Override
     public void registerTaskStackListener(ITaskStackListener listener) throws RemoteException {
-        synchronized (ActivityManagerService.this) {
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "registerTaskStackListener()");
+        synchronized (this) {
             if (listener != null) {
                 mTaskStackListeners.register(listener);
             }
@@ -3590,7 +3624,7 @@
     Intent getHomeIntent() {
         Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null);
         intent.setComponent(mTopComponent);
-        intent.addFlags(Intent.FLAG_DEBUG_ENCRYPTION_TRIAGED);
+        intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
         if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
             intent.addCategory(Intent.CATEGORY_HOME);
         }
@@ -4342,7 +4376,7 @@
     }
 
     @Override
-    public final int startActivityFromRecents(int taskId, int launchStackId, Bundle bOptions) {
+    public final int startActivityFromRecents(int taskId, Bundle bOptions) {
         if (checkCallingPermission(START_TASKS_FROM_RECENTS) != PackageManager.PERMISSION_GRANTED) {
             String msg = "Permission Denial: startActivityFromRecents called without " +
                     START_TASKS_FROM_RECENTS;
@@ -4351,24 +4385,28 @@
         }
         final long origId = Binder.clearCallingIdentity();
         try {
-            return startActivityFromRecentsInner(taskId, launchStackId, bOptions);
+            return startActivityFromRecentsInner(taskId, bOptions);
         } finally {
             Binder.restoreCallingIdentity(origId);
         }
     }
 
-    final int startActivityFromRecentsInner(int taskId, int launchStackId, Bundle bOptions) {
+    final int startActivityFromRecentsInner(int taskId, Bundle bOptions) {
         final TaskRecord task;
         final int callingUid;
         final String callingPackage;
         final Intent intent;
         final int userId;
         synchronized (this) {
+            final ActivityOptions activityOptions = (bOptions != null)
+                    ? new ActivityOptions(bOptions) : null;
+            final int launchStackId = (activityOptions != null)
+                    ? activityOptions.getLaunchStackId() : INVALID_STACK_ID;
+
             if (launchStackId == HOME_STACK_ID) {
                 throw new IllegalArgumentException("startActivityFromRecentsInner: Task "
                         + taskId + " can't be launch in the home stack.");
             }
-
             task = mStackSupervisor.anyTaskForIdLocked(taskId, RESTORE_FROM_RECENTS, launchStackId);
             if (task == null) {
                 throw new IllegalArgumentException(
@@ -4376,10 +4414,9 @@
             }
 
             if (launchStackId != INVALID_STACK_ID) {
-                if (launchStackId == DOCKED_STACK_ID && bOptions != null) {
-                    ActivityOptions activityOptions = new ActivityOptions(bOptions);
-                    mWindowManager.setDockedStackCreateState(activityOptions.getDockCreateMode(),
-                            null /* initialBounds */);
+                if (launchStackId == DOCKED_STACK_ID && activityOptions != null) {
+                    mWindowManager.setDockedStackCreateState(
+                            activityOptions.getDockCreateMode(), null /* initialBounds */);
                 }
                 if (task.stack.mStackId != launchStackId) {
                     mStackSupervisor.moveTaskToStackLocked(
@@ -4388,7 +4425,10 @@
                 }
             }
 
-            if (task.getRootActivity() != null) {
+            // If the user must confirm credentials (e.g. when first launching a work app and the
+            // Work Challenge is present) let startActivityInPackage handle the intercepting.
+            if (!mUserController.shouldConfirmCredentials(task.userId)
+                    && task.getRootActivity() != null) {
                 moveTaskToFrontLocked(task.taskId, 0, bOptions);
                 return ActivityManager.START_TASK_TO_FRONT;
             }
@@ -4473,7 +4513,7 @@
             if (config != null) {
                 r.frozenBeforeDestroy = true;
                 if (!updateConfigurationLocked(config, r, false)) {
-                    mStackSupervisor.resumeTopActivitiesLocked();
+                    mStackSupervisor.resumeFocusedStackTopActivityLocked();
                 }
             }
             Binder.restoreCallingIdentity(origId);
@@ -4811,12 +4851,11 @@
             finishInstrumentationLocked(app, Activity.RESULT_CANCELED, info);
         }
 
-        if (!restarting && hasVisibleActivities && !mStackSupervisor.resumeTopActivitiesLocked()) {
-            // If there was nothing to resume, and we are not already
-            // restarting this process, but there is a visible activity that
-            // is hosted by the process...  then make sure all visible
-            // activities are running, taking care of restarting this
-            // process.
+        if (!restarting && hasVisibleActivities
+                && !mStackSupervisor.resumeFocusedStackTopActivityLocked()) {
+            // If there was nothing to resume, and we are not already restarting this process, but
+            // there is a visible activity that is hosted by the process...  then make sure all
+            // visible activities are running, taking care of restarting this process.
             mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
         }
     }
@@ -5873,7 +5912,7 @@
         // Clean-up disabled activities.
         if (mStackSupervisor.finishDisabledPackageActivitiesLocked(
                 packageName, disabledClasses, true, false, userId) && mBooted) {
-            mStackSupervisor.resumeTopActivitiesLocked();
+            mStackSupervisor.resumeFocusedStackTopActivityLocked();
             mStackSupervisor.scheduleIdleLocked();
         }
 
@@ -6061,7 +6100,7 @@
                 }
             }
             if (mBooted) {
-                mStackSupervisor.resumeTopActivitiesLocked();
+                mStackSupervisor.resumeFocusedStackTopActivityLocked();
                 mStackSupervisor.scheduleIdleLocked();
             }
         }
@@ -6736,6 +6775,15 @@
     }
 
     @Override
+    public final void activityRelaunched(IBinder token) {
+        final long origId = Binder.clearCallingIdentity();
+        synchronized (this) {
+            mStackSupervisor.activityRelaunchedLocked(token);
+        }
+        Binder.restoreCallingIdentity(origId);
+    }
+
+    @Override
     public void reportSizeConfigurations(IBinder token, int[] horizontalSizeConfiguration,
             int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) {
         if (DEBUG_CONFIGURATION) Slog.v(TAG, "Report configuration: " + token + " "
@@ -7257,7 +7305,7 @@
                             + "Can't find activity for token=" + token);
                 }
 
-                if (!r.info.supportsPip) {
+                if (!r.supportsPictureInPicture()) {
                     throw new IllegalArgumentException("enterPictureInPictureMode: "
                             + "Picture-In-Picture not supported for r=" + r);
                 }
@@ -8994,15 +9042,14 @@
                 task.mResizeable = resizeable;
                 mWindowManager.setTaskResizeable(taskId, resizeable);
                 mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
-                mStackSupervisor.resumeTopActivitiesLocked();
+                mStackSupervisor.resumeFocusedStackTopActivityLocked();
             }
         }
     }
 
     @Override
     public void resizeTask(int taskId, Rect bounds, int resizeMode) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "resizeTask()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeTask()");
         long ident = Binder.clearCallingIdentity();
         try {
             synchronized (this) {
@@ -9052,8 +9099,7 @@
 
     @Override
     public Rect getTaskBounds(int taskId) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "getTaskBounds()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getTaskBounds()");
         long ident = Binder.clearCallingIdentity();
         Rect rect = new Rect();
         try {
@@ -9355,8 +9401,7 @@
     @Override
     public IActivityContainer createVirtualActivityContainer(IBinder parentActivityToken,
             IActivityContainerCallback callback) throws RemoteException {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "createActivityContainer()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "createActivityContainer()");
         synchronized (this) {
             if (parentActivityToken == null) {
                 throw new IllegalArgumentException("parent token must not be null");
@@ -9374,8 +9419,7 @@
 
     @Override
     public void deleteActivityContainer(IActivityContainer container) throws RemoteException {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "deleteActivityContainer()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "deleteActivityContainer()");
         synchronized (this) {
             mStackSupervisor.deleteActivityContainer(container);
         }
@@ -9383,8 +9427,7 @@
 
     @Override
     public IActivityContainer createStackOnDisplay(int displayId) throws RemoteException {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "createStackOnDisplay()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "createStackOnDisplay()");
         synchronized (this) {
             final int stackId = mStackSupervisor.getNextStackId();
             final ActivityStack stack =
@@ -9419,23 +9462,23 @@
     }
 
     @Override
-    public void moveActivityToStack(IBinder token, int stackId) throws RemoteException {
-        if (stackId == HOME_STACK_ID) {
-            throw new IllegalArgumentException(
-                    "moveActivityToStack: Attempt to move token " + token + " to home stack");
-        }
+    public void exitFreeformMode(IBinder token) throws RemoteException {
         synchronized (this) {
             long ident = Binder.clearCallingIdentity();
             try {
                 final ActivityRecord r = ActivityRecord.forTokenLocked(token);
                 if (r == null) {
                     throw new IllegalArgumentException(
-                            "moveActivityToStack: No activity record matching token=" + token);
+                            "exitFreeformMode: No activity record matching token=" + token);
                 }
-                if (DEBUG_STACK) Slog.d(TAG_STACK, "moveActivityToStack: moving r=" + r
-                        + " to stackId=" + stackId);
-                mStackSupervisor.moveTaskToStackLocked(r.task.taskId, stackId, ON_TOP, !FORCE_FOCUS,
-                        "moveActivityToStack", ANIMATE);
+                final ActivityStack stack = r.getStackLocked(token);
+                if (stack == null || stack.mStackId != FREEFORM_WORKSPACE_STACK_ID) {
+                    throw new IllegalStateException(
+                            "exitFreeformMode: You can only go fullscreen from freeform.");
+                }
+                if (DEBUG_STACK) Slog.d(TAG_STACK, "exitFreeformMode: " + r);
+                mStackSupervisor.moveTaskToStackLocked(r.task.taskId, FULLSCREEN_WORKSPACE_STACK_ID,
+                        ON_TOP, !FORCE_FOCUS, "exitFreeformMode", ANIMATE);
             } finally {
                 Binder.restoreCallingIdentity(ident);
             }
@@ -9444,8 +9487,7 @@
 
     @Override
     public void moveTaskToStack(int taskId, int stackId, boolean toTop) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "moveTaskToStack()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToStack()");
         if (stackId == HOME_STACK_ID) {
             throw new IllegalArgumentException(
                     "moveTaskToStack: Attempt to move task " + taskId + " to home stack");
@@ -9480,8 +9522,7 @@
     @Override
     public void moveTaskToDockedStack(int taskId, int createMode, boolean toTop, boolean animate,
             Rect initialBounds) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "moveTaskToDockedStack()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "moveTaskToDockedStack()");
         synchronized (this) {
             long ident = Binder.clearCallingIdentity();
             try {
@@ -9507,8 +9548,7 @@
      */
     @Override
     public boolean moveTopActivityToPinnedStack(int stackId, Rect bounds) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "moveTopActivityToPinnedStack()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "moveTopActivityToPinnedStack()");
         synchronized (this) {
             if (!mSupportsPictureInPicture) {
                 throw new IllegalStateException("moveTopActivityToPinnedStack:"
@@ -9526,13 +9566,31 @@
 
     @Override
     public void resizeStack(int stackId, Rect bounds, boolean allowResizeInDockedMode) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "resizeStack()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "resizeStack()");
         long ident = Binder.clearCallingIdentity();
         try {
             synchronized (this) {
                 mStackSupervisor.resizeStackLocked(
-                        stackId, bounds, !PRESERVE_WINDOWS, allowResizeInDockedMode);
+                        stackId, bounds, null /* tempTaskBounds */, null /* tempTaskInsetBounds */,
+                        !PRESERVE_WINDOWS, allowResizeInDockedMode);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    @Override
+    public void resizeDockedStack(Rect dockedBounds, Rect tempDockedTaskBounds,
+            Rect tempDockedTaskInsetBounds,
+            Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds) {
+        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
+                "resizeDockedStack()");
+        long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized (this) {
+                mStackSupervisor.resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds,
+                        tempDockedTaskInsetBounds, tempOtherTaskBounds, tempOtherTaskInsetBounds,
+                        PRESERVE_WINDOWS);
             }
         } finally {
             Binder.restoreCallingIdentity(ident);
@@ -9541,8 +9599,7 @@
 
     @Override
     public void positionTaskInStack(int taskId, int stackId, int position) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "positionTaskInStack()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()");
         if (stackId == HOME_STACK_ID) {
             throw new IllegalArgumentException(
                     "positionTaskInStack: Attempt to change the position of task "
@@ -9563,8 +9620,7 @@
 
     @Override
     public List<StackInfo> getAllStackInfos() {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "getAllStackInfos()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getAllStackInfos()");
         long ident = Binder.clearCallingIdentity();
         try {
             synchronized (this) {
@@ -9577,8 +9633,7 @@
 
     @Override
     public StackInfo getStackInfo(int stackId) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "getStackInfo()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()");
         long ident = Binder.clearCallingIdentity();
         try {
             synchronized (this) {
@@ -9591,8 +9646,7 @@
 
     @Override
     public boolean isInHomeStack(int taskId) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "getStackInfo()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "getStackInfo()");
         long ident = Binder.clearCallingIdentity();
         try {
             synchronized (this) {
@@ -9706,8 +9760,7 @@
 
     @Override
     public void startLockTaskModeOnCurrent() throws RemoteException {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "startLockTaskModeOnCurrent");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "startLockTaskModeOnCurrent");
         long ident = Binder.clearCallingIdentity();
         try {
             synchronized (this) {
@@ -9759,8 +9812,7 @@
 
     @Override
     public void stopLockTaskModeOnCurrent() throws RemoteException {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "stopLockTaskModeOnCurrent");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "stopLockTaskModeOnCurrent");
         long ident = Binder.clearCallingIdentity();
         try {
             stopLockTaskMode();
@@ -9802,7 +9854,7 @@
             ParceledListSlice<ProviderInfo> slice = AppGlobals.getPackageManager()
                     .queryContentProviders(app.processName, app.uid,
                             STOCK_PM_FLAGS | PackageManager.GET_URI_PERMISSION_PATTERNS
-                                    | PackageManager.MATCH_ENCRYPTION_DEFAULT);
+                                    | PackageManager.MATCH_DEBUG_TRIAGED_MISSING);
             providers = slice != null ? slice.getList() : null;
         } catch (RemoteException ex) {
         }
@@ -11033,6 +11085,12 @@
         mHandler.sendMessageDelayed(nmsg, NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY);
     }
 
+    /** Notifies all listeners when an Activity is pinned. */
+    void notifyActivityPinnedLocked() {
+        mHandler.removeMessages(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG);
+        mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG).sendToTarget();
+    }
+
     @Override
     public void notifyCleartextNetwork(int uid, byte[] firstPacket) {
         mHandler.obtainMessage(NOTIFY_CLEARTEXT_NETWORK_MSG, uid, 0, firstPacket).sendToTarget();
@@ -12149,7 +12207,9 @@
     private void retrieveSettings() {
         final ContentResolver resolver = mContext.getContentResolver();
         final boolean freeformWindowManagement =
-                mContext.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT);
+                mContext.getPackageManager().hasSystemFeature(FEATURE_FREEFORM_WINDOW_MANAGEMENT)
+                        || Settings.Global.getInt(
+                                resolver, DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0;
         final boolean supportsPictureInPicture =
                 mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE);
 
@@ -12158,9 +12218,8 @@
         final boolean alwaysFinishActivities =
                 Settings.Global.getInt(resolver, ALWAYS_FINISH_ACTIVITIES, 0) != 0;
         final boolean forceRtl = Settings.Global.getInt(resolver, DEVELOPMENT_FORCE_RTL, 0) != 0;
-        final int defaultForceResizable = Build.IS_DEBUGGABLE ? 1 : 0;
         final boolean forceResizable = Settings.Global.getInt(
-                resolver, DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, defaultForceResizable) != 0;
+                resolver, DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0;
         // Transfer any global setting for forcing RTL layout, into a System Property
         SystemProperties.set(DEVELOPMENT_FORCE_RTL, forceRtl ? "1":"0");
 
@@ -12193,6 +12252,17 @@
                     com.android.internal.R.dimen.thumbnail_height);
             mDefaultPinnedStackBounds = Rect.unflattenFromString(res.getString(
                     com.android.internal.R.string.config_defaultPictureInPictureBounds));
+            final String appsNotReportingCrashes = res.getString(
+                    com.android.internal.R.string.config_appsNotReportingCrashes);
+            if (appsNotReportingCrashes != null) {
+                final String[] split = appsNotReportingCrashes.split(",");
+                if (split.length > 0) {
+                    mAppsNotReportingCrashes = new ArraySet<>();
+                    for (int i = 0; i < split.length; i++) {
+                        mAppsNotReportingCrashes.add(split[i]);
+                    }
+                }
+            }
         }
     }
 
@@ -12603,7 +12673,7 @@
             } finally {
                 Binder.restoreCallingIdentity(ident);
             }
-            mStackSupervisor.resumeTopActivitiesLocked();
+            mStackSupervisor.resumeFocusedStackTopActivityLocked();
             mUserController.sendUserSwitchBroadcastsLocked(-1, currentUserId);
         }
     }
@@ -12714,10 +12784,10 @@
                 // annoy the user repeatedly.  Unless it is persistent, since those
                 // processes run critical code.
                 removeProcessLocked(app, false, false, "crash");
-                mStackSupervisor.resumeTopActivitiesLocked();
+                mStackSupervisor.resumeFocusedStackTopActivityLocked();
                 return false;
             }
-            mStackSupervisor.resumeTopActivitiesLocked();
+            mStackSupervisor.resumeFocusedStackTopActivityLocked();
         } else {
             mStackSupervisor.finishTopRunningActivityLocked(app, reason);
         }
@@ -14811,7 +14881,7 @@
             int dumpUid = -2;
             if (dumpPackage != null) {
                 try {
-                    dumpUid = mContext.getPackageManager().getPackageUid(dumpPackage, 0);
+                    dumpUid = mContext.getPackageManager().getPackageUidAsUser(dumpPackage, 0);
                 } catch (NameNotFoundException e) {
                     dumpUid = -1;
                 }
@@ -17010,7 +17080,7 @@
     private List<ResolveInfo> collectReceiverComponents(Intent intent, String resolvedType,
             int callingUid, int[] users) {
         // TODO: come back and remove this assumption to triage all broadcasts
-        int pmFlags = STOCK_PM_FLAGS | PackageManager.MATCH_ENCRYPTION_DEFAULT;
+        int pmFlags = STOCK_PM_FLAGS | PackageManager.MATCH_DEBUG_TRIAGED_MISSING;
 
         List<ResolveInfo> receivers = null;
         try {
@@ -17780,6 +17850,11 @@
                         "Unable to find instrumentation target package: " + ii.targetPackage);
                 return false;
             }
+            if (!ai.hasCode()) {
+                reportStartInstrumentationFailure(watcher, className,
+                        "Instrumentation target has no code: " + ii.targetPackage);
+                return false;
+            }
 
             int match = mContext.getPackageManager().checkSignatures(
                     ii.targetPackage, ii.packageName);
@@ -17933,8 +18008,7 @@
 
     @Override
     public void suppressResizeConfigChanges(boolean suppress) throws RemoteException {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "suppressResizeConfigChanges()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "suppressResizeConfigChanges()");
         synchronized (this) {
             mSuppressResizeConfigChanges = suppress;
         }
@@ -17942,8 +18016,7 @@
 
     @Override
     public void moveTasksToFullscreenStack(int fromStackId) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "moveTasksToFullscreenStack()");
+        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "moveTasksToFullscreenStack()");
         if (fromStackId == HOME_STACK_ID) {
             throw new IllegalArgumentException("You can't move tasks from the home stack.");
         }
@@ -18062,10 +18135,18 @@
                 EventLog.writeEvent(EventLogTags.CONFIGURATION_CHANGED, changes);
 
                 if (!initLocale && !values.getLocales().isEmpty() && values.userSetLocale) {
-                    if (mSupportedSystemLocales == null) {
-                        mSupportedSystemLocales = Resources.getSystem().getAssets().getLocales();
+                    final Locale locale;
+                    if (values.getLocales().size() == 1) {
+                        // This is an optimization to avoid the JNI call when the result of
+                        // getFirstMatch() does not depend on the supported locales.
+                        locale = values.getLocales().getPrimary();
+                    } else {
+                        if (mSupportedSystemLocales == null) {
+                            mSupportedSystemLocales =
+                                    Resources.getSystem().getAssets().getLocales();
+                        }
+                        locale = values.getLocales().getFirstMatch(mSupportedSystemLocales);
                     }
-                    final Locale locale = values.getLocales().getFirstMatch(mSupportedSystemLocales);
                     SystemProperties.set("persist.sys.locale", locale.toLanguageTag());
                     mHandler.sendMessage(mHandler.obtainMessage(SEND_LOCALE_TO_MOUNT_DAEMON_MSG,
                             locale));
@@ -20889,7 +20970,7 @@
         public void moveToFront() {
             checkCaller();
             // Will bring task to front if it already has a root activity.
-            startActivityFromRecentsInner(mTaskId, INVALID_STACK_ID, null);
+            startActivityFromRecentsInner(mTaskId, null);
         }
 
         @Override
diff --git a/services/core/java/com/android/server/am/ActivityMetricsLogger.java b/services/core/java/com/android/server/am/ActivityMetricsLogger.java
index 9680382..4101dde 100644
--- a/services/core/java/com/android/server/am/ActivityMetricsLogger.java
+++ b/services/core/java/com/android/server/am/ActivityMetricsLogger.java
@@ -26,7 +26,7 @@
     // Preallocated strings we are sending to tron, so we don't have to allocate a new one every
     // time we log.
     private static final String[] TRON_WINDOW_STATE_VARZ_STRINGS = {
-            "tron_varz_window_time_0", "tron_varz_window_time_1", "tron_varz_window_time_2"};
+            "window_time_0", "window_time_1", "window_time_2"};
 
     private int mWindowState = WINDOW_STATE_STANDARD;
     private long mLastLogTimeSecs;
diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java
index 4d9120b..4fb87c3 100755
--- a/services/core/java/com/android/server/am/ActivityRecord.java
+++ b/services/core/java/com/android/server/am/ActivityRecord.java
@@ -16,7 +16,11 @@
 
 package com.android.server.am;
 
+import static android.app.ActivityManager.StackId;
 import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
+import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
+import static android.content.pm.ActivityInfo.FLAG_RESIZEABLE;
+import static android.content.pm.ActivityInfo.FLAG_SUPPORTS_PICTURE_IN_PICTURE;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
@@ -739,6 +743,22 @@
                         (intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
     }
 
+    boolean isFocusable() {
+        return StackId.canReceiveKeys(task.stack.mStackId) || isAlwaysFocusable();
+    }
+
+    boolean isResizeable() {
+        return (info.flags & FLAG_RESIZEABLE) != 0;
+    }
+
+    boolean supportsPictureInPicture() {
+        return (info.flags & FLAG_SUPPORTS_PICTURE_IN_PICTURE) != 0;
+    }
+
+    boolean isAlwaysFocusable() {
+        return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0;
+    }
+
     void makeFinishingLocked() {
         if (!finishing) {
             if (task != null && task.stack != null
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 1492e23..e123dbd 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -21,8 +21,13 @@
 import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
 import static android.app.ActivityManager.StackId.HOME_STACK_ID;
 import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
+import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
+import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT;
+import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
+import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
 import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
 
+import static android.content.res.Configuration.SCREENLAYOUT_UNDEFINED;
 import static com.android.server.am.ActivityManagerDebugConfig.*;
 import static com.android.server.am.ActivityManagerService.LOCK_SCREEN_SHOWN;
 import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
@@ -560,7 +565,7 @@
 
         // TODO(multi-display): Needs to also work if focus is moving to the non-home display.
         if (isOnHomeDisplay()) {
-            mStackSupervisor.setFocusStack(reason, this);
+            mStackSupervisor.setFocusStackUnchecked(reason, this);
         }
         if (task != null) {
             insertTaskAtTop(task, null);
@@ -572,6 +577,16 @@
         }
     }
 
+    boolean isFocusable() {
+        if (StackId.canReceiveKeys(mStackId)) {
+            return true;
+        }
+        // The stack isn't focusable. See if its top activity is focusable to force focus on the
+        // stack.
+        final ActivityRecord r = topRunningActivityLocked();
+        return r != null && r.isFocusable();
+    }
+
     final boolean isAttached() {
         return mStacks != null;
     }
@@ -917,7 +932,7 @@
         if (prev == null) {
             if (!resuming) {
                 Slog.wtf(TAG, "Trying to pause when nothing is resumed");
-                mStackSupervisor.resumeTopActivitiesLocked();
+                mStackSupervisor.resumeFocusedStackTopActivityLocked();
             }
             return false;
         }
@@ -1008,7 +1023,7 @@
             // pause, so just treat it as being paused now.
             if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next.");
             if (!resuming) {
-                mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
+                mStackSupervisor.resumeFocusedStackTopActivityLocked();
             }
             return false;
         }
@@ -1075,7 +1090,7 @@
             } else {
                 if (r.configDestroy) {
                     destroyActivityLocked(r, true, "stop-config");
-                    mStackSupervisor.resumeTopActivitiesLocked();
+                    mStackSupervisor.resumeFocusedStackTopActivityLocked();
                 } else {
                     mStackSupervisor.updatePreviousProcessLocked(r);
                 }
@@ -1131,17 +1146,16 @@
         if (resumeNext) {
             final ActivityStack topStack = mStackSupervisor.getFocusedStack();
             if (!mService.isSleepingOrShuttingDown()) {
-                mStackSupervisor.resumeTopActivitiesLocked(topStack, prev, null);
+                mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack, prev, null);
             } else {
                 mStackSupervisor.checkReadyForSleepLocked();
                 ActivityRecord top = topStack.topRunningActivityLocked();
                 if (top == null || (prev != null && top != prev)) {
-                    // If there are no more activities available to run,
-                    // do resume anyway to start something.  Also if the top
-                    // activity on the stack is not the just paused activity,
-                    // we need to go ahead and resume it to ensure we complete
-                    // an in-flight app switch.
-                    mStackSupervisor.resumeTopActivitiesLocked(topStack, null, null);
+                    // If there are no more activities available to run, do resume anyway to start
+                    // something. Also if the top activity on the stack is not the just paused
+                    // activity, we need to go ahead and resume it to ensure we complete an
+                    // in-flight app switch.
+                    mStackSupervisor.resumeFocusedStackTopActivityLocked();
                 }
             }
         }
@@ -1296,7 +1310,7 @@
         return null;
     }
 
-    private ActivityStack getNextVisibleStackLocked() {
+    ActivityStack getNextFocusableStackLocked() {
         ArrayList<ActivityStack> stacks = mStacks;
         final ActivityRecord parent = mActivityContainer.mParentActivity;
         if (parent != null) {
@@ -1305,7 +1319,7 @@
         if (stacks != null) {
             for (int i = stacks.size() - 1; i >= 0; --i) {
                 ActivityStack stack = stacks.get(i);
-                if (stack != this && stack.isStackVisibleLocked()) {
+                if (stack != this && stack.isFocusable() && stack.isStackVisibleLocked()) {
                     return stack;
                 }
             }
@@ -1478,7 +1492,7 @@
         boolean aboveTop = top != null;
         final boolean stackInvisible = !isStackVisibleLocked();
         boolean behindFullscreenActivity = stackInvisible;
-        boolean noStackActivityResumed = (isInStackLocked(starting) == null);
+        boolean resumeNextActivity = isFocusable() && (isInStackLocked(starting) == null);
 
         for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
             final TaskRecord task = mTaskHistory.get(taskNdx);
@@ -1509,18 +1523,18 @@
 
                     if (r.app == null || r.app.thread == null) {
                         if (makeVisibleAndRestartIfNeeded(starting, configChanges, isTop,
-                                noStackActivityResumed, r)) {
+                                resumeNextActivity, r)) {
                             if (activityNdx >= activities.size()) {
                                 // Record may be removed if its process needs to restart.
                                 activityNdx = activities.size() - 1;
                             } else {
-                                noStackActivityResumed = false;
+                                resumeNextActivity = false;
                             }
                         }
                     } else if (r.visible) {
                         // If this activity is already visible, then there is nothing to do here.
                         if (handleAlreadyVisible(r)) {
-                            noStackActivityResumed = false;
+                            resumeNextActivity = false;
                         }
                     } else {
                         makeVisible(starting, r);
@@ -1561,7 +1575,7 @@
     }
 
     private boolean makeVisibleAndRestartIfNeeded(ActivityRecord starting, int configChanges,
-            boolean isTop, boolean noStackActivityResumed, ActivityRecord r) {
+            boolean isTop, boolean andResume, ActivityRecord r) {
         // We need to make sure the app is running if it's the top, or it is just made visible from
         // invisible. If the app is already visible, it must have died while it was visible. In this
         // case, we'll show the dead window but will not restart the app. Otherwise we could end up
@@ -1578,7 +1592,7 @@
                 setVisible(r, true);
             }
             if (r != starting) {
-                mStackSupervisor.startSpecificActivityLocked(r, noStackActivityResumed, false);
+                mStackSupervisor.startSpecificActivityLocked(r, andResume, false);
                 return true;
             }
         }
@@ -1772,15 +1786,17 @@
      *
      * @param prev The previously resumed activity, for when in the process
      * of pausing; can be null to call from elsewhere.
+     * @param options Activity options.
      *
      * @return Returns true if something is being resumed, or false if
      * nothing happened.
+     *
+     * NOTE: It is not safe to call this method directly as it can cause an activity in a
+     *       non-focused stack to be resumed.
+     *       Use {@link ActivityStackSupervisor#resumeFocusedStackTopActivityLocked} to resume the
+     *       right activity for the current system state.
      */
-    final boolean resumeTopActivityLocked(ActivityRecord prev) {
-        return resumeTopActivityLocked(prev, null);
-    }
-
-    final boolean resumeTopActivityLocked(ActivityRecord prev, ActivityOptions options) {
+    boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) {
         if (mStackSupervisor.inResumeTopActivity) {
             // Don't even start recursing.
             return false;
@@ -1831,14 +1847,13 @@
         if (next == null) {
             // There are no more activities!
             final String reason = "noMoreActivities";
-            if (!mFullscreen) {
+            if (!mFullscreen && adjustFocusToNextFocusableStackLocked(reason)) {
                 // Try to move focus to the next visible stack with a running activity if this
                 // stack is not covering the entire screen.
-                final ActivityStack stack = getNextVisibleStackLocked();
-                if (adjustFocusToNextVisibleStackLocked(stack, reason)) {
-                    return mStackSupervisor.resumeTopActivitiesLocked(stack, prev, null);
-                }
+                return mStackSupervisor.resumeFocusedStackTopActivityLocked(
+                        mStackSupervisor.getFocusedStack(), prev, null);
             }
+
             // Let's just start up the Launcher...
             ActivityOptions.abort(options);
             if (DEBUG_STATES) Slog.d(TAG_STATES,
@@ -2870,7 +2885,7 @@
         final ActivityRecord next = topRunningActivityLocked();
         final String myReason = reason + " adjustFocus";
         if (next != r) {
-            if (next != null && StackId.keepFocusInStackIfPossible(mStackId)) {
+            if (next != null && StackId.keepFocusInStackIfPossible(mStackId) && isFocusable()) {
                 // For freeform, docked, and pinned stacks we always keep the focus within the
                 // stack as long as there is a running activity in the stack that we can adjust
                 // focus to.
@@ -2882,8 +2897,7 @@
                     // For non-fullscreen stack, we want to move the focus to the next visible
                     // stack to prevent the home screen from moving to the top and obscuring
                     // other visible stacks.
-                    if (!mFullscreen
-                            && adjustFocusToNextVisibleStackLocked(null, myReason)) {
+                    if (!mFullscreen && adjustFocusToNextFocusableStackLocked(myReason)) {
                         return;
                     }
                     // Move the home stack to the top if this stack is fullscreen or there is no
@@ -2897,24 +2911,16 @@
             }
         }
 
-        final ActivityRecord top = mStackSupervisor.topRunningActivityLocked();
-        if (top != null) {
-            mService.setFocusedActivityLocked(top, myReason);
-        }
+        mService.setFocusedActivityLocked(mStackSupervisor.topRunningActivityLocked(), myReason);
     }
 
-    private boolean adjustFocusToNextVisibleStackLocked(ActivityStack inStack, String reason) {
-        final ActivityStack stack = (inStack != null) ? inStack : getNextVisibleStackLocked();
-        final String myReason = reason + " adjustFocusToNextVisibleStack";
+    private boolean adjustFocusToNextFocusableStackLocked(String reason) {
+        final ActivityStack stack = getNextFocusableStackLocked();
+        final String myReason = reason + " adjustFocusToNextFocusableStack";
         if (stack == null) {
             return false;
         }
-        final ActivityRecord top = stack.topRunningActivityLocked();
-        if (top == null) {
-            return false;
-        }
-        mService.setFocusedActivityLocked(top, myReason);
-        return true;
+        return mService.setFocusedActivityLocked(stack.topRunningActivityLocked(), myReason);
     }
 
     final void stopActivityLocked(ActivityRecord r) {
@@ -3224,7 +3230,7 @@
             r.makeFinishingLocked();
             boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm");
             if (activityRemoved) {
-                mStackSupervisor.resumeTopActivitiesLocked();
+                mStackSupervisor.resumeFocusedStackTopActivityLocked();
             }
             if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS,
                     "destroyActivityLocked: finishCurrentActivityLocked r=" + r +
@@ -3237,7 +3243,7 @@
         if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r);
         mStackSupervisor.mFinishingActivities.add(r);
         r.resumeKeyDispatchingLocked();
-        mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
+        mStackSupervisor.resumeFocusedStackTopActivityLocked();
         return r;
     }
 
@@ -3395,7 +3401,7 @@
         if (mPausingActivity == r) {
             mPausingActivity = null;
         }
-        mService.clearFocusedActivity(r);
+        mService.resetFocusedActivityIfNeededLocked(r);
 
         r.configDestroy = false;
         r.frozenBeforeDestroy = false;
@@ -3526,7 +3532,7 @@
             }
         }
         if (activityRemoved) {
-            mStackSupervisor.resumeTopActivitiesLocked();
+            mStackSupervisor.resumeFocusedStackTopActivityLocked();
         }
     }
 
@@ -3700,7 +3706,7 @@
                     removeActivityFromHistoryLocked(r, reason);
                 }
             }
-            mStackSupervisor.resumeTopActivitiesLocked();
+            mStackSupervisor.resumeFocusedStackTopActivityLocked();
         } finally {
             Binder.restoreCallingIdentity(origId);
         }
@@ -3738,7 +3744,7 @@
             setVisibleBehindActivity(null);
             mStackSupervisor.scheduleIdleTimeoutLocked(null);
         }
-        mStackSupervisor.resumeTopActivitiesLocked();
+        mStackSupervisor.resumeFocusedStackTopActivityLocked();
     }
 
     boolean hasVisibleBehindActivity() {
@@ -3953,7 +3959,7 @@
             updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options);
         }
 
-        mStackSupervisor.resumeTopActivitiesLocked();
+        mStackSupervisor.resumeFocusedStackTopActivityLocked();
         EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId);
 
         if (VALIDATE_TOKENS) {
@@ -4016,7 +4022,7 @@
             if (fullscreenStack != null && fullscreenStack.hasVisibleBehindActivity()) {
                 final ActivityRecord visibleBehind = fullscreenStack.getVisibleBehindActivity();
                 mService.setFocusedActivityLocked(visibleBehind, "moveTaskToBack");
-                mStackSupervisor.resumeTopActivitiesLocked(fullscreenStack, null, null);
+                mStackSupervisor.resumeFocusedStackTopActivityLocked();
                 return true;
             }
         }
@@ -4071,7 +4077,7 @@
             return mStackSupervisor.resumeHomeStackTask(taskToReturnTo, null, "moveTaskToBack");
         }
 
-        mStackSupervisor.resumeTopActivitiesLocked();
+        mStackSupervisor.resumeFocusedStackTopActivityLocked();
         return true;
     }
 
@@ -4223,20 +4229,20 @@
         int taskChanges = oldTaskOverride.diff(taskConfig);
         // We don't want to use size changes if they don't cross boundaries that are important to
         // the app.
-        if ((taskChanges & ActivityInfo.CONFIG_SCREEN_SIZE) != 0) {
+        if ((taskChanges & CONFIG_SCREEN_SIZE) != 0) {
             final boolean crosses = record.crossesHorizontalSizeThreshold(
                     oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp)
                     || record.crossesVerticalSizeThreshold(
                     oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp);
             if (!crosses) {
-                taskChanges &= ~ActivityInfo.CONFIG_SCREEN_SIZE;
+                taskChanges &= ~CONFIG_SCREEN_SIZE;
             }
         }
-        if ((taskChanges & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
+        if ((taskChanges & CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
             final int oldSmallest = oldTaskOverride.smallestScreenWidthDp;
             final int newSmallest = taskConfig.smallestScreenWidthDp;
             if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) {
-                taskChanges &= ~ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
+                taskChanges &= ~CONFIG_SMALLEST_SCREEN_SIZE;
             }
         }
         return catchConfigChangesFromUnset(taskConfig, oldTaskOverride, taskChanges);
@@ -4248,7 +4254,7 @@
             // {@link Configuration#diff} doesn't catch changes from unset values.
             // Check for changes we care about.
             if (oldTaskOverride.orientation != taskConfig.orientation) {
-                taskChanges |= ActivityInfo.CONFIG_ORIENTATION;
+                taskChanges |= CONFIG_ORIENTATION;
             }
             // We want to explicitly track situations where the size configuration goes from
             // undefined to defined. We don't care about crossing the threshold in that case,
@@ -4258,29 +4264,35 @@
             final int undefinedHeight = Configuration.SCREEN_HEIGHT_DP_UNDEFINED;
             if ((oldHeight == undefinedHeight && newHeight != undefinedHeight)
                     || (oldHeight != undefinedHeight && newHeight == undefinedHeight)) {
-                taskChanges |= ActivityInfo.CONFIG_SCREEN_SIZE;
+                taskChanges |= CONFIG_SCREEN_SIZE;
             }
             final int oldWidth = oldTaskOverride.screenWidthDp;
             final int newWidth = taskConfig.screenWidthDp;
             final int undefinedWidth = Configuration.SCREEN_WIDTH_DP_UNDEFINED;
             if ((oldWidth == undefinedWidth && newWidth != undefinedWidth)
                     || (oldWidth != undefinedWidth && newWidth == undefinedWidth)) {
-                taskChanges |= ActivityInfo.CONFIG_SCREEN_SIZE;
+                taskChanges |= CONFIG_SCREEN_SIZE;
             }
             final int oldSmallest = oldTaskOverride.smallestScreenWidthDp;
             final int newSmallest = taskConfig.smallestScreenWidthDp;
             final int undefinedSmallest = Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
             if ((oldSmallest == undefinedSmallest && newSmallest != undefinedSmallest)
                     || (oldSmallest != undefinedSmallest && newSmallest == undefinedSmallest)) {
-                taskChanges |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
+                taskChanges |= CONFIG_SMALLEST_SCREEN_SIZE;
+            }
+            final int oldLayout = oldTaskOverride.screenLayout;
+            final int newLayout = taskConfig.screenLayout;
+            if ((oldLayout == SCREENLAYOUT_UNDEFINED && newLayout != SCREENLAYOUT_UNDEFINED)
+                || (oldLayout != SCREENLAYOUT_UNDEFINED && newLayout == SCREENLAYOUT_UNDEFINED)) {
+                taskChanges |= CONFIG_SCREEN_LAYOUT;
             }
         }
         return taskChanges;
     }
 
     private static boolean isResizeOnlyChange(int change) {
-        return (change & ~(ActivityInfo.CONFIG_SCREEN_SIZE
-                | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE | ActivityInfo.CONFIG_ORIENTATION)) == 0;
+        return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION
+                | CONFIG_SCREEN_LAYOUT)) == 0;
     }
 
     private void relaunchActivityLocked(
@@ -4313,6 +4325,7 @@
             r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, changes,
                     !andResume, new Configuration(mService.mConfiguration),
                     new Configuration(r.task.mOverrideConfig), preserveWindow);
+            mStackSupervisor.activityRelaunchingLocked(r);
             // Note: don't need to call pauseIfSleepingLocked() here, because
             // the caller will only pass in 'andResume' if this activity is
             // currently resumed, which implies we aren't sleeping.
@@ -4593,7 +4606,7 @@
                     a.forceNewConfig = true;
                     if (starting != null && a == starting && a.visible) {
                         a.startFreezingScreenLocked(starting.app,
-                                ActivityInfo.CONFIG_SCREEN_LAYOUT);
+                                CONFIG_SCREEN_LAYOUT);
                     }
                 }
             }
@@ -4661,7 +4674,7 @@
             // We only need to adjust focused stack if this stack is in focus.
             if (isOnHomeDisplay() && mStackSupervisor.isFocusedStack(this)) {
                 String myReason = reason + " leftTaskHistoryEmpty";
-                if (mFullscreen || !adjustFocusToNextVisibleStackLocked(null, myReason)) {
+                if (mFullscreen || !adjustFocusToNextFocusableStackLocked(myReason)) {
                     mStackSupervisor.moveHomeStackToFront(myReason);
                 }
             }
@@ -4734,10 +4747,7 @@
 
     private void postAddTask(TaskRecord task, ActivityStack prevStack) {
         if (prevStack != null) {
-            if (prevStack != this
-                    && (prevStack.mStackId == PINNED_STACK_ID || mStackId == PINNED_STACK_ID)) {
-                task.reportPictureInPictureModeChange();
-            }
+            task.reportPictureInPictureModeChangeIfNeeded(prevStack);
         } else if (task.voiceSession != null) {
             try {
                 task.voiceSession.taskStarted(task.intent, task.taskId);
@@ -4751,32 +4761,28 @@
         task.updateOverrideConfiguration(bounds);
         mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken,
                 r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen,
-                (r.info.flags & ActivityInfo.FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId,
-                r.info.configChanges, task.voiceSession != null, r.mLaunchTaskBehind,
-                bounds, task.mOverrideConfig, !r.isHomeActivity());
+                (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, r.info.configChanges,
+                task.voiceSession != null, r.mLaunchTaskBehind, bounds, task.mOverrideConfig,
+                !r.isHomeActivity(), r.isAlwaysFocusable());
         mWindowManager.setTaskResizeable(task.taskId, task.mResizeable);
         r.taskConfigOverride = task.mOverrideConfig;
     }
 
-    void setFocusAndResumeStateIfNeeded(
-            ActivityRecord r, boolean setFocus, boolean setResume, String reason) {
-        // If the activity had focus before move focus to this stack.
-        if (setFocus) {
-            // If the activity owns the last resumed activity, transfer that together,
-            // so that we don't resume the same activity again in the new stack.
-            // Apps may depend on onResume()/onPause() being called in pairs.
-            if (setResume) {
-                mResumedActivity = r;
-                // Move the stack in which we are placing the activity to the front. We don't use
-                // ActivityManagerService.setFocusedActivityLocked, because if the activity is
-                // already focused, the call will short-circuit and do nothing.
-                moveToFront(reason);
-            } else {
-                // We need to not only move the stack to the front, but also have the activity
-                // focused. This will achieve both goals.
-                mService.setFocusedActivityLocked(r, reason);
-            }
+    void moveToFrontAndResumeStateIfNeeded(
+            ActivityRecord r, boolean moveToFront, boolean setResume, String reason) {
+        if (!moveToFront) {
+            return;
         }
+
+        // If the activity owns the last resumed activity, transfer that together,
+        // so that we don't resume the same activity again in the new stack.
+        // Apps may depend on onResume()/onPause() being called in pairs.
+        if (setResume) {
+            mResumedActivity = r;
+        }
+        // Move the stack in which we are placing the activity to the front. The call will also
+        // make sure the activity focus is set.
+        moveToFront(reason);
     }
 
     /**
@@ -4800,8 +4806,11 @@
         r.setTask(task, null);
         task.addActivityToTop(r);
         setAppTask(r, task);
-        task.reportPictureInPictureModeChange();
-        setFocusAndResumeStateIfNeeded(r, wasFocused, wasResumed, "moveActivityToStack");
+        task.reportPictureInPictureModeChangeIfNeeded(prevStack);
+        moveToFrontAndResumeStateIfNeeded(r, wasFocused, wasResumed, "moveActivityToStack");
+        if (wasResumed) {
+            prevStack.mResumedActivity = null;
+        }
     }
 
     private void setAppTask(ActivityRecord r, TaskRecord task) {
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 32671acf..4672023 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -16,70 +16,6 @@
 
 package com.android.server.am;
 
-import static android.Manifest.permission.START_ANY_ACTIVITY;
-import static android.app.ActivityManager.LOCK_TASK_MODE_LOCKED;
-import static android.app.ActivityManager.LOCK_TASK_MODE_NONE;
-import static android.app.ActivityManager.LOCK_TASK_MODE_PINNED;
-import static android.app.ActivityManager.RESIZE_MODE_FORCED;
-import static android.app.ActivityManager.RESIZE_MODE_SYSTEM;
-import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
-import static android.app.ActivityManager.StackId.FIRST_DYNAMIC_STACK_ID;
-import static android.app.ActivityManager.StackId.FIRST_STATIC_STACK_ID;
-import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
-import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
-import static android.app.ActivityManager.StackId.HOME_STACK_ID;
-import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
-import static android.app.ActivityManager.StackId.LAST_STATIC_STACK_ID;
-import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
-import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
-import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
-import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
-import static android.content.pm.PackageManager.PERMISSION_GRANTED;
-import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONTAINERS;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_IDLE;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKSCREEN;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PAUSE;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RELEASE;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBLE_BEHIND;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONTAINERS;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_IDLE;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PAUSE;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RELEASE;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBLE_BEHIND;
-import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
-import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
-import static com.android.server.am.ActivityManagerService.FIRST_SUPERVISOR_STACK_MSG;
-import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
-import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
-import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
-import static com.android.server.am.ActivityStack.ActivityState.DESTROYED;
-import static com.android.server.am.ActivityStack.ActivityState.DESTROYING;
-import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING;
-import static com.android.server.am.ActivityStack.ActivityState.PAUSED;
-import static com.android.server.am.ActivityStack.ActivityState.PAUSING;
-import static com.android.server.am.ActivityStack.ActivityState.RESUMED;
-import static com.android.server.am.ActivityStack.ActivityState.STOPPED;
-import static com.android.server.am.ActivityStack.ActivityState.STOPPING;
-import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK;
-import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE;
-import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
-import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_PINNABLE;
-import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_WHITELISTED;
-
 import android.Manifest;
 import android.app.Activity;
 import android.app.ActivityManager;
@@ -164,6 +100,70 @@
 import java.util.List;
 import java.util.Set;
 
+import static android.Manifest.permission.START_ANY_ACTIVITY;
+import static android.app.ActivityManager.LOCK_TASK_MODE_LOCKED;
+import static android.app.ActivityManager.LOCK_TASK_MODE_NONE;
+import static android.app.ActivityManager.LOCK_TASK_MODE_PINNED;
+import static android.app.ActivityManager.RESIZE_MODE_FORCED;
+import static android.app.ActivityManager.RESIZE_MODE_SYSTEM;
+import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
+import static android.app.ActivityManager.StackId.FIRST_DYNAMIC_STACK_ID;
+import static android.app.ActivityManager.StackId.FIRST_STATIC_STACK_ID;
+import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
+import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
+import static android.app.ActivityManager.StackId.HOME_STACK_ID;
+import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
+import static android.app.ActivityManager.StackId.LAST_STATIC_STACK_ID;
+import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
+import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
+import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
+import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
+import static android.content.pm.PackageManager.PERMISSION_GRANTED;
+import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONTAINERS;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_IDLE;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKSCREEN;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PAUSE;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RELEASE;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBLE_BEHIND;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONTAINERS;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_IDLE;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PAUSE;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RELEASE;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBLE_BEHIND;
+import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
+import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
+import static com.android.server.am.ActivityManagerService.FIRST_SUPERVISOR_STACK_MSG;
+import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
+import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
+import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
+import static com.android.server.am.ActivityStack.ActivityState.DESTROYED;
+import static com.android.server.am.ActivityStack.ActivityState.DESTROYING;
+import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING;
+import static com.android.server.am.ActivityStack.ActivityState.PAUSED;
+import static com.android.server.am.ActivityStack.ActivityState.PAUSING;
+import static com.android.server.am.ActivityStack.ActivityState.RESUMED;
+import static com.android.server.am.ActivityStack.ActivityState.STOPPED;
+import static com.android.server.am.ActivityStack.ActivityState.STOPPING;
+import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK;
+import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE;
+import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
+import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_PINNABLE;
+import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_WHITELISTED;
+
 public final class ActivityStackSupervisor implements DisplayListener {
     private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStackSupervisor" : TAG_AM;
     private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS;
@@ -370,7 +370,7 @@
      */
     private LockTaskNotify mLockTaskNotify;
 
-    /** Used to keep resumeTopActivityLocked() from being entered recursively */
+    /** Used to keep resumeTopActivityUncheckedLocked() from being entered recursively */
     boolean inResumeTopActivity;
 
     // temp. rects used during resize calculation so we don't need to create a new object each time.
@@ -379,6 +379,7 @@
 
     private final SparseArray<Configuration> mTmpConfigs = new SparseArray<>();
     private final SparseArray<Rect> mTmpBounds = new SparseArray<>();
+    private final SparseArray<Rect> mTmpInsetBounds = new SparseArray<>();
 
     // The default minimal size that will be used if the activity doesn't specify its minimal size.
     // It will be calculated when the default display gets added.
@@ -389,6 +390,8 @@
 
     private final ActivityMetricsLogger mActivityMetricsLogger;
 
+    private final ResizeDockedStackTimeout mResizeDockedStackTimeout;
+
     static class FindTaskResult {
         ActivityRecord r;
         boolean matchedByRootAffinity;
@@ -432,6 +435,7 @@
         mRecentTasks = recentTasks;
         mHandler = new ActivityStackSupervisorHandler(mService.mHandler.getLooper());
         mActivityMetricsLogger = new ActivityMetricsLogger(this, mService.mContext);
+        mResizeDockedStackTimeout = new ResizeDockedStackTimeout(service, this, mHandler);
     }
 
     /**
@@ -492,8 +496,8 @@
                 calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay);
             }
 
-            createStackOnDisplay(HOME_STACK_ID, Display.DEFAULT_DISPLAY, true);
-            mHomeStack = mFocusedStack = mLastFocusedStack = getStack(HOME_STACK_ID);
+            mHomeStack = mFocusedStack = mLastFocusedStack =
+                    getStack(HOME_STACK_ID, CREATE_IF_NEEDED, ON_TOP);
 
             mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
         }
@@ -537,16 +541,30 @@
         return stack == mHomeStack.mStacks.get((mHomeStack.mStacks.size() - 1));
     }
 
-    void setFocusStack(String reason, ActivityStack focusedStack) {
-        mLastFocusedStack = mFocusedStack;
-        mFocusedStack = focusedStack;
+    /** NOTE: Should only be called from {@link ActivityStack#moveToFront} */
+    void setFocusStackUnchecked(String reason, ActivityStack focusCandidate) {
+        if (!focusCandidate.isFocusable()) {
+            // The focus candidate isn't focusable. Move focus to the top stack that is focusable.
+            focusCandidate = focusCandidate.getNextFocusableStackLocked();
+        }
 
-        EventLogTags.writeAmFocusedStack(
-                mCurrentUser, mFocusedStack == null ? -1 : mFocusedStack.getStackId(),
-                mLastFocusedStack == null ? -1 : mLastFocusedStack.getStackId(), reason);
+        if (focusCandidate != mFocusedStack) {
+            mLastFocusedStack = mFocusedStack;
+            mFocusedStack = focusCandidate;
+
+            EventLogTags.writeAmFocusedStack(
+                    mCurrentUser, mFocusedStack == null ? -1 : mFocusedStack.getStackId(),
+                    mLastFocusedStack == null ? -1 : mLastFocusedStack.getStackId(), reason);
+        }
+
+        final ActivityRecord r = topRunningActivityLocked();
+        if (mService.mFocusedActivity != r) {
+            // The focus activity should always be the top activity in the focused stack.
+            // There will be chaos and anarchy if it isn't...
+            mService.setFocusedActivityLocked(r, reason + " setFocusStack");
+        }
 
         if (mService.mBooting || !mService.mBooted) {
-            final ActivityRecord r = topRunningActivityLocked();
             if (r != null && r.idle) {
                 checkFinishBootingLocked();
             }
@@ -591,12 +609,14 @@
 
         mHomeStack.moveHomeStackTaskToTop(homeStackTaskType);
         ActivityRecord r = getHomeActivity();
+        final String myReason = reason + " resumeHomeStackTask";
+
         // Only resume home activity if isn't finishing.
         if (r != null && !r.finishing) {
-            mService.setFocusedActivityLocked(r, reason);
-            return resumeTopActivitiesLocked(mHomeStack, prev, null);
+            mService.setFocusedActivityLocked(r, myReason);
+            return resumeFocusedStackTopActivityLocked(mHomeStack, prev, null);
         }
-        return mService.startHomeActivityLocked(mCurrentUser, reason);
+        return mService.startHomeActivityLocked(mCurrentUser, myReason);
     }
 
     TaskRecord anyTaskForIdLocked(int id) {
@@ -893,7 +913,7 @@
         final ArrayList<ActivityStack> stacks = mHomeStack.mStacks;
         for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
             final ActivityStack stack = stacks.get(stackNdx);
-            if (stack != focusedStack && isFrontStack(stack)) {
+            if (stack != focusedStack && isFrontStack(stack) && stack.isFocusable()) {
                 r = stack.topRunningActivityLocked();
                 if (r != null) {
                     return r;
@@ -1148,14 +1168,12 @@
             // a resume.
             stack.minimalResumeActivityLocked(r);
         } else {
-            // This activity is not starting in the resumed state... which
-            // should look like we asked it to pause+stop (but remain visible),
-            // and it has done so and reported back the current icicle and
-            // other state.
+            // This activity is not starting in the resumed state... which should look like we asked
+            // it to pause+stop (but remain visible), and it has done so and reported back the
+            // current icicle and other state.
             if (DEBUG_STATES) Slog.v(TAG_STATES,
-                    "Moving to STOPPED: " + r + " (starting in stopped state)");
-            r.state = STOPPED;
-            r.stopped = true;
+                    "Moving to PAUSED: " + r + " (starting in paused state)");
+            r.state = PAUSED;
         }
 
         // Launch the new version setup screen if needed.  We do this -after-
@@ -1345,30 +1363,20 @@
         return ACTIVITY_RESTRICTION_NONE;
     }
 
-    boolean setFocusedStack(ActivityRecord r, String reason) {
+    boolean moveActivityStackToFront(ActivityRecord r, String reason) {
         if (r == null) {
             // Not sure what you are trying to do, but it is not going to work...
             return false;
         }
         final TaskRecord task = r.task;
         if (task == null || task.stack == null) {
-            Slog.w(TAG, "Can't set focus stack for r=" + r + " task=" + task);
+            Slog.w(TAG, "Can't move stack to front for r=" + r + " task=" + task);
             return false;
         }
         task.stack.moveToFront(reason, task);
         return true;
     }
 
-    Rect getOverrideBounds(ActivityRecord r, ActivityOptions options, TaskRecord inTask) {
-        Rect newBounds = null;
-        if (options != null && (r.info.resizeable || (inTask != null && inTask.mResizeable))) {
-            if (canUseActivityOptionsLaunchBounds(options)) {
-                newBounds = options.getLaunchBounds();
-            }
-        }
-        return newBounds;
-    }
-
     void setLaunchSource(int uid) {
         mLaunchingActivity.setWorkSource(new WorkSource(uid));
     }
@@ -1518,7 +1526,7 @@
         //mWindowManager.dump();
 
         if (activityRemoved) {
-            resumeTopActivitiesLocked();
+            resumeFocusedStackTopActivityLocked();
         }
 
         return r;
@@ -1611,35 +1619,17 @@
         }
     }
 
-    boolean resumeTopActivitiesLocked() {
-        return resumeTopActivitiesLocked(null, null, null);
+    boolean resumeFocusedStackTopActivityLocked() {
+        return resumeFocusedStackTopActivityLocked(null, null, null);
     }
 
-    boolean resumeTopActivitiesLocked(
+    boolean resumeFocusedStackTopActivityLocked(
             ActivityStack targetStack, ActivityRecord target, ActivityOptions targetOptions) {
-        if (targetStack == null) {
-            targetStack = mFocusedStack;
+        if (targetStack != null && isFocusedStack(targetStack)) {
+            return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions);
         }
-        // Do targetStack first.
-        boolean result = false;
-        if (isFocusedStack(targetStack)) {
-            result = targetStack.resumeTopActivityLocked(target, targetOptions);
-        }
-
-        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
-            final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
-            for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
-                final ActivityStack stack = stacks.get(stackNdx);
-                if (stack == targetStack) {
-                    // Already started above.
-                    continue;
-                }
-                if (isFocusedStack(stack)) {
-                    stack.resumeTopActivityLocked(null);
-                }
-            }
-        }
-        return result;
+        mFocusedStack.resumeTopActivityUncheckedLocked(null, null);
+        return false;
     }
 
     void finishTopRunningActivityLocked(ProcessRecord app, String reason) {
@@ -1681,10 +1671,13 @@
         }
 
         if (task.mResizeable && options != null) {
-            if (canUseActivityOptionsLaunchBounds(options)) {
+            int stackId = options.getLaunchStackId();
+            if (canUseActivityOptionsLaunchBounds(options, stackId)) {
                 Rect bounds = options.getLaunchBounds();
                 task.updateOverrideConfiguration(bounds);
-                final int stackId = task.getLaunchStackId();
+                if (stackId == INVALID_STACK_ID) {
+                    stackId = task.getLaunchStackId();
+                }
                 if (stackId != task.stack.mStackId) {
                     moveTaskToStackUncheckedLocked(task, stackId, ON_TOP, !FORCE_FOCUS, reason);
                     // moveTaskToStackUncheckedLocked() should already placed the task on top,
@@ -1706,10 +1699,14 @@
                 "findTaskToMoveToFront: moved to front of stack=" + task.stack);
     }
 
-    private boolean canUseActivityOptionsLaunchBounds(ActivityOptions options) {
+    boolean canUseActivityOptionsLaunchBounds(ActivityOptions options, int launchStackId) {
         // We use the launch bounds in the activity options is the device supports freeform
-        // window management.
-        return options.hasLaunchBounds() && mService.mSupportsFreeformWindowManagement;
+        // window management or is launching into the pinned stack.
+        if (!options.hasLaunchBounds()) {
+            return false;
+        }
+        return (mService.mSupportsPictureInPicture && launchStackId == PINNED_STACK_ID)
+                || mService.mSupportsFreeformWindowManagement;
     }
 
     ActivityStack getStack(int stackId) {
@@ -1806,16 +1803,20 @@
         }
     }
 
-    void resizeStackLocked(int stackId, Rect bounds, boolean preserveWindows,
-            boolean allowResizeInDockedMode) {
+    void resizeStackLocked(int stackId, Rect bounds, Rect tempTaskBounds, Rect tempTaskInsetBounds,
+            boolean preserveWindows, boolean allowResizeInDockedMode) {
+        if (stackId == DOCKED_STACK_ID) {
+            resizeDockedStackLocked(bounds, tempTaskBounds, tempTaskInsetBounds, null, null,
+                    preserveWindows);
+            return;
+        }
         final ActivityStack stack = getStack(stackId);
         if (stack == null) {
             Slog.w(TAG, "resizeStack: stackId " + stackId + " not found.");
             return;
         }
 
-        if (!allowResizeInDockedMode
-                && stackId != DOCKED_STACK_ID && getStack(DOCKED_STACK_ID) != null) {
+        if (!allowResizeInDockedMode && getStack(DOCKED_STACK_ID) != null) {
             // If the docked stack exist we don't allow resizes of stacks not caused by the docked
             // stack size changing so things don't get out of sync.
             return;
@@ -1824,100 +1825,143 @@
         Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeStack_" + stackId);
         mWindowManager.deferSurfaceLayout();
         try {
-
-            if (bounds != null && mWindowManager.isFullscreenBounds(stackId, bounds)) {
-                // The bounds passed in corresponds to the fullscreen bounds which we normally
-                // represent with null. Go ahead and set it to null so that all tasks configuration
-                // can have the right fullscreen state.
-                bounds = null;
-            }
-
-            ActivityRecord r = stack.topRunningActivityLocked();
-
-            mTmpBounds.clear();
-            mTmpConfigs.clear();
-            ArrayList<TaskRecord> tasks = stack.getAllTasks();
-            for (int i = tasks.size() - 1; i >= 0; i--) {
-                TaskRecord task = tasks.get(i);
-                if (task.mResizeable) {
-                    if (stack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
-                        // For freeform stack we don't adjust the size of the tasks to match that
-                        // of the stack, but we do try to make sure the tasks are still contained
-                        // with the bounds of the stack.
-                        tempRect2.set(task.mBounds);
-                        fitWithinBounds(tempRect2, bounds);
-                        task.updateOverrideConfiguration(tempRect2);
-                    } else {
-                        task.updateOverrideConfiguration(bounds);
-                    }
-                }
-
-                mTmpConfigs.put(task.taskId, task.mOverrideConfig);
-                mTmpBounds.put(task.taskId, task.mBounds);
-            }
-            stack.mFullscreen = mWindowManager.resizeStack(stackId, bounds, mTmpConfigs, mTmpBounds);
-            if (stack.mStackId == DOCKED_STACK_ID) {
-                // Dock stack funness...Yay!
-                if (stack.mFullscreen) {
-                    // The dock stack went fullscreen which is kinda like dismissing it.
-                    // In this case we make all other static stacks fullscreen and move all
-                    // docked stack tasks to the fullscreen stack.
-                    for (int i = FIRST_STATIC_STACK_ID; i <= LAST_STATIC_STACK_ID; i++) {
-                        if (StackId.isResizeableByDockedStack(i) && getStack(i) != null) {
-                            resizeStackLocked(i, null, preserveWindows, true);
-                        }
-                    }
-
-                    final int count = tasks.size();
-                    for (int i = 0; i < count; i++) {
-                        moveTaskToStackLocked(tasks.get(i).taskId,
-                                FULLSCREEN_WORKSPACE_STACK_ID, ON_TOP, FORCE_FOCUS, "resizeStack",
-                                false /* animate */);
-                    }
-
-                    // stack shouldn't contain anymore activities, so nothing to resume.
-                    r = null;
-                } else {
-                    // Docked stacks occupy a dedicated region on screen so the size of all other
-                    // static stacks need to be adjusted so they don't overlap with the docked stack.
-                    // We get the bounds to use from window manager which has been adjusted for any
-                    // screen controls and is also the same for all stacks.
-                    mWindowManager.getStackDockedModeBounds(HOME_STACK_ID, tempRect);
-
-                    for (int i = FIRST_STATIC_STACK_ID; i <= LAST_STATIC_STACK_ID; i++) {
-                        if (StackId.isResizeableByDockedStack(i)) {
-                            ActivityStack otherStack = getStack(i);
-                            if (otherStack != null) {
-                                resizeStackLocked(i, tempRect, PRESERVE_WINDOWS, true);
-                            }
-                        }
-                    }
-                }
-                // Since we are resizing the stack, all other operations should strive to preserve
-                // windows.
-                preserveWindows = true;
-            }
-            stack.setBounds(bounds);
-
-            if (r != null) {
-                final boolean updated = stack.ensureActivityConfigurationLocked(r, 0, preserveWindows);
-                // And we need to make sure at this point that all other activities
-                // are made visible with the correct configuration.
-                ensureActivitiesVisibleLocked(r, 0, preserveWindows);
-                if (!updated) {
-                    resumeTopActivitiesLocked(stack, null, null);
-                }
-            }
+            resizeStackUncheckedLocked(stack, bounds, tempTaskBounds, tempTaskInsetBounds);
+            ensureConfigurationAndResume(stack, stack.topRunningActivityLocked(), preserveWindows);
         } finally {
             mWindowManager.continueSurfaceLayout();
             Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
         }
     }
 
-    void resizeTaskLocked(TaskRecord task, Rect bounds, int resizeMode, boolean preserveWindow) {
+    private void resizeStackUncheckedLocked(ActivityStack stack, Rect bounds, Rect tempTaskBounds,
+            Rect tempTaskInsetBounds) {
+        if (bounds != null && mWindowManager.isFullscreenBounds(stack.mStackId, bounds)) {
+            // The bounds passed in corresponds to the fullscreen bounds which we normally
+            // represent with null. Go ahead and set it to null so that all tasks configuration
+            // can have the right fullscreen state.
+            bounds = null;
+        }
+
+        mTmpBounds.clear();
+        mTmpConfigs.clear();
+        mTmpInsetBounds.clear();
+        ArrayList<TaskRecord> tasks = stack.getAllTasks();
+        for (int i = tasks.size() - 1; i >= 0; i--) {
+            TaskRecord task = tasks.get(i);
+            if (task.mResizeable) {
+                if (stack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
+                    // For freeform stack we don't adjust the size of the tasks to match that
+                    // of the stack, but we do try to make sure the tasks are still contained
+                    // with the bounds of the stack.
+                    tempRect2.set(task.mBounds);
+                    fitWithinBounds(tempRect2, bounds);
+                    task.updateOverrideConfiguration(tempRect2);
+                } else {
+                    task.updateOverrideConfiguration(tempTaskBounds != null
+                            ? tempTaskBounds : bounds);
+                }
+            }
+
+            mTmpConfigs.put(task.taskId, task.mOverrideConfig);
+            mTmpBounds.put(task.taskId, task.mBounds);
+            if (tempTaskInsetBounds != null) {
+                mTmpInsetBounds.put(task.taskId, tempTaskInsetBounds);
+            }
+        }
+
+        // We might trigger a configuration change. Save the current task bounds for freezing.
+        mWindowManager.prepareFreezingTaskBounds(stack.mStackId);
+        stack.mFullscreen = mWindowManager.resizeStack(stack.mStackId, bounds, mTmpConfigs,
+                mTmpBounds, mTmpInsetBounds);
+        stack.setBounds(bounds);
+    }
+
+    private void ensureConfigurationAndResume(ActivityStack stack, ActivityRecord r,
+            boolean preserveWindows) {
+        if (r == null) {
+            return;
+        }
+        final boolean updated = stack.ensureActivityConfigurationLocked(r, 0,
+                preserveWindows);
+        // And we need to make sure at this point that all other activities
+        // are made visible with the correct configuration.
+        ensureActivitiesVisibleLocked(r, 0, preserveWindows);
+        if (!updated) {
+            resumeFocusedStackTopActivityLocked();
+        }
+    }
+
+    void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds,
+            Rect tempDockedTaskInsetBounds,
+            Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, boolean preserveWindows) {
+        final ActivityStack stack = getStack(DOCKED_STACK_ID);
+        if (stack == null) {
+            Slog.w(TAG, "resizeDockedStackLocked: docked stack not found");
+            return;
+        }
+
+        Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeDockedStack");
+        mWindowManager.deferSurfaceLayout();
+        try {
+            ActivityRecord r = stack.topRunningActivityLocked();
+            resizeStackUncheckedLocked(stack, dockedBounds, tempDockedTaskBounds,
+                    tempDockedTaskInsetBounds);
+
+            if (stack.mFullscreen) {
+                // The dock stack went fullscreen which is kinda like dismissing it.
+                // In this case we make all other static stacks fullscreen and move all
+                // docked stack tasks to the fullscreen stack.
+                for (int i = FIRST_STATIC_STACK_ID; i <= LAST_STATIC_STACK_ID; i++) {
+                    if (StackId.isResizeableByDockedStack(i) && getStack(i) != null) {
+                        resizeStackLocked(i, null, null, null, preserveWindows,
+                                true /* allowResizeInDockedMode */);
+                    }
+                }
+
+                ArrayList<TaskRecord> tasks = stack.getAllTasks();
+                final int count = tasks.size();
+                for (int i = 0; i < count; i++) {
+                    moveTaskToStackLocked(tasks.get(i).taskId,
+                            FULLSCREEN_WORKSPACE_STACK_ID, ON_TOP, FORCE_FOCUS, "resizeStack",
+                            false /* animate */);
+                }
+
+                // stack shouldn't contain anymore activities, so nothing to resume.
+                r = null;
+            } else {
+                // Docked stacks occupy a dedicated region on screen so the size of all other
+                // static stacks need to be adjusted so they don't overlap with the docked stack.
+                // We get the bounds to use from window manager which has been adjusted for any
+                // screen controls and is also the same for all stacks.
+                mWindowManager.getStackDockedModeBounds(HOME_STACK_ID, tempRect);
+                for (int i = FIRST_STATIC_STACK_ID; i <= LAST_STATIC_STACK_ID; i++) {
+                    if (StackId.isResizeableByDockedStack(i)) {
+                        ActivityStack otherStack = getStack(i);
+                        if (otherStack != null) {
+                            resizeStackLocked(i, tempRect, tempOtherTaskBounds,
+                                    tempOtherTaskInsetBounds, preserveWindows,
+                                    true /* allowResizeInDockedMode */);
+                        }
+                    }
+                }
+            }
+            ensureConfigurationAndResume(stack, r, preserveWindows);
+        } finally {
+            mWindowManager.continueSurfaceLayout();
+            Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
+        }
+
+        mResizeDockedStackTimeout.notifyResizing(dockedBounds,
+                tempDockedTaskBounds != null
+                || tempDockedTaskInsetBounds != null
+                || tempOtherTaskBounds != null
+                || tempOtherTaskInsetBounds != null);
+    }
+
+    boolean resizeTaskLocked(TaskRecord task, Rect bounds, int resizeMode, boolean preserveWindow) {
         if (!task.mResizeable) {
             Slog.w(TAG, "resizeTask: task " + task + " not resizeable.");
-            return;
+            return true;
         }
 
         adjustForMinimalTaskDimensions(task, bounds);
@@ -1927,7 +1971,7 @@
         final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0;
         if (task.mBounds != null && task.mBounds.equals(bounds) && !forced) {
             // Nothing to do here...
-            return;
+            return true;
         }
 
         if (!mWindowManager.isValidTaskId(task.taskId)) {
@@ -1939,7 +1983,7 @@
                 // re-restore the task so it can have the proper stack association.
                 restoreRecentTaskLocked(task, FREEFORM_WORKSPACE_STACK_ID);
             }
-            return;
+            return true;
         }
 
         // Do not move the task to another stack here.
@@ -1961,13 +2005,14 @@
                 // All other activities must be made visible with their correct configuration.
                 ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
                 if (!kept) {
-                    resumeTopActivitiesLocked(stack, null, null);
+                    resumeFocusedStackTopActivityLocked();
                 }
             }
         }
         mWindowManager.resizeTask(task.taskId, bounds, task.mOverrideConfig, kept, forced);
 
         Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
+        return kept;
     }
 
     private void adjustForMinimalTaskDimensions(TaskRecord task, Rect bounds) {
@@ -2083,8 +2128,14 @@
     ActivityStack moveTaskToStackUncheckedLocked(
             TaskRecord task, int stackId, boolean toTop, boolean forceFocus, String reason) {
         final ActivityRecord r = task.getTopActivity();
-        final boolean wasFocused = isFocusedStack(task.stack) && (topRunningActivityLocked() == r);
-        final boolean wasResumed = wasFocused && (task.stack.mResumedActivity == r);
+        final ActivityStack prevStack = task.stack;
+        final boolean wasFocused = isFocusedStack(prevStack) && (topRunningActivityLocked() == r);
+        final boolean wasResumed = wasFocused && (prevStack.mResumedActivity == r);
+        // In some cases the focused stack isn't the front stack. E.g. pinned stack.
+        // Whenever we are moving the top activity from the front stack we want to make sure to move
+        // the stack to the front.
+        final boolean wasFront = isFrontStack(prevStack)
+                && (prevStack.topRunningActivityLocked() == r);
 
         final boolean resizeable = task.mResizeable;
         // Temporarily disable resizeablility of task we are moving. We don't want it to be resized
@@ -2097,9 +2148,9 @@
         stack.addTask(task, toTop, reason);
 
         // If the task had focus before (or we're requested to move focus),
-        // move focus to the new stack.
-        stack.setFocusAndResumeStateIfNeeded(
-                r, forceFocus || wasFocused, wasResumed, reason);
+        // move focus to the new stack by moving the stack to the front.
+        stack.moveToFrontAndResumeStateIfNeeded(
+                r, forceFocus || wasFocused || wasFront, wasResumed, reason);
 
         return stack;
     }
@@ -2119,13 +2170,17 @@
         }
 
         final ActivityRecord topActivity = task.getTopActivity();
-        if (StackId.preserveWindowOnTaskMove(stackId) && topActivity != null) {
+        final boolean mightReplaceWindow =
+                StackId.preserveWindowOnTaskMove(stackId) && topActivity != null;
+        if (mightReplaceWindow) {
             // We are about to relaunch the activity because its configuration changed due to
             // being maximized, i.e. size change. The activity will first remove the old window
             // and then add a new one. This call will tell window manager about this, so it can
             // preserve the old window until the new one is drawn. This prevents having a gap
             // between the removal and addition, in which no window is visible. We also want the
             // entrance of the new window to be properly animated.
+            // Note here we always set the replacing window first, as the flags might be needed
+            // during the relaunch. If we end up not doing any relaunch, we clear the flags later.
             mWindowManager.setReplacingWindow(topActivity.appToken, animate);
         }
         final ActivityStack stack = moveTaskToStackUncheckedLocked(
@@ -2135,21 +2190,29 @@
             stack.mNoAnimActivities.add(topActivity);
         }
 
+        boolean kept = true;
         // Make sure the task has the appropriate bounds/size for the stack it is in.
         if (stackId == FULLSCREEN_WORKSPACE_STACK_ID && task.mBounds != null) {
-            resizeTaskLocked(task, stack.mBounds, RESIZE_MODE_SYSTEM, !PRESERVE_WINDOWS);
+            kept = resizeTaskLocked(task, stack.mBounds, RESIZE_MODE_SYSTEM, !PRESERVE_WINDOWS);
         } else if (stackId == FREEFORM_WORKSPACE_STACK_ID
                 && task.mBounds == null && task.mLastNonFullscreenBounds != null) {
-            resizeTaskLocked(task, task.mLastNonFullscreenBounds,
+            kept = resizeTaskLocked(task, task.mLastNonFullscreenBounds,
                     RESIZE_MODE_SYSTEM, !PRESERVE_WINDOWS);
         } else if (stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID) {
-            resizeTaskLocked(task, stack.mBounds, RESIZE_MODE_SYSTEM, !PRESERVE_WINDOWS);
+            kept = resizeTaskLocked(task, stack.mBounds, RESIZE_MODE_SYSTEM, !PRESERVE_WINDOWS);
+        }
+
+        if (mightReplaceWindow) {
+            // If we didn't actual do a relaunch (indicated by kept==true meaning we kept the old
+            // window), we need to clear the replace window settings. Otherwise, we schedule a
+            // timeout to remove the old window if the replacing window is not coming in time.
+            mWindowManager.scheduleClearReplacingWindowIfNeeded(topActivity.appToken, !kept);
         }
 
         // The task might have already been running and its visibility needs to be synchronized with
         // the visibility of the stack / windows.
         ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
-        resumeTopActivitiesLocked();
+        resumeFocusedStackTopActivityLocked();
 
         if (!task.mResizeable && isStackDockedInEffect(stackId)) {
             showNonResizeableDockToast(taskId);
@@ -2170,7 +2233,7 @@
             return false;
         }
 
-        if (!mService.mForceResizableActivities && !r.info.supportsPip) {
+        if (!mService.mForceResizableActivities && !r.supportsPictureInPicture()) {
             Slog.w(TAG,
                     "moveTopStackActivityToPinnedStackLocked: Picture-In-Picture not supported for "
                             + " r=" + r);
@@ -2194,13 +2257,18 @@
         }
 
         if (bounds != null) {
-            resizeStackLocked(stackId, bounds, !PRESERVE_WINDOWS, true);
+            resizeStackLocked(stackId, bounds, null /* tempTaskBounds */,
+                    null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, true);
         }
 
         // The task might have already been running and its visibility needs to be synchronized with
         // the visibility of the stack / windows.
         ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
-        resumeTopActivitiesLocked();
+        resumeFocusedStackTopActivityLocked();
+
+        if (stackId == PINNED_STACK_ID) {
+            mService.notifyActivityPinnedLocked();
+        }
     }
 
     void positionTaskInStackLocked(int taskId, int stackId, int position) {
@@ -2219,7 +2287,7 @@
         // The task might have already been running and its visibility needs to be synchronized with
         // the visibility of the stack / windows.
         stack.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
-        resumeTopActivitiesLocked();
+        resumeFocusedStackTopActivityLocked();
     }
 
     ActivityRecord findTaskLocked(ActivityRecord r) {
@@ -2329,7 +2397,7 @@
                 final ActivityStack stack = stacks.get(stackNdx);
                 stack.awakeFromSleepingLocked();
                 if (isFocusedStack(stack)) {
-                    resumeTopActivitiesLocked();
+                    resumeFocusedStackTopActivityLocked();
                 }
             }
         }
@@ -3124,7 +3192,7 @@
                     if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK,
                             "setLockTaskModeLocked: Tasks remaining, can't unlock");
                     lockedTask.performClearTaskLocked();
-                    resumeTopActivitiesLocked();
+                    resumeFocusedStackTopActivityLocked();
                     return;
                 }
             }
@@ -3165,7 +3233,7 @@
 
         if (andResume) {
             findTaskToMoveToFrontLocked(task, 0, null, reason);
-            resumeTopActivitiesLocked();
+            resumeFocusedStackTopActivityLocked();
         }
     }
 
@@ -3233,7 +3301,7 @@
             didSomething = true;
         }
         if (didSomething) {
-            resumeTopActivitiesLocked();
+            resumeFocusedStackTopActivityLocked();
         }
     }
 
@@ -3241,6 +3309,14 @@
         return mLockTaskModeState;
     }
 
+    void activityRelaunchedLocked(IBinder token) {
+        mWindowManager.notifyAppRelaunchingFinished(token);
+    }
+
+    void activityRelaunchingLocked(ActivityRecord r) {
+        mWindowManager.notifyAppRelaunching(r.appToken);
+    }
+
     void logStackState() {
         mActivityMetricsLogger.logWindowState();
     }
@@ -3280,7 +3356,7 @@
                 } break;
                 case RESUME_TOP_ACTIVITY_MSG: {
                     synchronized (mService) {
-                        resumeTopActivitiesLocked();
+                        resumeFocusedStackTopActivityLocked();
                     }
                 } break;
                 case SLEEP_TIMEOUT_MSG: {
@@ -3661,7 +3737,7 @@
 
             mSurface = surface;
             if (surface != null) {
-                mStack.resumeTopActivityLocked(null);
+                resumeFocusedStackTopActivityLocked();
             } else {
                 mContainerState = CONTAINER_STATE_NO_SURFACE;
                 ((VirtualActivityDisplay) mActivityDisplay).setSurface(null);
diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java
index b16e160..f712613 100644
--- a/services/core/java/com/android/server/am/ActivityStarter.java
+++ b/services/core/java/com/android/server/am/ActivityStarter.java
@@ -1,14 +1,47 @@
 package com.android.server.am;
 
+import static android.app.Activity.RESULT_CANCELED;
+import static android.app.ActivityManager.INTENT_SENDER_ACTIVITY;
+import static android.app.ActivityManager.START_CLASS_NOT_FOUND;
+import static android.app.ActivityManager.START_DELIVERED_TO_TOP;
+import static android.app.ActivityManager.START_FLAG_ONLY_IF_NEEDED;
+import static android.app.ActivityManager.START_RETURN_INTENT_TO_CALLER;
+import static android.app.ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
+import static android.app.ActivityManager.START_SUCCESS;
+import static android.app.ActivityManager.START_TASK_TO_FRONT;
+import static android.app.ActivityManager.StackId;
 import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
 import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
 import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
+import static android.app.ActivityManager.StackId.HOME_STACK_ID;
+import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
+import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
+import static android.app.PendingIntent.FLAG_CANCEL_CURRENT;
+import static android.app.PendingIntent.FLAG_IMMUTABLE;
+import static android.app.PendingIntent.FLAG_ONE_SHOT;
+import static android.content.Context.KEYGUARD_SERVICE;
+import static android.content.Intent.EXTRA_INTENT;
+import static android.content.Intent.EXTRA_PACKAGE_NAME;
+import static android.content.Intent.EXTRA_TASK_ID;
 import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
 import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
+import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
 import static android.content.Intent.FLAG_ACTIVITY_LAUNCH_TO_SIDE;
 import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
+import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
 import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
+import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
+import static android.content.Intent.FLAG_ACTIVITY_NO_USER_ACTION;
 import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
+import static android.content.Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP;
+import static android.content.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT;
+import static android.content.Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED;
+import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
+import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
+import static android.content.pm.ActivityInfo.DOCUMENT_LAUNCH_ALWAYS;
+import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
+import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK;
+import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOCUS;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PERMISSIONS_REVIEW;
@@ -42,7 +75,6 @@
 import android.app.PendingIntent;
 import android.app.ProfilerInfo;
 import android.content.ComponentName;
-import android.content.Context;
 import android.content.IIntentSender;
 import android.content.Intent;
 import android.content.IntentSender;
@@ -67,7 +99,6 @@
 
 import com.android.internal.app.HeavyWeightSwitcherActivity;
 import com.android.internal.app.IVoiceInteractor;
-import com.android.internal.widget.LockPatternUtils;
 import com.android.server.am.ActivityStackSupervisor.PendingActivityLaunch;
 import com.android.server.wm.WindowManagerService;
 
@@ -79,7 +110,7 @@
  * This class collects all the logic for determining how an intent and flags should be turned into
  * an activity and associated task and stack.
  */
-public class ActivityStarter {
+class ActivityStarter {
     private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStarter" : TAG_AM;
     private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS;
     private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS;
@@ -92,6 +123,79 @@
 
     final ArrayList<PendingActivityLaunch> mPendingActivityLaunches = new ArrayList<>();
 
+    // Share state variable among methods when starting an activity.
+    private ActivityRecord mStartActivity;
+    private Intent mIntent;
+    private int mCallingUid;
+    private ActivityOptions mOptions;
+
+    private boolean mLaunchSingleTop;
+    private boolean mLaunchSingleInstance;
+    private boolean mLaunchSingleTask;
+    private boolean mLaunchTaskBehind;
+    private int mLaunchFlags;
+
+    private Rect mLaunchBounds;
+
+    private ActivityRecord mNotTop;
+    private boolean mDoResume;
+    private int mStartFlags;
+    private ActivityRecord mSourceRecord;
+
+    private TaskRecord mInTask;
+    private boolean mAddingToTask;
+    private TaskRecord mReuseTask;
+
+    private ActivityInfo mNewTaskInfo;
+    private Intent mNewTaskIntent;
+    private ActivityStack mSourceStack;
+    private ActivityStack mTargetStack;
+    // TODO: Is the mMoveHome flag really needed?
+    private boolean mMovedHome;
+    private boolean mMovedToFront;
+    private boolean mNoAnimation;
+    private boolean mKeepCurTransition;
+
+    private IVoiceInteractionSession mVoiceSession;
+    private IVoiceInteractor mVoiceInteractor;
+
+    private void reset() {
+        mStartActivity = null;
+        mIntent = null;
+        mCallingUid = -1;
+        mOptions = null;
+
+        mLaunchSingleTop = false;
+        mLaunchSingleInstance = false;
+        mLaunchSingleTask = false;
+        mLaunchTaskBehind = false;
+        mLaunchFlags = 0;
+
+        mLaunchBounds = null;
+
+        mNotTop = null;
+        mDoResume = false;
+        mStartFlags = 0;
+        mSourceRecord = null;
+
+        mInTask = null;
+        mAddingToTask = false;
+        mReuseTask = null;
+
+        mNewTaskInfo = null;
+        mNewTaskIntent = null;
+        mSourceStack = null;
+
+        mTargetStack = null;
+        mMovedHome = false;
+        mMovedToFront = false;
+        mNoAnimation = false;
+        mKeepCurTransition = false;
+
+        mVoiceSession = null;
+        mVoiceInteractor = null;
+    }
+
     ActivityStarter(ActivityManagerService service, ActivityStackSupervisor supervisor) {
         mService = service;
         mSupervisor = supervisor;
@@ -234,11 +338,10 @@
 
         final ActivityStack resultStack = resultRecord == null ? null : resultRecord.task.stack;
 
-        if (err != ActivityManager.START_SUCCESS) {
+        if (err != START_SUCCESS) {
             if (resultRecord != null) {
-                resultStack.sendActivityResultLocked(-1,
-                        resultRecord, resultWho, requestCode,
-                        Activity.RESULT_CANCELED, null);
+                resultStack.sendActivityResultLocked(
+                        -1, resultRecord, resultWho, requestCode, RESULT_CANCELED, null);
             }
             ActivityOptions.abort(options);
             return err;
@@ -262,48 +365,36 @@
             }
         }
 
-        UserInfo user = mSupervisor.getUserInfo(userId);
-        KeyguardManager km = (KeyguardManager) mService.mContext
-                .getSystemService(Context.KEYGUARD_SERVICE);
-        if (user.isManagedProfile()
-                && LockPatternUtils.isSeparateWorkChallengeEnabled()
-                && km.isDeviceLocked(userId)) {
-            IIntentSender target = mService.getIntentSenderLocked(
-                    ActivityManager.INTENT_SENDER_ACTIVITY, callingPackage,
-                    Binder.getCallingUid(), userId, null, null, 0, new Intent[]{ intent },
-                    new String[]{ resolvedType },
-                    PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT
-                            | PendingIntent.FLAG_IMMUTABLE, null);
-            final int flags = intent.getFlags();
-            final Intent newIntent = km.createConfirmDeviceCredentialIntent(null, null, user.id);
-            if (newIntent != null) {
-                intent = newIntent;
-                intent.setFlags(flags
-                        | Intent.FLAG_ACTIVITY_NEW_TASK
-                        | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
-                intent.putExtra(Intent.EXTRA_PACKAGE_NAME, aInfo.packageName);
-                intent.putExtra(Intent.EXTRA_INTENT, new IntentSender(target));
-
-                resolvedType = null;
-                callingUid = realCallingUid;
-                callingPid = realCallingPid;
-
-                UserInfo parent = UserManager.get(mService.mContext).getProfileParent(userId);
-                rInfo = mSupervisor.resolveIntent(intent, resolvedType, parent.id);
-                aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags,
-                        null /*profilerInfo*/);
+        final Intent interceptingIntent = interceptWithConfirmCredentialsIfNeeded(intent,
+                resolvedType, aInfo, callingPackage, userId);
+        if (interceptingIntent != null) {
+            intent = interceptingIntent;
+            callingPid = realCallingPid;
+            callingUid = realCallingUid;
+            resolvedType = null;
+            // If we are intercepting and there was a task, convert it into an extra for the
+            // ConfirmCredentials intent and unassign it, as otherwise the task will move to
+            // front even if ConfirmCredentials is cancelled.
+            if (inTask != null) {
+                intent.putExtra(EXTRA_TASK_ID, inTask.taskId);
+                inTask = null;
             }
+
+            final UserInfo parent = UserManager.get(mService.mContext).getProfileParent(userId);
+            rInfo = mSupervisor.resolveIntent(intent, resolvedType, parent.id);
+            aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags,
+                    null /*profilerInfo*/);
         }
 
         if (abort) {
             if (resultRecord != null) {
                 resultStack.sendActivityResultLocked(-1, resultRecord, resultWho, requestCode,
-                        Activity.RESULT_CANCELED, null);
+                        RESULT_CANCELED, null);
             }
             // We pretend to the caller that it was really started, but
             // they will just get a cancel result.
             ActivityOptions.abort(options);
-            return ActivityManager.START_SUCCESS;
+            return START_SUCCESS;
         }
 
         // If permissions need a review before any of the app components can run, we
@@ -429,8 +520,8 @@
 
         doPendingActivityLaunchesLocked(false);
 
-        err = startActivityUncheckedLocked(r, sourceRecord, voiceSession,
-                voiceInteractor, startFlags, true, options, inTask);
+        err = startActivityUnchecked(
+                r, sourceRecord, voiceSession, voiceInteractor, startFlags, true, options, inTask);
 
         if (err < 0) {
             // If someone asked to have the keyguard dismissed on the next
@@ -442,6 +533,34 @@
         return err;
     }
 
+    /**
+     * Creates an intent to intercept the current activity start with Confirm Credentials if needed.
+     *
+     * @return The intercepting intent if needed.
+     */
+    private Intent interceptWithConfirmCredentialsIfNeeded(Intent intent, String resolvedType,
+            ActivityInfo aInfo, String callingPackage, int userId) {
+        if (!mService.mUserController.shouldConfirmCredentials(userId)) {
+            return null;
+        }
+        final IIntentSender target = mService.getIntentSenderLocked(
+                INTENT_SENDER_ACTIVITY, callingPackage,
+                Binder.getCallingUid(), userId, null, null, 0, new Intent[]{ intent },
+                new String[]{ resolvedType },
+                FLAG_CANCEL_CURRENT | FLAG_ONE_SHOT | FLAG_IMMUTABLE, null);
+        final int flags = intent.getFlags();
+        final KeyguardManager km = (KeyguardManager) mService.mContext
+                .getSystemService(KEYGUARD_SERVICE);
+        final Intent newIntent = km.createConfirmDeviceCredentialIntent(null, null, userId);
+        if (newIntent == null) {
+            return null;
+        }
+        newIntent.setFlags(flags | FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+        newIntent.putExtra(EXTRA_PACKAGE_NAME, aInfo.packageName);
+        newIntent.putExtra(EXTRA_INTENT, new IntentSender(target));
+        return newIntent;
+    }
+
     void startHomeActivityLocked(Intent intent, ActivityInfo aInfo, String reason) {
         mSupervisor.moveHomeStackTaskToTop(HOME_ACTIVITY_TYPE, reason);
         startActivityLocked(null /*caller*/, intent, null /*ephemeralIntent*/,
@@ -608,7 +727,7 @@
                         } catch (InterruptedException e) {
                         }
                     } while (!outResult.timeout && outResult.who == null);
-                } else if (res == ActivityManager.START_TASK_TO_FRONT) {
+                } else if (res == START_TASK_TO_FRONT) {
                     ActivityRecord r = stack.topRunningActivityLocked();
                     if (r.nowVisible && r.state == RESUMED) {
                         outResult.timeout = false;
@@ -632,682 +751,6 @@
         }
     }
 
-    final int startActivityUncheckedLocked(final ActivityRecord r, ActivityRecord sourceRecord,
-            IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, int startFlags,
-            boolean doResume, ActivityOptions options, TaskRecord inTask) {
-        final Intent intent = r.intent;
-        final int callingUid = r.launchedFromUid;
-
-        final Rect newBounds = mSupervisor.getOverrideBounds(r, options, inTask);
-        final boolean overrideBounds = newBounds != null;
-
-        // In some flows in to this function, we retrieve the task record and hold on to it
-        // without a lock before calling back in to here...  so the task at this point may
-        // not actually be in recents.  Check for that, and if it isn't in recents just
-        // consider it invalid.
-        if (inTask != null && !inTask.inRecents) {
-            Slog.w(TAG, "Starting activity in task not in recents: " + inTask);
-            inTask = null;
-        }
-
-        final boolean launchSingleTop = r.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP;
-        final boolean launchSingleInstance = r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE;
-        final boolean launchSingleTask = r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK;
-        int launchFlags = adjustLaunchFlagsToDocumentMode(r, launchSingleInstance, launchSingleTask,
-                intent.getFlags());
-        final boolean launchTaskBehind = r.mLaunchTaskBehind
-                && !launchSingleTask && !launchSingleInstance
-                && (launchFlags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0;
-
-        if (r.resultTo != null && (launchFlags & FLAG_ACTIVITY_NEW_TASK) != 0
-                && r.resultTo.task.stack != null) {
-            // For whatever reason this activity is being launched into a new
-            // task...  yet the caller has requested a result back.  Well, that
-            // is pretty messed up, so instead immediately send back a cancel
-            // and let the new task continue launched as normal without a
-            // dependency on its originator.
-            Slog.w(TAG, "Activity is launching as a new task, so cancelling activity result.");
-            r.resultTo.task.stack.sendActivityResultLocked(-1,
-                    r.resultTo, r.resultWho, r.requestCode,
-                    Activity.RESULT_CANCELED, null);
-            r.resultTo = null;
-        }
-
-        if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0 && r.resultTo == null) {
-            launchFlags |= FLAG_ACTIVITY_NEW_TASK;
-        }
-
-        // If we are actually going to launch in to a new task, there are some cases where
-        // we further want to do multiple task.
-        if ((launchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) {
-            if (launchTaskBehind
-                    || r.info.documentLaunchMode == ActivityInfo.DOCUMENT_LAUNCH_ALWAYS) {
-                launchFlags |= FLAG_ACTIVITY_MULTIPLE_TASK;
-            }
-        }
-
-        // We'll invoke onUserLeaving before onPause only if the launching
-        // activity did not explicitly state that this is an automated launch.
-        mSupervisor.mUserLeaving = (launchFlags & Intent.FLAG_ACTIVITY_NO_USER_ACTION) == 0;
-        if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING,
-                "startActivity() => mUserLeaving=" + mSupervisor.mUserLeaving);
-
-        // If the caller has asked not to resume at this point, we make note
-        // of this in the record so that we can skip it when trying to find
-        // the top running activity.
-        if (!doResume || !mSupervisor.okToShowLocked(r)) {
-            r.delayedResume = true;
-            doResume = false;
-        }
-
-        final ActivityRecord notTop =
-                (launchFlags & Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP) != 0 ? r : null;
-
-        // If the onlyIfNeeded flag is set, then we can do this if the activity
-        // being launched is the same as the one making the call...  or, as
-        // a special case, if we do not know the caller then we count the
-        // current top activity as the caller.
-        if ((startFlags&ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
-            ActivityRecord checkedCaller = sourceRecord;
-            if (checkedCaller == null) {
-                checkedCaller = mSupervisor.mFocusedStack.topRunningNonDelayedActivityLocked(
-                        notTop);
-            }
-            if (!checkedCaller.realActivity.equals(r.realActivity)) {
-                // Caller is not the same as launcher, so always needed.
-                startFlags &= ~ActivityManager.START_FLAG_ONLY_IF_NEEDED;
-            }
-        }
-
-        boolean addingToTask = false;
-        TaskRecord reuseTask = null;
-
-        // If the caller is not coming from another activity, but has given us an
-        // explicit task into which they would like us to launch the new activity,
-        // then let's see about doing that.
-        if (sourceRecord == null && inTask != null && inTask.stack != null) {
-            final Intent baseIntent = inTask.getBaseIntent();
-            final ActivityRecord root = inTask.getRootActivity();
-            if (baseIntent == null) {
-                ActivityOptions.abort(options);
-                throw new IllegalArgumentException("Launching into task without base intent: "
-                        + inTask);
-            }
-
-            // If this task is empty, then we are adding the first activity -- it
-            // determines the root, and must be launching as a NEW_TASK.
-            if (launchSingleInstance || launchSingleTask) {
-                if (!baseIntent.getComponent().equals(r.intent.getComponent())) {
-                    ActivityOptions.abort(options);
-                    throw new IllegalArgumentException("Trying to launch singleInstance/Task "
-                            + r + " into different task " + inTask);
-                }
-                if (root != null) {
-                    ActivityOptions.abort(options);
-                    throw new IllegalArgumentException("Caller with inTask " + inTask
-                            + " has root " + root + " but target is singleInstance/Task");
-                }
-            }
-
-            // If task is empty, then adopt the interesting intent launch flags in to the
-            // activity being started.
-            if (root == null) {
-                final int flagsOfInterest = FLAG_ACTIVITY_NEW_TASK
-                        | FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT
-                        | Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
-                launchFlags = (launchFlags&~flagsOfInterest)
-                        | (baseIntent.getFlags()&flagsOfInterest);
-                intent.setFlags(launchFlags);
-                inTask.setIntent(r);
-                addingToTask = true;
-
-                // If the task is not empty and the caller is asking to start it as the root
-                // of a new task, then we don't actually want to start this on the task.  We
-                // will bring the task to the front, and possibly give it a new intent.
-            } else if ((launchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) {
-                addingToTask = false;
-
-            } else {
-                addingToTask = true;
-            }
-
-            reuseTask = inTask;
-        } else {
-            inTask = null;
-            // Launch ResolverActivity in the source task, so that it stays in the task
-            // bounds when in freeform workspace.
-            // Also put noDisplay activities in the source task. These by itself can
-            // be placed in any task/stack, however it could launch other activities
-            // like ResolverActivity, and we want those to stay in the original task.
-            if ((r.isResolverActivity() || r.noDisplay) && sourceRecord != null
-                    && sourceRecord.isFreeform())  {
-                addingToTask = true;
-            }
-        }
-
-        if (inTask == null) {
-            if (sourceRecord == null) {
-                // This activity is not being started from another...  in this
-                // case we -always- start a new task.
-                if ((launchFlags & FLAG_ACTIVITY_NEW_TASK) == 0 && inTask == null) {
-                    Slog.w(TAG, "startActivity called from non-Activity context; forcing " +
-                            "Intent.FLAG_ACTIVITY_NEW_TASK for: " + intent);
-                    launchFlags |= FLAG_ACTIVITY_NEW_TASK;
-                }
-            } else if (sourceRecord.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
-                // The original activity who is starting us is running as a single
-                // instance...  this new activity it is starting must go on its
-                // own task.
-                launchFlags |= FLAG_ACTIVITY_NEW_TASK;
-            } else if (launchSingleInstance || launchSingleTask) {
-                // The activity being started is a single instance...  it always
-                // gets launched into its own task.
-                launchFlags |= FLAG_ACTIVITY_NEW_TASK;
-            }
-        }
-
-        ActivityInfo newTaskInfo = null;
-        Intent newTaskIntent = null;
-        final ActivityStack sourceStack;
-        if (sourceRecord != null) {
-            if (sourceRecord.finishing) {
-                // If the source is finishing, we can't further count it as our source.  This
-                // is because the task it is associated with may now be empty and on its way out,
-                // so we don't want to blindly throw it in to that task.  Instead we will take
-                // the NEW_TASK flow and try to find a task for it. But save the task information
-                // so it can be used when creating the new task.
-                if ((launchFlags & FLAG_ACTIVITY_NEW_TASK) == 0) {
-                    Slog.w(TAG, "startActivity called from finishing " + sourceRecord
-                            + "; forcing " + "Intent.FLAG_ACTIVITY_NEW_TASK for: " + intent);
-                    launchFlags |= FLAG_ACTIVITY_NEW_TASK;
-                    newTaskInfo = sourceRecord.info;
-                    newTaskIntent = sourceRecord.task.intent;
-                }
-                sourceRecord = null;
-                sourceStack = null;
-            } else {
-                sourceStack = sourceRecord.task.stack;
-            }
-        } else {
-            sourceStack = null;
-        }
-
-        boolean movedHome = false;
-        ActivityStack targetStack;
-
-        intent.setFlags(launchFlags);
-        final boolean noAnimation = (launchFlags & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0;
-
-        ActivityRecord intentActivity = getReusableIntentActivity(r, inTask, intent,
-                launchSingleInstance, launchSingleTask, launchFlags);
-        if (intentActivity != null) {
-            // When the flags NEW_TASK and CLEAR_TASK are set, then the task gets reused
-            // but still needs to be a lock task mode violation since the task gets
-            // cleared out and the device would otherwise leave the locked task.
-            if (mSupervisor.isLockTaskModeViolation(intentActivity.task,
-                    (launchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK))
-                            == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK))) {
-                mSupervisor.showLockTaskToast();
-                Slog.e(TAG, "startActivityUnchecked: Attempt to violate Lock Task Mode");
-                return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
-            }
-            if (r.task == null) {
-                r.task = intentActivity.task;
-            }
-            if (intentActivity.task.intent == null) {
-                // This task was started because of movement of the activity based on affinity...
-                // Now that we are actually launching it, we can assign the base intent.
-                intentActivity.task.setIntent(r);
-            }
-
-            targetStack = intentActivity.task.stack;
-            targetStack.mLastPausedActivity = null;
-            // If the target task is not in the front, then we need
-            // to bring it to the front...  except...  well, with
-            // SINGLE_TASK_LAUNCH it's not entirely clear.  We'd like
-            // to have the same behavior as if a new instance was
-            // being started, which means not bringing it to the front
-            // if the caller is not itself in the front.
-            final ActivityStack focusStack = mSupervisor.getFocusedStack();
-            ActivityRecord curTop = (focusStack == null)
-                    ? null : focusStack.topRunningNonDelayedActivityLocked(notTop);
-            boolean movedToFront = false;
-            if (curTop != null && (curTop.task != intentActivity.task ||
-                    curTop.task != focusStack.topTask())) {
-                r.intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
-                if (sourceRecord == null || (sourceStack.topActivity() != null &&
-                        sourceStack.topActivity().task == sourceRecord.task)) {
-                    // We really do want to push this one into the user's face, right now.
-                    if (launchTaskBehind && sourceRecord != null) {
-                        intentActivity.setTaskToAffiliateWith(sourceRecord.task);
-                    }
-                    movedHome = true;
-                    final ActivityStack sideStack = getLaunchToSideStack(r, launchFlags, r.task);
-                    if (sideStack == null || sideStack == targetStack) {
-                        // We only want to move to the front, if we aren't going to launch on a
-                        // different stack. If we launch on a different stack, we will put the
-                        // task on top there.
-                        targetStack.moveTaskToFrontLocked(intentActivity.task, noAnimation,
-                                options, r.appTimeTracker, "bringingFoundTaskToFront");
-                        movedToFront = true;
-                    }
-                    if ((launchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME))
-                            == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
-                        // Caller wants to appear on home activity.
-                        intentActivity.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
-                    }
-                    options = null;
-                }
-            }
-            if (!movedToFront && doResume) {
-                if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Bring to front target: " + targetStack
-                        + " from " + intentActivity);
-                targetStack.moveToFront("intentActivityFound");
-            }
-
-            // If the caller has requested that the target task be
-            // reset, then do so.
-            if ((launchFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
-                intentActivity = targetStack.resetTaskIfNeededLocked(intentActivity, r);
-            }
-            if ((startFlags & ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
-                // We don't need to start a new activity, and
-                // the client said not to do anything if that
-                // is the case, so this is it!  And for paranoia, make
-                // sure we have correctly resumed the top activity.
-                if (doResume) {
-                    mSupervisor.resumeTopActivitiesLocked(targetStack, null, options);
-
-                    // Make sure to notify Keyguard as well if we are not running an app
-                    // transition later.
-                    if (!movedToFront) {
-                        mSupervisor.notifyActivityDrawnForKeyguard();
-                    }
-                } else {
-                    ActivityOptions.abort(options);
-                }
-                mSupervisor.updateUserStackLocked(r.userId, targetStack);
-                return ActivityManager.START_RETURN_INTENT_TO_CALLER;
-            }
-            if ((launchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK))
-                    == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) {
-                // The caller has requested to completely replace any
-                // existing task with its new activity.  Well that should
-                // not be too hard...
-                reuseTask = intentActivity.task;
-                reuseTask.performClearTaskLocked();
-                reuseTask.setIntent(r);
-            } else if ((launchFlags & FLAG_ACTIVITY_CLEAR_TOP) != 0
-                    || launchSingleInstance || launchSingleTask) {
-                // In this situation we want to remove all activities
-                // from the task up to the one being started.  In most
-                // cases this means we are resetting the task to its
-                // initial state.
-                ActivityRecord top = intentActivity.task.performClearTaskLocked(r, launchFlags);
-                if (top != null) {
-                    if (top.frontOfTask) {
-                        // Activity aliases may mean we use different
-                        // intents for the top activity, so make sure
-                        // the task now has the identity of the new
-                        // intent.
-                        top.task.setIntent(r);
-                    }
-                    ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, r, top.task);
-                    top.deliverNewIntentLocked(callingUid, r.intent, r.launchedFromPackage);
-                } else {
-                    // A special case: we need to start the activity because it is not
-                    // currently running, and the caller has asked to clear the current
-                    // task to have this activity at the top.
-                    addingToTask = true;
-                    // Now pretend like this activity is being started by the top of its
-                    // task, so it is put in the right place.
-                    sourceRecord = intentActivity;
-                    TaskRecord task = sourceRecord.task;
-                    if (task != null && task.stack == null) {
-                        // Target stack got cleared when we all activities were removed
-                        // above. Go ahead and reset it.
-                        targetStack = computeStackFocus(
-                                sourceRecord, false /* newTask */, null /* bounds */, launchFlags);
-                        targetStack.addTask(task,
-                                !launchTaskBehind /* toTop */, "startActivityUnchecked");
-                    }
-
-                }
-            } else if (r.realActivity.equals(intentActivity.task.realActivity)) {
-                // In this case the top activity on the task is the
-                // same as the one being launched, so we take that
-                // as a request to bring the task to the foreground.
-                // If the top activity in the task is the root
-                // activity, deliver this new intent to it if it
-                // desires.
-                if (((launchFlags&Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0 || launchSingleTop)
-                        && intentActivity.realActivity.equals(r.realActivity)) {
-                    ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, r,
-                            intentActivity.task);
-                    if (intentActivity.frontOfTask) {
-                        intentActivity.task.setIntent(r);
-                    }
-                    intentActivity.deliverNewIntentLocked(callingUid, r.intent,
-                            r.launchedFromPackage);
-                } else if (!r.intent.filterEquals(intentActivity.task.intent)) {
-                    // In this case we are launching the root activity
-                    // of the task, but with a different intent.  We
-                    // should start a new instance on top.
-                    addingToTask = true;
-                    sourceRecord = intentActivity;
-                }
-            } else if ((launchFlags&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) == 0) {
-                // In this case an activity is being launched in to an
-                // existing task, without resetting that task.  This
-                // is typically the situation of launching an activity
-                // from a notification or shortcut.  We want to place
-                // the new activity on top of the current task.
-                addingToTask = true;
-                sourceRecord = intentActivity;
-            } else if (!intentActivity.task.rootWasReset) {
-                // In this case we are launching in to an existing task
-                // that has not yet been started from its front door.
-                // The current task has been brought to the front.
-                // Ideally, we'd probably like to place this new task
-                // at the bottom of its stack, but that's a little hard
-                // to do with the current organization of the code so
-                // for now we'll just drop it.
-                intentActivity.task.setIntent(r);
-            }
-            if (!addingToTask && reuseTask == null) {
-                // We didn't do anything...  but it was needed (a.k.a., client
-                // don't use that intent!)  And for paranoia, make
-                // sure we have correctly resumed the top activity.
-                if (doResume) {
-                    targetStack.resumeTopActivityLocked(null, options);
-                    if (!movedToFront) {
-                        // Make sure to notify Keyguard as well if we are not running an app
-                        // transition later.
-                        mSupervisor.notifyActivityDrawnForKeyguard();
-                    }
-                } else {
-                    ActivityOptions.abort(options);
-                }
-                mSupervisor.updateUserStackLocked(r.userId, targetStack);
-                return ActivityManager.START_TASK_TO_FRONT;
-            }
-        }
-
-        //String uri = r.intent.toURI();
-        //Intent intent2 = new Intent(uri);
-        //Slog.i(TAG, "Given intent: " + r.intent);
-        //Slog.i(TAG, "URI is: " + uri);
-        //Slog.i(TAG, "To intent: " + intent2);
-
-        if (r.packageName != null) {
-            // If the activity being launched is the same as the one currently
-            // at the top, then we need to check if it should only be launched
-            // once.
-            ActivityStack topStack = mSupervisor.mFocusedStack;
-            ActivityRecord top = topStack.topRunningNonDelayedActivityLocked(notTop);
-            final boolean dontStart = top != null && r.resultTo == null
-                    && top.realActivity.equals(r.realActivity) && top.userId == r.userId
-                    && top.app != null && top.app.thread != null
-                    && ((launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0
-                    || launchSingleTop || launchSingleTask);
-            if (dontStart) {
-                ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, top, top.task);
-                // For paranoia, make sure we have correctly resumed the top activity.
-                topStack.mLastPausedActivity = null;
-                if (doResume) {
-                    mSupervisor.resumeTopActivitiesLocked();
-                }
-                ActivityOptions.abort(options);
-                if ((startFlags & ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
-                    // We don't need to start a new activity, and the client said not to do
-                    // anything if that is the case, so this is it!
-                    return ActivityManager.START_RETURN_INTENT_TO_CALLER;
-                }
-                top.deliverNewIntentLocked(callingUid, r.intent, r.launchedFromPackage);
-                return ActivityManager.START_DELIVERED_TO_TOP;
-            }
-        } else {
-            if (r.resultTo != null && r.resultTo.task.stack != null) {
-                r.resultTo.task.stack.sendActivityResultLocked(-1, r.resultTo, r.resultWho,
-                        r.requestCode, Activity.RESULT_CANCELED, null);
-            }
-            ActivityOptions.abort(options);
-            return ActivityManager.START_CLASS_NOT_FOUND;
-        }
-
-        boolean newTask = false;
-        boolean keepCurTransition = false;
-
-        final TaskRecord taskToAffiliate = launchTaskBehind && sourceRecord != null ?
-                sourceRecord.task : null;
-
-        // Should this be considered a new task?
-        if (r.resultTo == null && inTask == null && !addingToTask
-                && (launchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) {
-            newTask = true;
-            targetStack = computeStackFocus(r, newTask, newBounds, launchFlags);
-            if (doResume) {
-                targetStack.moveToFront("startingNewTask");
-            }
-
-            if (reuseTask == null) {
-                r.setTask(targetStack.createTaskRecord(mSupervisor.getNextTaskId(),
-                        newTaskInfo != null ? newTaskInfo : r.info,
-                        newTaskIntent != null ? newTaskIntent : intent,
-                        voiceSession, voiceInteractor, !launchTaskBehind /* toTop */),
-                        taskToAffiliate);
-                if (overrideBounds) {
-                    r.task.updateOverrideConfiguration(newBounds);
-                }
-                if (DEBUG_TASKS) Slog.v(TAG_TASKS,
-                        "Starting new activity " + r + " in new task " + r.task);
-            } else {
-                r.setTask(reuseTask, taskToAffiliate);
-            }
-            if (mSupervisor.isLockTaskModeViolation(r.task)) {
-                Slog.e(TAG, "Attempted Lock Task Mode violation r=" + r);
-                return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
-            }
-            if (!movedHome) {
-                if ((launchFlags &
-                        (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME))
-                        == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
-                    // Caller wants to appear on home activity, so before starting
-                    // their own activity we will bring home to the front.
-                    r.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
-                }
-            }
-        } else if (sourceRecord != null) {
-            final TaskRecord sourceTask = sourceRecord.task;
-            if (mSupervisor.isLockTaskModeViolation(sourceTask)) {
-                Slog.e(TAG, "Attempted Lock Task Mode violation r=" + r);
-                return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
-            }
-            targetStack = null;
-            if (sourceTask.stack.topTask() != sourceTask) {
-                // We only want to allow changing stack if the target task is not the top one,
-                // otherwise we would move the launching task to the other side, rather than show
-                // two side by side.
-                targetStack = getLaunchToSideStack(r, launchFlags, r.task);
-            }
-            if (targetStack == null) {
-                targetStack = sourceTask.stack;
-            } else if (targetStack != sourceTask.stack) {
-                mSupervisor.moveTaskToStackLocked(sourceTask.taskId, targetStack.mStackId,
-                        ON_TOP, FORCE_FOCUS, "launchToSide", !ANIMATE);
-            }
-            if (doResume) {
-                targetStack.moveToFront("sourceStackToFront");
-            }
-            final TaskRecord topTask = targetStack.topTask();
-            if (topTask != sourceTask) {
-                targetStack.moveTaskToFrontLocked(sourceTask, noAnimation, options,
-                        r.appTimeTracker, "sourceTaskToFront");
-            }
-            if (!addingToTask && (launchFlags&Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) {
-                // In this case, we are adding the activity to an existing
-                // task, but the caller has asked to clear that task if the
-                // activity is already running.
-                ActivityRecord top = sourceTask.performClearTaskLocked(r, launchFlags);
-                keepCurTransition = true;
-                if (top != null) {
-                    ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, r, top.task);
-                    top.deliverNewIntentLocked(callingUid, r.intent, r.launchedFromPackage);
-                    // For paranoia, make sure we have correctly
-                    // resumed the top activity.
-                    targetStack.mLastPausedActivity = null;
-                    if (doResume) {
-                        targetStack.resumeTopActivityLocked(null);
-                    }
-                    ActivityOptions.abort(options);
-                    return ActivityManager.START_DELIVERED_TO_TOP;
-                }
-            } else if (!addingToTask &&
-                    (launchFlags&Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {
-                // In this case, we are launching an activity in our own task
-                // that may already be running somewhere in the history, and
-                // we want to shuffle it to the front of the stack if so.
-                final ActivityRecord top = sourceTask.findActivityInHistoryLocked(r);
-                if (top != null) {
-                    final TaskRecord task = top.task;
-                    task.moveActivityToFrontLocked(top);
-                    ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, r, task);
-                    top.updateOptionsLocked(options);
-                    top.deliverNewIntentLocked(callingUid, r.intent, r.launchedFromPackage);
-                    targetStack.mLastPausedActivity = null;
-                    if (doResume) {
-                        targetStack.resumeTopActivityLocked(null);
-                    }
-                    return ActivityManager.START_DELIVERED_TO_TOP;
-                }
-            }
-            // An existing activity is starting this new activity, so we want
-            // to keep the new one in the same task as the one that is starting
-            // it.
-            r.setTask(sourceTask, null);
-            if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Starting new activity " + r
-                    + " in existing task " + r.task + " from source " + sourceRecord);
-
-        } else if (inTask != null) {
-            // The caller is asking that the new activity be started in an explicit
-            // task it has provided to us.
-            if (mSupervisor.isLockTaskModeViolation(inTask)) {
-                Slog.e(TAG, "Attempted Lock Task Mode violation r=" + r);
-                return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
-            }
-            if (overrideBounds) {
-                inTask.updateOverrideConfiguration(newBounds);
-                int stackId = inTask.getLaunchStackId();
-                if (stackId != inTask.stack.mStackId) {
-                    mSupervisor.moveTaskToStackUncheckedLocked(
-                            inTask, stackId, ON_TOP, !FORCE_FOCUS, "inTaskToFront");
-                }
-            }
-            targetStack = inTask.stack;
-            targetStack.moveTaskToFrontLocked(inTask, noAnimation, options, r.appTimeTracker,
-                    "inTaskToFront");
-
-            // Check whether we should actually launch the new activity in to the task,
-            // or just reuse the current activity on top.
-            ActivityRecord top = inTask.getTopActivity();
-            if (top != null && top.realActivity.equals(r.realActivity) && top.userId == r.userId) {
-                if ((launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0
-                        || launchSingleTop || launchSingleTask) {
-                    ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, top, top.task);
-                    if ((startFlags&ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
-                        // We don't need to start a new activity, and
-                        // the client said not to do anything if that
-                        // is the case, so this is it!
-                        return ActivityManager.START_RETURN_INTENT_TO_CALLER;
-                    }
-                    top.deliverNewIntentLocked(callingUid, r.intent, r.launchedFromPackage);
-                    return ActivityManager.START_DELIVERED_TO_TOP;
-                }
-            }
-
-            if (!addingToTask) {
-                // We don't actually want to have this activity added to the task, so just
-                // stop here but still tell the caller that we consumed the intent.
-                ActivityOptions.abort(options);
-                return ActivityManager.START_TASK_TO_FRONT;
-            }
-
-            r.setTask(inTask, null);
-            if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Starting new activity " + r
-                    + " in explicit task " + r.task);
-
-        } else {
-            // This not being started from an existing activity, and not part
-            // of a new task...  just put it in the top task, though these days
-            // this case should never happen.
-            targetStack = computeStackFocus(r, newTask, null /* bounds */, launchFlags);
-            if (doResume) {
-                targetStack.moveToFront("addingToTopTask");
-            }
-            ActivityRecord prev = targetStack.topActivity();
-            r.setTask(prev != null ? prev.task : targetStack.createTaskRecord(
-                    mSupervisor.getNextTaskId(), r.info, intent, null, null, true), null);
-            mWindowManager.moveTaskToTop(r.task.taskId);
-            if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Starting new activity " + r
-                    + " in new guessed " + r.task);
-        }
-
-        mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName,
-                intent, r.getUriPermissionsLocked(), r.userId);
-
-        if (sourceRecord != null && sourceRecord.isRecentsActivity()) {
-            r.task.setTaskToReturnTo(RECENTS_ACTIVITY_TYPE);
-        }
-        if (newTask) {
-            EventLog.writeEvent(EventLogTags.AM_CREATE_TASK, r.userId, r.task.taskId);
-        }
-        ActivityStack.logStartActivity(EventLogTags.AM_CREATE_ACTIVITY, r, r.task);
-        targetStack.mLastPausedActivity = null;
-        targetStack.startActivityLocked(r, newTask, keepCurTransition, options);
-        if (doResume) {
-            if (!launchTaskBehind) {
-                mService.setFocusedActivityLocked(r, "startedActivity");
-            }
-            mSupervisor.resumeTopActivitiesLocked(targetStack, r, options);
-        } else {
-            targetStack.addRecentActivityLocked(r);
-        }
-        mSupervisor.updateUserStackLocked(r.userId, targetStack);
-
-        if (!r.task.mResizeable && mSupervisor.isStackDockedInEffect(targetStack.mStackId)) {
-            mSupervisor.showNonResizeableDockToast(r.task.taskId);
-        }
-
-        return ActivityManager.START_SUCCESS;
-    }
-
-    private int adjustLaunchFlagsToDocumentMode(ActivityRecord r, boolean launchSingleInstance,
-            boolean launchSingleTask, int launchFlags) {
-        if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0 &&
-                (launchSingleInstance || launchSingleTask)) {
-            // We have a conflict between the Intent and the Activity manifest, manifest wins.
-            Slog.i(TAG, "Ignoring FLAG_ACTIVITY_NEW_DOCUMENT, launchMode is " +
-                    "\"singleInstance\" or \"singleTask\"");
-            launchFlags &=
-                    ~(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_MULTIPLE_TASK);
-        } else {
-            switch (r.info.documentLaunchMode) {
-                case ActivityInfo.DOCUMENT_LAUNCH_NONE:
-                    break;
-                case ActivityInfo.DOCUMENT_LAUNCH_INTO_EXISTING:
-                    launchFlags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
-                    break;
-                case ActivityInfo.DOCUMENT_LAUNCH_ALWAYS:
-                    launchFlags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
-                    break;
-                case ActivityInfo.DOCUMENT_LAUNCH_NEVER:
-                    launchFlags &= ~FLAG_ACTIVITY_MULTIPLE_TASK;
-                    break;
-            }
-        }
-        return launchFlags;
-    }
-
     final int startActivities(IApplicationThread caller, int callingUid, String callingPackage,
             Intent[] intents, String[] resolvedTypes, IBinder resultTo,
             Bundle bOptions, int userId) {
@@ -1381,7 +824,743 @@
             Binder.restoreCallingIdentity(origId);
         }
 
-        return ActivityManager.START_SUCCESS;
+        return START_SUCCESS;
+    }
+
+    private int startActivityUnchecked(final ActivityRecord r, ActivityRecord sourceRecord,
+            IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
+            int startFlags, boolean doResume, ActivityOptions options, TaskRecord inTask) {
+
+        setInitialState(r, options, inTask, doResume, startFlags, sourceRecord, voiceSession,
+                voiceInteractor);
+
+        computeLaunchingTaskFlags();
+
+        computeSourceStack();
+
+        mIntent.setFlags(mLaunchFlags);
+
+        ActivityRecord intentActivity = getReusableIntentActivity();
+
+        if (intentActivity != null) {
+            // When the flags NEW_TASK and CLEAR_TASK are set, then the task gets reused but
+            // still needs to be a lock task mode violation since the task gets cleared out and
+            // the device would otherwise leave the locked task.
+            if (mSupervisor.isLockTaskModeViolation(intentActivity.task,
+                    (mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK))
+                            == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK))) {
+                mSupervisor.showLockTaskToast();
+                Slog.e(TAG, "startActivityUnchecked: Attempt to violate Lock Task Mode");
+                return START_RETURN_LOCK_TASK_MODE_VIOLATION;
+            }
+
+            if (mStartActivity.task == null) {
+                mStartActivity.task = intentActivity.task;
+            }
+            if (intentActivity.task.intent == null) {
+                // This task was started because of movement of the activity based on affinity...
+                // Now that we are actually launching it, we can assign the base intent.
+                intentActivity.task.setIntent(mStartActivity);
+            }
+
+            intentActivity = setTargetStackAndMoveToFrontIfNeeded(intentActivity);
+
+            if ((mStartFlags & START_FLAG_ONLY_IF_NEEDED) != 0) {
+                // We don't need to start a new activity, and the client said not to do anything
+                // if that is the case, so this is it!  And for paranoia, make sure we have
+                // correctly resumed the top activity.
+                resumeTargetStackIfNeeded();
+                return START_RETURN_INTENT_TO_CALLER;
+            }
+
+            setTaskFromIntentActivity(intentActivity);
+
+            if (!mAddingToTask && mReuseTask == null) {
+                // We didn't do anything...  but it was needed (a.k.a., client don't use that
+                // intent!)  And for paranoia, make sure we have correctly resumed the top activity.
+                resumeTargetStackIfNeeded();
+                return START_TASK_TO_FRONT;
+            }
+        }
+
+        if (mStartActivity.packageName == null) {
+            if (mStartActivity.resultTo != null && mStartActivity.resultTo.task.stack != null) {
+                mStartActivity.resultTo.task.stack.sendActivityResultLocked(
+                        -1, mStartActivity.resultTo, mStartActivity.resultWho,
+                        mStartActivity.requestCode, RESULT_CANCELED, null);
+            }
+            ActivityOptions.abort(mOptions);
+            return START_CLASS_NOT_FOUND;
+        }
+
+        // If the activity being launched is the same as the one currently at the top, then
+        // we need to check if it should only be launched once.
+        final ActivityStack topStack = mSupervisor.mFocusedStack;
+        final ActivityRecord top = topStack.topRunningNonDelayedActivityLocked(mNotTop);
+        final boolean dontStart = top != null && mStartActivity.resultTo == null
+                && top.realActivity.equals(mStartActivity.realActivity)
+                && top.userId == mStartActivity.userId
+                && top.app != null && top.app.thread != null
+                && ((mLaunchFlags & FLAG_ACTIVITY_SINGLE_TOP) != 0
+                || mLaunchSingleTop || mLaunchSingleTask);
+        if (dontStart) {
+            ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, top, top.task);
+            // For paranoia, make sure we have correctly resumed the top activity.
+            topStack.mLastPausedActivity = null;
+            if (mDoResume) {
+                mSupervisor.resumeFocusedStackTopActivityLocked();
+            }
+            ActivityOptions.abort(mOptions);
+            if ((mStartFlags & START_FLAG_ONLY_IF_NEEDED) != 0) {
+                // We don't need to start a new activity, and the client said not to do
+                // anything if that is the case, so this is it!
+                return START_RETURN_INTENT_TO_CALLER;
+            }
+            top.deliverNewIntentLocked(
+                    mCallingUid, mStartActivity.intent, mStartActivity.launchedFromPackage);
+            return START_DELIVERED_TO_TOP;
+        }
+
+        boolean newTask = false;
+        final TaskRecord taskToAffiliate = (mLaunchTaskBehind && mSourceRecord != null)
+                ? mSourceRecord.task : null;
+
+        // Should this be considered a new task?
+        if (mStartActivity.resultTo == null && mInTask == null && !mAddingToTask
+                && (mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) {
+            newTask = true;
+            setTaskFromReuseOrCreateNewTask(taskToAffiliate);
+
+            if (mSupervisor.isLockTaskModeViolation(mStartActivity.task)) {
+                Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity);
+                return START_RETURN_LOCK_TASK_MODE_VIOLATION;
+            }
+            if (!mMovedHome
+                    && (mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME))
+                    == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
+                // Caller wants to appear on home activity, so before starting
+                // their own activity we will bring home to the front.
+                mStartActivity.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
+            }
+        } else if (mSourceRecord != null) {
+            if (mSupervisor.isLockTaskModeViolation(mSourceRecord.task)) {
+                Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity);
+                return START_RETURN_LOCK_TASK_MODE_VIOLATION;
+            }
+
+            final int result = setTaskFromSourceRecord();
+            if (result != START_SUCCESS) {
+                return result;
+            }
+        } else if (mInTask != null) {
+            // The caller is asking that the new activity be started in an explicit
+            // task it has provided to us.
+            if (mSupervisor.isLockTaskModeViolation(mInTask)) {
+                Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity);
+                return START_RETURN_LOCK_TASK_MODE_VIOLATION;
+            }
+
+            final int result = setTaskFromInTask();
+            if (result != START_SUCCESS) {
+                return result;
+            }
+        } else {
+            // This not being started from an existing activity, and not part of a new task...
+            // just put it in the top task, though these days this case should never happen.
+            setTaskToCurrentTopOrCreateNewTask();
+        }
+
+        mService.grantUriPermissionFromIntentLocked(mCallingUid, mStartActivity.packageName,
+                mIntent, mStartActivity.getUriPermissionsLocked(), mStartActivity.userId);
+
+        if (mSourceRecord != null && mSourceRecord.isRecentsActivity()) {
+            mStartActivity.task.setTaskToReturnTo(RECENTS_ACTIVITY_TYPE);
+        }
+        if (newTask) {
+            EventLog.writeEvent(
+                    EventLogTags.AM_CREATE_TASK, mStartActivity.userId, mStartActivity.task.taskId);
+        }
+        ActivityStack.logStartActivity(
+                EventLogTags.AM_CREATE_ACTIVITY, mStartActivity, mStartActivity.task);
+        mTargetStack.mLastPausedActivity = null;
+        mTargetStack.startActivityLocked(mStartActivity, newTask, mKeepCurTransition, mOptions);
+        if (mDoResume) {
+            if (!mLaunchTaskBehind) {
+                // TODO(b/26381750): Remove this code after verification that all the decision
+                // points above moved targetStack to the front which will also set the focus
+                // activity.
+                mService.setFocusedActivityLocked(mStartActivity, "startedActivity");
+            }
+            mSupervisor.resumeFocusedStackTopActivityLocked(mTargetStack, mStartActivity,
+                    mOptions);
+        } else {
+            mTargetStack.addRecentActivityLocked(mStartActivity);
+        }
+        mSupervisor.updateUserStackLocked(mStartActivity.userId, mTargetStack);
+
+        if (!mStartActivity.task.mResizeable
+                && mSupervisor.isStackDockedInEffect(mTargetStack.mStackId)) {
+            mSupervisor.showNonResizeableDockToast(mStartActivity.task.taskId);
+        }
+
+        return START_SUCCESS;
+    }
+
+    private void setInitialState(ActivityRecord r, ActivityOptions options, TaskRecord inTask,
+            boolean doResume, int startFlags, ActivityRecord sourceRecord,
+            IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor) {
+        reset();
+
+        mStartActivity = r;
+        mIntent = r.intent;
+        mOptions = options;
+        mCallingUid = r.launchedFromUid;
+        mSourceRecord = sourceRecord;
+        mVoiceSession = voiceSession;
+        mVoiceInteractor = voiceInteractor;
+
+        mLaunchBounds = getOverrideBounds(r, options, inTask);
+
+        mLaunchSingleTop = r.launchMode == LAUNCH_SINGLE_TOP;
+        mLaunchSingleInstance = r.launchMode == LAUNCH_SINGLE_INSTANCE;
+        mLaunchSingleTask = r.launchMode == LAUNCH_SINGLE_TASK;
+        mLaunchFlags = adjustLaunchFlagsToDocumentMode(
+                r, mLaunchSingleInstance, mLaunchSingleTask, mIntent.getFlags());
+        mLaunchTaskBehind = r.mLaunchTaskBehind
+                && !mLaunchSingleTask && !mLaunchSingleInstance
+                && (mLaunchFlags & FLAG_ACTIVITY_NEW_DOCUMENT) != 0;
+
+        sendNewTaskResultRequestIfNeeded();
+
+        if ((mLaunchFlags & FLAG_ACTIVITY_NEW_DOCUMENT) != 0 && r.resultTo == null) {
+            mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK;
+        }
+
+        // If we are actually going to launch in to a new task, there are some cases where
+        // we further want to do multiple task.
+        if ((mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) {
+            if (mLaunchTaskBehind
+                    || r.info.documentLaunchMode == DOCUMENT_LAUNCH_ALWAYS) {
+                mLaunchFlags |= FLAG_ACTIVITY_MULTIPLE_TASK;
+            }
+        }
+
+        // We'll invoke onUserLeaving before onPause only if the launching
+        // activity did not explicitly state that this is an automated launch.
+        mSupervisor.mUserLeaving = (mLaunchFlags & FLAG_ACTIVITY_NO_USER_ACTION) == 0;
+        if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING,
+                "startActivity() => mUserLeaving=" + mSupervisor.mUserLeaving);
+
+        // If the caller has asked not to resume at this point, we make note
+        // of this in the record so that we can skip it when trying to find
+        // the top running activity.
+        mDoResume = doResume;
+        if (!doResume || !mSupervisor.okToShowLocked(r)) {
+            r.delayedResume = true;
+            mDoResume = false;
+        }
+
+        mNotTop = (mLaunchFlags & FLAG_ACTIVITY_PREVIOUS_IS_TOP) != 0 ? r : null;
+
+        mInTask = inTask;
+        // In some flows in to this function, we retrieve the task record and hold on to it
+        // without a lock before calling back in to here...  so the task at this point may
+        // not actually be in recents.  Check for that, and if it isn't in recents just
+        // consider it invalid.
+        if (inTask != null && !inTask.inRecents) {
+            Slog.w(TAG, "Starting activity in task not in recents: " + inTask);
+            mInTask = null;
+        }
+
+        mStartFlags = startFlags;
+        // If the onlyIfNeeded flag is set, then we can do this if the activity being launched
+        // is the same as the one making the call...  or, as a special case, if we do not know
+        // the caller then we count the current top activity as the caller.
+        if ((startFlags & START_FLAG_ONLY_IF_NEEDED) != 0) {
+            ActivityRecord checkedCaller = sourceRecord;
+            if (checkedCaller == null) {
+                checkedCaller = mSupervisor.mFocusedStack.topRunningNonDelayedActivityLocked(
+                        mNotTop);
+            }
+            if (!checkedCaller.realActivity.equals(r.realActivity)) {
+                // Caller is not the same as launcher, so always needed.
+                mStartFlags &= ~START_FLAG_ONLY_IF_NEEDED;
+            }
+        }
+
+        mNoAnimation = (mLaunchFlags & FLAG_ACTIVITY_NO_ANIMATION) != 0;
+    }
+
+    private void sendNewTaskResultRequestIfNeeded() {
+        if (mStartActivity.resultTo != null && (mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0
+                && mStartActivity.resultTo.task.stack != null) {
+            // For whatever reason this activity is being launched into a new task...
+            // yet the caller has requested a result back.  Well, that is pretty messed up,
+            // so instead immediately send back a cancel and let the new task continue launched
+            // as normal without a dependency on its originator.
+            Slog.w(TAG, "Activity is launching as a new task, so cancelling activity result.");
+            mStartActivity.resultTo.task.stack.sendActivityResultLocked(-1, mStartActivity.resultTo,
+                    mStartActivity.resultWho, mStartActivity.requestCode, RESULT_CANCELED, null);
+            mStartActivity.resultTo = null;
+        }
+    }
+
+    private void computeLaunchingTaskFlags() {
+        // If the caller is not coming from another activity, but has given us an explicit task into
+        // which they would like us to launch the new activity, then let's see about doing that.
+        if (mSourceRecord == null && mInTask != null && mInTask.stack != null) {
+            final Intent baseIntent = mInTask.getBaseIntent();
+            final ActivityRecord root = mInTask.getRootActivity();
+            if (baseIntent == null) {
+                ActivityOptions.abort(mOptions);
+                throw new IllegalArgumentException("Launching into task without base intent: "
+                        + mInTask);
+            }
+
+            // If this task is empty, then we are adding the first activity -- it
+            // determines the root, and must be launching as a NEW_TASK.
+            if (mLaunchSingleInstance || mLaunchSingleTask) {
+                if (!baseIntent.getComponent().equals(mStartActivity.intent.getComponent())) {
+                    ActivityOptions.abort(mOptions);
+                    throw new IllegalArgumentException("Trying to launch singleInstance/Task "
+                            + mStartActivity + " into different task " + mInTask);
+                }
+                if (root != null) {
+                    ActivityOptions.abort(mOptions);
+                    throw new IllegalArgumentException("Caller with mInTask " + mInTask
+                            + " has root " + root + " but target is singleInstance/Task");
+                }
+            }
+
+            // If task is empty, then adopt the interesting intent launch flags in to the
+            // activity being started.
+            if (root == null) {
+                final int flagsOfInterest = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_MULTIPLE_TASK
+                        | FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_RETAIN_IN_RECENTS;
+                mLaunchFlags = (mLaunchFlags & ~flagsOfInterest)
+                        | (baseIntent.getFlags() & flagsOfInterest);
+                mIntent.setFlags(mLaunchFlags);
+                mInTask.setIntent(mStartActivity);
+                mAddingToTask = true;
+
+                // If the task is not empty and the caller is asking to start it as the root of
+                // a new task, then we don't actually want to start this on the task. We will
+                // bring the task to the front, and possibly give it a new intent.
+            } else if ((mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) {
+                mAddingToTask = false;
+
+            } else {
+                mAddingToTask = true;
+            }
+
+            mReuseTask = mInTask;
+        } else {
+            mInTask = null;
+            // Launch ResolverActivity in the source task, so that it stays in the task bounds
+            // when in freeform workspace.
+            // Also put noDisplay activities in the source task. These by itself can be placed
+            // in any task/stack, however it could launch other activities like ResolverActivity,
+            // and we want those to stay in the original task.
+            if ((mStartActivity.isResolverActivity() || mStartActivity.noDisplay) && mSourceRecord != null
+                    && mSourceRecord.isFreeform())  {
+                mAddingToTask = true;
+            }
+        }
+
+        if (mInTask == null) {
+            if (mSourceRecord == null) {
+                // This activity is not being started from another...  in this
+                // case we -always- start a new task.
+                if ((mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) == 0 && mInTask == null) {
+                    Slog.w(TAG, "startActivity called from non-Activity context; forcing " +
+                            "Intent.FLAG_ACTIVITY_NEW_TASK for: " + mIntent);
+                    mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK;
+                }
+            } else if (mSourceRecord.launchMode == LAUNCH_SINGLE_INSTANCE) {
+                // The original activity who is starting us is running as a single
+                // instance...  this new activity it is starting must go on its
+                // own task.
+                mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK;
+            } else if (mLaunchSingleInstance || mLaunchSingleTask) {
+                // The activity being started is a single instance...  it always
+                // gets launched into its own task.
+                mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK;
+            }
+        }
+    }
+
+    private void computeSourceStack() {
+        if (mSourceRecord == null) {
+            mSourceStack = null;
+            return;
+        }
+        if (!mSourceRecord.finishing) {
+            mSourceStack = mSourceRecord.task.stack;
+            return;
+        }
+
+        // If the source is finishing, we can't further count it as our source. This is because the
+        // task it is associated with may now be empty and on its way out, so we don't want to
+        // blindly throw it in to that task.  Instead we will take the NEW_TASK flow and try to find
+        // a task for it. But save the task information so it can be used when creating the new task.
+        if ((mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) == 0) {
+            Slog.w(TAG, "startActivity called from finishing " + mSourceRecord
+                    + "; forcing " + "Intent.FLAG_ACTIVITY_NEW_TASK for: " + mIntent);
+            mLaunchFlags |= FLAG_ACTIVITY_NEW_TASK;
+            mNewTaskInfo = mSourceRecord.info;
+            mNewTaskIntent = mSourceRecord.task.intent;
+        }
+        mSourceRecord = null;
+        mSourceStack = null;
+    }
+
+    /**
+     * Decide whether the new activity should be inserted into an existing task. Returns null
+     * if not or an ActivityRecord with the task into which the new activity should be added.
+     */
+    private ActivityRecord getReusableIntentActivity() {
+        // We may want to try to place the new activity in to an existing task.  We always
+        // do this if the target activity is singleTask or singleInstance; we will also do
+        // this if NEW_TASK has been requested, and there is not an additional qualifier telling
+        // us to still place it in a new task: multi task, always doc mode, or being asked to
+        // launch this as a new task behind the current one.
+        boolean putIntoExistingTask = ((mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0 &&
+                (mLaunchFlags & FLAG_ACTIVITY_MULTIPLE_TASK) == 0)
+                || mLaunchSingleInstance || mLaunchSingleTask;
+        // If bring to front is requested, and no result is requested and we have not been given
+        // an explicit task to launch in to, and we can find a task that was started with this
+        // same component, then instead of launching bring that one to the front.
+        putIntoExistingTask &= mInTask == null && mStartActivity.resultTo == null;
+        ActivityRecord intentActivity = null;
+        if (putIntoExistingTask) {
+            // See if there is a task to bring to the front.  If this is a SINGLE_INSTANCE
+            // activity, there can be one and only one instance of it in the history, and it is
+            // always in its own unique task, so we do a special search.
+            intentActivity = mLaunchSingleInstance ? mSupervisor.findActivityLocked(mIntent, mStartActivity.info)
+                    : mSupervisor.findTaskLocked(mStartActivity);
+        }
+        return intentActivity;
+    }
+
+    private ActivityRecord setTargetStackAndMoveToFrontIfNeeded(ActivityRecord intentActivity) {
+        mTargetStack = intentActivity.task.stack;
+        mTargetStack.mLastPausedActivity = null;
+        // If the target task is not in the front, then we need to bring it to the front...
+        // except...  well, with SINGLE_TASK_LAUNCH it's not entirely clear. We'd like to have
+        // the same behavior as if a new instance was being started, which means not bringing it
+        // to the front if the caller is not itself in the front.
+        final ActivityStack focusStack = mSupervisor.getFocusedStack();
+        ActivityRecord curTop = (focusStack == null)
+                ? null : focusStack.topRunningNonDelayedActivityLocked(mNotTop);
+
+        if (curTop != null && (curTop.task != intentActivity.task ||
+                curTop.task != focusStack.topTask())) {
+            mStartActivity.intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
+            if (mSourceRecord == null || (mSourceStack.topActivity() != null &&
+                    mSourceStack.topActivity().task == mSourceRecord.task)) {
+                // We really do want to push this one into the user's face, right now.
+                if (mLaunchTaskBehind && mSourceRecord != null) {
+                    intentActivity.setTaskToAffiliateWith(mSourceRecord.task);
+                }
+                mMovedHome = true;
+                final ActivityStack launchStack =
+                        getLaunchStack(mStartActivity, mLaunchFlags, mStartActivity.task,
+                                mOptions, true);
+                if (launchStack == null || launchStack == mTargetStack) {
+                    // We only want to move to the front, if we aren't going to launch on a
+                    // different stack. If we launch on a different stack, we will put the
+                    // task on top there.
+                    mTargetStack.moveTaskToFrontLocked(intentActivity.task, mNoAnimation,
+                            mOptions, mStartActivity.appTimeTracker, "bringingFoundTaskToFront");
+                    mMovedToFront = true;
+                }
+                if ((mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME))
+                        == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
+                    // Caller wants to appear on home activity.
+                    intentActivity.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
+                }
+                mOptions = null;
+            }
+        }
+        if (!mMovedToFront && mDoResume) {
+            if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Bring to front target: " + mTargetStack
+                    + " from " + intentActivity);
+            mTargetStack.moveToFront("intentActivityFound");
+        }
+
+        // If the caller has requested that the target task be reset, then do so.
+        if ((mLaunchFlags & FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
+            return mTargetStack.resetTaskIfNeededLocked(intentActivity, mStartActivity);
+        }
+        return intentActivity;
+    }
+
+    private void setTaskFromIntentActivity(ActivityRecord intentActivity) {
+        if ((mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK))
+                == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) {
+            // The caller has requested to completely replace any existing task with its new
+            // activity. Well that should not be too hard...
+            mReuseTask = intentActivity.task;
+            mReuseTask.performClearTaskLocked();
+            mReuseTask.setIntent(mStartActivity);
+        } else if ((mLaunchFlags & FLAG_ACTIVITY_CLEAR_TOP) != 0
+                || mLaunchSingleInstance || mLaunchSingleTask) {
+            // In this situation we want to remove all activities from the task up to the one
+            // being started. In most cases this means we are resetting the task to its initial
+            // state.
+            ActivityRecord top = intentActivity.task.performClearTaskLocked(mStartActivity,
+                    mLaunchFlags);
+            if (top != null) {
+                if (top.frontOfTask) {
+                    // Activity aliases may mean we use different intents for the top activity,
+                    // so make sure the task now has the identity of the new intent.
+                    top.task.setIntent(mStartActivity);
+                }
+                ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, mStartActivity, top.task);
+                top.deliverNewIntentLocked(mCallingUid, mStartActivity.intent, mStartActivity.launchedFromPackage);
+            } else {
+                // A special case: we need to start the activity because it is not currently
+                // running, and the caller has asked to clear the current task to have this
+                // activity at the top.
+                mAddingToTask = true;
+                // Now pretend like this activity is being started by the top of its task, so it
+                // is put in the right place.
+                mSourceRecord = intentActivity;
+                final TaskRecord task = mSourceRecord.task;
+                if (task != null && task.stack == null) {
+                    // Target stack got cleared when we all activities were removed above.
+                    // Go ahead and reset it.
+                    mTargetStack = computeStackFocus(mSourceRecord, false /* newTask */,
+                            null /* bounds */, mLaunchFlags, mOptions);
+                    mTargetStack.addTask(task,
+                            !mLaunchTaskBehind /* toTop */, "startActivityUnchecked");
+                }
+            }
+        } else if (mStartActivity.realActivity.equals(intentActivity.task.realActivity)) {
+            // In this case the top activity on the task is the same as the one being launched,
+            // so we take that as a request to bring the task to the foreground. If the top
+            // activity in the task is the root activity, deliver this new intent to it if it
+            // desires.
+            if (((mLaunchFlags & FLAG_ACTIVITY_SINGLE_TOP) != 0 || mLaunchSingleTop)
+                    && intentActivity.realActivity.equals(mStartActivity.realActivity)) {
+                ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, mStartActivity,
+                        intentActivity.task);
+                if (intentActivity.frontOfTask) {
+                    intentActivity.task.setIntent(mStartActivity);
+                }
+                intentActivity.deliverNewIntentLocked(mCallingUid, mStartActivity.intent,
+                        mStartActivity.launchedFromPackage);
+            } else if (!mStartActivity.intent.filterEquals(intentActivity.task.intent)) {
+                // In this case we are launching the root activity of the task, but with a
+                // different intent. We should start a new instance on top.
+                mAddingToTask = true;
+                mSourceRecord = intentActivity;
+            }
+        } else if ((mLaunchFlags & FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) == 0) {
+            // In this case an activity is being launched in to an existing task, without
+            // resetting that task. This is typically the situation of launching an activity
+            // from a notification or shortcut. We want to place the new activity on top of the
+            // current task.
+            mAddingToTask = true;
+            mSourceRecord = intentActivity;
+        } else if (!intentActivity.task.rootWasReset) {
+            // In this case we are launching into an existing task that has not yet been started
+            // from its front door. The current task has been brought to the front. Ideally,
+            // we'd probably like to place this new task at the bottom of its stack, but that's
+            // a little hard to do with the current organization of the code so for now we'll
+            // just drop it.
+            intentActivity.task.setIntent(mStartActivity);
+        }
+    }
+
+    private void resumeTargetStackIfNeeded() {
+        if (mDoResume) {
+            mSupervisor.resumeFocusedStackTopActivityLocked(mTargetStack, null, mOptions);
+            if (!mMovedToFront) {
+                // Make sure to notify Keyguard as well if we are not running an app transition
+                // later.
+                mSupervisor.notifyActivityDrawnForKeyguard();
+            }
+        } else {
+            ActivityOptions.abort(mOptions);
+        }
+        mSupervisor.updateUserStackLocked(mStartActivity.userId, mTargetStack);
+    }
+
+    private void setTaskFromReuseOrCreateNewTask(TaskRecord taskToAffiliate) {
+        mTargetStack = computeStackFocus(mStartActivity, true, mLaunchBounds, mLaunchFlags,
+                mOptions);
+        if (mDoResume) {
+            mTargetStack.moveToFront("startingNewTask");
+        }
+
+        if (mReuseTask == null) {
+            final TaskRecord task = mTargetStack.createTaskRecord(mSupervisor.getNextTaskId(),
+                    mNewTaskInfo != null ? mNewTaskInfo : mStartActivity.info,
+                    mNewTaskIntent != null ? mNewTaskIntent : mIntent,
+                    mVoiceSession, mVoiceInteractor, !mLaunchTaskBehind /* toTop */);
+            mStartActivity.setTask(task, taskToAffiliate);
+            if (mLaunchBounds != null) {
+                mStartActivity.task.updateOverrideConfiguration(mLaunchBounds);
+            }
+            if (DEBUG_TASKS) Slog.v(TAG_TASKS,
+                    "Starting new activity " +
+                            mStartActivity + " in new task " + mStartActivity.task);
+        } else {
+            mStartActivity.setTask(mReuseTask, taskToAffiliate);
+        }
+    }
+
+    private int setTaskFromSourceRecord() {
+        final TaskRecord sourceTask = mSourceRecord.task;
+        // We only want to allow changing stack if the target task is not the top one,
+        // otherwise we would move the launching task to the other side, rather than show
+        // two side by side.
+        final boolean launchToSideAllowed = sourceTask.stack.topTask() != sourceTask;
+        mTargetStack = getLaunchStack(mStartActivity, mLaunchFlags, mStartActivity.task, mOptions, launchToSideAllowed);
+
+        if (mTargetStack == null) {
+            mTargetStack = sourceTask.stack;
+        } else if (mTargetStack != sourceTask.stack) {
+            mSupervisor.moveTaskToStackLocked(sourceTask.taskId, mTargetStack.mStackId,
+                    ON_TOP, FORCE_FOCUS, "launchToSide", !ANIMATE);
+        }
+        if (mDoResume) {
+            mTargetStack.moveToFront("sourceStackToFront");
+        }
+        final TaskRecord topTask = mTargetStack.topTask();
+        if (topTask != sourceTask) {
+            mTargetStack.moveTaskToFrontLocked(sourceTask, mNoAnimation, mOptions,
+                    mStartActivity.appTimeTracker, "sourceTaskToFront");
+        }
+        if (!mAddingToTask && (mLaunchFlags & FLAG_ACTIVITY_CLEAR_TOP) != 0) {
+            // In this case, we are adding the activity to an existing task, but the caller has
+            // asked to clear that task if the activity is already running.
+            ActivityRecord top = sourceTask.performClearTaskLocked(mStartActivity, mLaunchFlags);
+            mKeepCurTransition = true;
+            if (top != null) {
+                ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, mStartActivity, top.task);
+                top.deliverNewIntentLocked(mCallingUid, mStartActivity.intent, mStartActivity.launchedFromPackage);
+                // For paranoia, make sure we have correctly resumed the top activity.
+                mTargetStack.mLastPausedActivity = null;
+                if (mDoResume) {
+                    mSupervisor.resumeFocusedStackTopActivityLocked();
+                }
+                ActivityOptions.abort(mOptions);
+                return START_DELIVERED_TO_TOP;
+            }
+        } else if (!mAddingToTask && (mLaunchFlags & FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {
+            // In this case, we are launching an activity in our own task that may already be
+            // running somewhere in the history, and we want to shuffle it to the front of the
+            // stack if so.
+            final ActivityRecord top = sourceTask.findActivityInHistoryLocked(mStartActivity);
+            if (top != null) {
+                final TaskRecord task = top.task;
+                task.moveActivityToFrontLocked(top);
+                top.updateOptionsLocked(mOptions);
+                ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, mStartActivity, task);
+                top.deliverNewIntentLocked(mCallingUid, mStartActivity.intent, mStartActivity.launchedFromPackage);
+                mTargetStack.mLastPausedActivity = null;
+                if (mDoResume) {
+                    mSupervisor.resumeFocusedStackTopActivityLocked();
+                }
+                return START_DELIVERED_TO_TOP;
+            }
+        }
+
+        // An existing activity is starting this new activity, so we want to keep the new one in
+        // the same task as the one that is starting it.
+        mStartActivity.setTask(sourceTask, null);
+        if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Starting new activity " + mStartActivity
+                + " in existing task " + mStartActivity.task + " from source " + mSourceRecord);
+        return START_SUCCESS;
+    }
+
+    private int setTaskFromInTask() {
+        if (mLaunchBounds != null) {
+            mInTask.updateOverrideConfiguration(mLaunchBounds);
+            int stackId = mInTask.getLaunchStackId();
+            if (stackId != mInTask.stack.mStackId) {
+                mSupervisor.moveTaskToStackUncheckedLocked(
+                        mInTask, stackId, ON_TOP, !FORCE_FOCUS, "inTaskToFront");
+            }
+        }
+        mTargetStack = mInTask.stack;
+        mTargetStack.moveTaskToFrontLocked(
+                mInTask, mNoAnimation, mOptions, mStartActivity.appTimeTracker, "inTaskToFront");
+
+        // Check whether we should actually launch the new activity in to the task,
+        // or just reuse the current activity on top.
+        ActivityRecord top = mInTask.getTopActivity();
+        if (top != null && top.realActivity.equals(mStartActivity.realActivity) && top.userId == mStartActivity.userId) {
+            if ((mLaunchFlags & FLAG_ACTIVITY_SINGLE_TOP) != 0
+                    || mLaunchSingleTop || mLaunchSingleTask) {
+                ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, top, top.task);
+                if ((mStartFlags & START_FLAG_ONLY_IF_NEEDED) != 0) {
+                    // We don't need to start a new activity, and the client said not to do
+                    // anything if that is the case, so this is it!
+                    return START_RETURN_INTENT_TO_CALLER;
+                }
+                top.deliverNewIntentLocked(mCallingUid, mStartActivity.intent, mStartActivity.launchedFromPackage);
+                return START_DELIVERED_TO_TOP;
+            }
+        }
+
+        if (!mAddingToTask) {
+            // We don't actually want to have this activity added to the task, so just
+            // stop here but still tell the caller that we consumed the intent.
+            ActivityOptions.abort(mOptions);
+            return START_TASK_TO_FRONT;
+        }
+
+        mStartActivity.setTask(mInTask, null);
+        if (DEBUG_TASKS) Slog.v(TAG_TASKS,
+                "Starting new activity " + mStartActivity + " in explicit task " + mStartActivity.task);
+
+        return START_SUCCESS;
+    }
+
+    private void setTaskToCurrentTopOrCreateNewTask() {
+        mTargetStack = computeStackFocus(mStartActivity, false, null /* bounds */, mLaunchFlags,
+                mOptions);
+        if (mDoResume) {
+            mTargetStack.moveToFront("addingToTopTask");
+        }
+        final ActivityRecord prev = mTargetStack.topActivity();
+        final TaskRecord task = prev != null ? prev.task
+                : mTargetStack.createTaskRecord(
+                mSupervisor.getNextTaskId(), mStartActivity.info, mIntent, null, null, true);
+        mStartActivity.setTask(task, null);
+        mWindowManager.moveTaskToTop(mStartActivity.task.taskId);
+        if (DEBUG_TASKS) Slog.v(TAG_TASKS,
+                "Starting new activity " + mStartActivity + " in new guessed " + mStartActivity.task);
+    }
+
+    private int adjustLaunchFlagsToDocumentMode(ActivityRecord r, boolean launchSingleInstance,
+            boolean launchSingleTask, int launchFlags) {
+        if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0 &&
+                (launchSingleInstance || launchSingleTask)) {
+            // We have a conflict between the Intent and the Activity manifest, manifest wins.
+            Slog.i(TAG, "Ignoring FLAG_ACTIVITY_NEW_DOCUMENT, launchMode is " +
+                    "\"singleInstance\" or \"singleTask\"");
+            launchFlags &=
+                    ~(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | FLAG_ACTIVITY_MULTIPLE_TASK);
+        } else {
+            switch (r.info.documentLaunchMode) {
+                case ActivityInfo.DOCUMENT_LAUNCH_NONE:
+                    break;
+                case ActivityInfo.DOCUMENT_LAUNCH_INTO_EXISTING:
+                    launchFlags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
+                    break;
+                case ActivityInfo.DOCUMENT_LAUNCH_ALWAYS:
+                    launchFlags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
+                    break;
+                case ActivityInfo.DOCUMENT_LAUNCH_NEVER:
+                    launchFlags &= ~FLAG_ACTIVITY_MULTIPLE_TASK;
+                    break;
+            }
+        }
+        return launchFlags;
     }
 
     final void doPendingActivityLaunchesLocked(boolean doResume) {
@@ -1389,9 +1568,8 @@
             PendingActivityLaunch pal = mPendingActivityLaunches.remove(0);
 
             try {
-                startActivityUncheckedLocked(pal.r, pal.sourceRecord, null, null,
-                        pal.startFlags, doResume && mPendingActivityLaunches.isEmpty(),
-                        null, null);
+                startActivityUnchecked(pal.r, pal.sourceRecord, null, null, pal.startFlags,
+                        doResume && mPendingActivityLaunches.isEmpty(), null, null);
             } catch (Exception e) {
                 Slog.e(TAG, "Exception during pending activity launch pal=" + pal, e);
                 pal.sendErrorResult(e.getMessage());
@@ -1400,13 +1578,13 @@
     }
 
     private ActivityStack computeStackFocus(ActivityRecord r, boolean newTask, Rect bounds,
-            int launchFlags) {
+            int launchFlags, ActivityOptions aOptions) {
         final TaskRecord task = r.task;
         if (!(r.isApplicationActivity() || (task != null && task.isApplicationTask()))) {
             return mSupervisor.mHomeStack;
         }
 
-        ActivityStack stack = getLaunchToSideStack(r, launchFlags, task);
+        ActivityStack stack = getLaunchStack(r, launchFlags, task, aOptions, true);
         if (stack != null) {
             return stack;
         }
@@ -1442,7 +1620,7 @@
         final boolean canUseFocusedStack =
                 focusedStackId == FULLSCREEN_WORKSPACE_STACK_ID
                         || focusedStackId == DOCKED_STACK_ID
-                        || (focusedStackId == FREEFORM_WORKSPACE_STACK_ID && r.info.resizeable);
+                        || (focusedStackId == FREEFORM_WORKSPACE_STACK_ID && r.isResizeable());
         if (canUseFocusedStack && (!newTask
                 || mSupervisor.mFocusedStack.mActivityContainer.isEligibleForNewTasks())) {
             if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG_FOCUS,
@@ -1471,10 +1649,19 @@
         return stack;
     }
 
-    private ActivityStack getLaunchToSideStack(ActivityRecord r, int launchFlags, TaskRecord task) {
-        if ((launchFlags & FLAG_ACTIVITY_LAUNCH_TO_SIDE) == 0) {
+    private ActivityStack getLaunchStack(ActivityRecord r, int launchFlags, TaskRecord task,
+            ActivityOptions aOptions, boolean launchToSideAllowed) {
+        final int launchStackId =
+                (aOptions != null) ? aOptions.getLaunchStackId() : INVALID_STACK_ID;
+
+        if (isValidLaunchStackId(launchStackId, r)) {
+            return mSupervisor.getStack(launchStackId, CREATE_IF_NEEDED, ON_TOP);
+        }
+
+        if (!launchToSideAllowed || (launchFlags & FLAG_ACTIVITY_LAUNCH_TO_SIDE) == 0) {
             return null;
         }
+
         // The parent activity doesn't want to launch the activity on top of itself, but
         // instead tries to put it onto other side in side-by-side mode.
         final ActivityStack parentStack = task != null ? task.stack
@@ -1498,36 +1685,39 @@
         }
     }
 
-    /**
-     * Decide whether the new activity should be inserted into an existing task. Returns null if not
-     * or an ActivityRecord with the task into which the new activity should be added.
-     */
-    private ActivityRecord getReusableIntentActivity(ActivityRecord r, TaskRecord inTask,
-            Intent intent, boolean launchSingleInstance, boolean launchSingleTask,
-            int launchFlags) {
-        // We may want to try to place the new activity in to an existing task.  We always
-        // do this if the target activity is singleTask or singleInstance; we will also do
-        // this if NEW_TASK has been requested, and there is not an additional qualifier telling
-        // us to still place it in a new task: multi task, always doc mode, or being asked to
-        // launch this as a new task behind the current one.
-        boolean putIntoExistingTask = ((launchFlags & FLAG_ACTIVITY_NEW_TASK) != 0 &&
-                (launchFlags & FLAG_ACTIVITY_MULTIPLE_TASK) == 0)
-                || launchSingleInstance || launchSingleTask;
-        // If bring to front is requested, and no result is requested and we have not
-        // been given an explicit task to launch in to, and
-        // we can find a task that was started with this same
-        // component, then instead of launching bring that one to the front.
-        putIntoExistingTask &= inTask == null && r.resultTo == null;
-        ActivityRecord intentActivity = null;
-        if (putIntoExistingTask) {
-            // See if there is a task to bring to the front.  If this is
-            // a SINGLE_INSTANCE activity, there can be one and only one
-            // instance of it in the history, and it is always in its own
-            // unique task, so we do a special search.
-            intentActivity = launchSingleInstance ? mSupervisor.findActivityLocked(intent, r.info)
-                    : mSupervisor.findTaskLocked(r);
+    private boolean isValidLaunchStackId(int stackId, ActivityRecord r) {
+        if (stackId == INVALID_STACK_ID || stackId == HOME_STACK_ID
+                || !StackId.isStaticStack(stackId)) {
+            return false;
         }
-        return intentActivity;
+
+        final boolean resizeable = r.isResizeable() || mService.mForceResizableActivities;
+
+        if (stackId != FULLSCREEN_WORKSPACE_STACK_ID && !resizeable) {
+            return false;
+        }
+
+        if (stackId == FREEFORM_WORKSPACE_STACK_ID && !mService.mSupportsFreeformWindowManagement) {
+            return false;
+        }
+
+        final boolean supportsPip = mService.mSupportsPictureInPicture
+                && (r.supportsPictureInPicture() || mService.mForceResizableActivities);
+        if (stackId == PINNED_STACK_ID && !supportsPip) {
+            return false;
+        }
+        return true;
+    }
+
+    Rect getOverrideBounds(ActivityRecord r, ActivityOptions options, TaskRecord inTask) {
+        Rect newBounds = null;
+        if (options != null && (r.isResizeable() || (inTask != null && inTask.mResizeable))) {
+            if (mSupervisor.canUseActivityOptionsLaunchBounds(
+                    options, options.getLaunchStackId())) {
+                newBounds = options.getLaunchBounds();
+            }
+        }
+        return newBounds;
     }
 
     void setWindowManager(WindowManagerService wm) {
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java
index f64b803..82862e8 100644
--- a/services/core/java/com/android/server/am/BatteryStatsService.java
+++ b/services/core/java/com/android/server/am/BatteryStatsService.java
@@ -1114,7 +1114,7 @@
                 } else {
                     // Not an option, last argument must be a package name.
                     try {
-                        reqUid = mContext.getPackageManager().getPackageUid(arg,
+                        reqUid = mContext.getPackageManager().getPackageUidAsUser(arg,
                                 UserHandle.getCallingUserId());
                     } catch (PackageManager.NameNotFoundException e) {
                         pw.println("Unknown package: " + arg);
diff --git a/services/core/java/com/android/server/am/ResizeDockedStackTimeout.java b/services/core/java/com/android/server/am/ResizeDockedStackTimeout.java
new file mode 100644
index 0000000..ff39589
--- /dev/null
+++ b/services/core/java/com/android/server/am/ResizeDockedStackTimeout.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.am;
+
+import android.graphics.Rect;
+import android.os.Handler;
+
+import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
+
+/**
+ * When resizing the docked stack, a caller can temporarily supply task bounds that are different
+ * from the stack bounds. In order to return to a sane state if the caller crashes or has a bug,
+ * this class manages this cycle.
+ */
+class ResizeDockedStackTimeout {
+
+    private static final long TIMEOUT_MS = 10 * 1000;
+    private final ActivityManagerService mService;
+    private final ActivityStackSupervisor mSupervisor;
+    private final Handler mHandler;
+    private final Rect mCurrentDockedBounds = new Rect();
+
+    private final Runnable mTimeoutRunnable = new Runnable() {
+        @Override
+        public void run() {
+            synchronized (mService) {
+                mSupervisor.resizeDockedStackLocked(mCurrentDockedBounds, null, null, null, null,
+                        PRESERVE_WINDOWS);
+            }
+        }
+    };
+
+    ResizeDockedStackTimeout(ActivityManagerService service, ActivityStackSupervisor supervisor,
+            Handler handler) {
+        mService = service;
+        mSupervisor = supervisor;
+        mHandler = handler;
+    }
+
+    void notifyResizing(Rect dockedBounds, boolean hasTempBounds) {
+        mHandler.removeCallbacks(mTimeoutRunnable);
+        if (!hasTempBounds) {
+            return;
+        }
+        mCurrentDockedBounds.set(dockedBounds);
+        mHandler.postDelayed(mTimeoutRunnable, TIMEOUT_MS);
+    }
+
+}
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 4647d77..ae987e6 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -23,6 +23,7 @@
 import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
 import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
 import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
+import static android.content.pm.ActivityInfo.FLAG_RESIZEABLE;
 import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
 import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
 import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
@@ -441,7 +442,7 @@
         } else {
             autoRemoveRecents = false;
         }
-        mResizeable = info.resizeable || mService.mForceResizableActivities;
+        mResizeable = (info.flags & FLAG_RESIZEABLE) != 0 || mService.mForceResizableActivities;
         mLockTaskMode = info.lockTaskLaunchMode;
         mPrivileged = (info.applicationInfo.privateFlags & PRIVATE_FLAG_PRIVILEGED) != 0;
         setLockTaskAuth();
@@ -697,7 +698,7 @@
         if (mActivities.isEmpty()) {
             taskType = r.mActivityType;
             if (taskType == HOME_ACTIVITY_TYPE && mService.mForceResizableActivities) {
-                mResizeable = r.info.resizeable;
+                mResizeable = r.isResizeable();
             }
             isPersistable = r.isPersistable();
             mCallingUid = r.launchedFromUid;
@@ -1297,6 +1298,9 @@
                     (mOverrideConfig.screenWidthDp <= mOverrideConfig.screenHeightDp)
                             ? Configuration.ORIENTATION_PORTRAIT
                             : Configuration.ORIENTATION_LANDSCAPE;
+            final int sl = Configuration.resetScreenLayout(serviceConfig.screenLayout);
+            mOverrideConfig.screenLayout = Configuration.reduceScreenLayout(
+                    sl, mOverrideConfig.screenWidthDp, mOverrideConfig.screenHeightDp);
         }
 
         if (mFullscreen != oldFullscreen) {
@@ -1321,7 +1325,12 @@
         }
     }
 
-    void reportPictureInPictureModeChange() {
+    void reportPictureInPictureModeChangeIfNeeded(ActivityStack prevStack) {
+        if (prevStack == null || prevStack == stack
+                || (prevStack.mStackId != PINNED_STACK_ID && stack.mStackId != PINNED_STACK_ID)) {
+            return;
+        }
+
         for (int i = mActivities.size() - 1; i >= 0; i--) {
             final ActivityRecord r = mActivities.get(i);
             if (r.app != null && r.app.thread != null) {
diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java
index 20b1e60..7172859 100644
--- a/services/core/java/com/android/server/am/UserController.java
+++ b/services/core/java/com/android/server/am/UserController.java
@@ -22,6 +22,7 @@
 import static android.app.ActivityManager.USER_OP_ERROR_RELATED_USERS_CANNOT_STOP;
 import static android.app.ActivityManager.USER_OP_IS_CURRENT;
 import static android.app.ActivityManager.USER_OP_SUCCESS;
+import static android.content.Context.KEYGUARD_SERVICE;
 import static android.os.Process.SYSTEM_UID;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_MU;
 import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
@@ -43,6 +44,7 @@
 import android.app.Dialog;
 import android.app.IStopUserCallback;
 import android.app.IUserSwitchObserver;
+import android.app.KeyguardManager;
 import android.content.Context;
 import android.content.IIntentReceiver;
 import android.content.Intent;
@@ -73,6 +75,7 @@
 import com.android.internal.R;
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.util.ArrayUtils;
+import com.android.internal.widget.LockPatternUtils;
 import com.android.server.pm.UserManagerService;
 
 import java.io.PrintWriter;
@@ -304,7 +307,10 @@
                         + relatedUserId);
                 // We still need to stop the requested user if it's a force stop.
                 if (force) {
+                    Slog.i(TAG,
+                            "Force stop user " + userId + ". Related users will not be stopped");
                     stopSingleUserLocked(userId, callback);
+                    return USER_OP_SUCCESS;
                 }
                 return USER_OP_ERROR_RELATED_USERS_CANNOT_STOP;
             }
@@ -931,7 +937,7 @@
         if (homeInFront) {
             mService.startHomeActivityLocked(newUserId, "moveUserToForeground");
         } else {
-            mService.mStackSupervisor.resumeTopActivitiesLocked();
+            mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
         }
         EventLogTags.writeAmSwitchUser(newUserId);
         getUserManager().onUserForeground(newUserId);
@@ -1283,6 +1289,20 @@
         return mCurrentProfileIds;
     }
 
+    /**
+     * Returns whether the given user requires credential entry at this time. This is used to
+     * intercept activity launches for work apps when the Work Challenge is present.
+     */
+    boolean shouldConfirmCredentials(int userId) {
+        final UserInfo user = getUserInfo(userId);
+        if (!user.isManagedProfile() || !LockPatternUtils.isSeparateWorkChallengeEnabled()) {
+            return false;
+        }
+        final KeyguardManager km = (KeyguardManager) mService.mContext
+                .getSystemService(KEYGUARD_SERVICE);
+        return km.isDeviceLocked(user.id);
+    }
+
     void dump(PrintWriter pw, boolean dumpAll) {
         pw.println("  mStartedUsers:");
         for (int i = 0; i < mStartedUsers.size(); i++) {
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index 2bea278..5bd4f98 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -309,7 +309,7 @@
         PackageManager pm = mContext.getPackageManager();
         int result;
         try {
-            result = pm.getPackageUid(app, userHandle);
+            result = pm.getPackageUidAsUser(app, userHandle);
         } catch (NameNotFoundException e) {
             result = -1;
         }
diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java
index c5e6e7c..4eabe36 100644
--- a/services/core/java/com/android/server/job/JobSchedulerService.java
+++ b/services/core/java/com/android/server/job/JobSchedulerService.java
@@ -161,8 +161,9 @@
     private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
-            Slog.d(TAG, "Receieved: " + intent.getAction());
-            if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
+            final String action = intent.getAction();
+            Slog.d(TAG, "Receieved: " + action);
+            if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
                 // If this is an outright uninstall rather than the first half of an
                 // app update sequence, cancel the jobs associated with the app.
                 if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
@@ -172,18 +173,21 @@
                     }
                     cancelJobsForUid(uidRemoved, true);
                 }
-            } else if (Intent.ACTION_USER_REMOVED.equals(intent.getAction())) {
+            } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
                 final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
                 if (DEBUG) {
                     Slog.d(TAG, "Removing jobs for user: " + userId);
                 }
                 cancelJobsForUser(userId);
-            } else if (PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED.equals(intent.getAction())
-                    || PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED.equals(intent.getAction())) {
+            } else if (PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED.equals(action)
+                    || PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED.equals(action)) {
                 updateIdleMode(mPowerManager != null
                         ? (mPowerManager.isDeviceIdleMode()
                                 || mPowerManager.isLightDeviceIdleMode())
                         : false);
+            } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
+                // Kick off pending jobs for any apps that re-appeared
+                mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget();
             }
         }
     };
@@ -425,17 +429,24 @@
     @Override
     public void onBootPhase(int phase) {
         if (PHASE_SYSTEM_SERVICES_READY == phase) {
-            // Register br for package removals and user removals.
+            // Register for package removals and user removals.
             final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_REMOVED);
             filter.addDataScheme("package");
             getContext().registerReceiverAsUser(
                     mBroadcastReceiver, UserHandle.ALL, filter, null, null);
+
             final IntentFilter userFilter = new IntentFilter(Intent.ACTION_USER_REMOVED);
             userFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
             userFilter.addAction(PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED);
             getContext().registerReceiverAsUser(
                     mBroadcastReceiver, UserHandle.ALL, userFilter, null, null);
-            mPowerManager = (PowerManager)getContext().getSystemService(Context.POWER_SERVICE);
+
+            final IntentFilter storageFilter = new IntentFilter();
+            storageFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
+            getContext().registerReceiverAsUser(
+                    mBroadcastReceiver, UserHandle.ALL, storageFilter, null, null);
+
+            mPowerManager = getContext().getSystemService(PowerManager.class);
             try {
                 ActivityManagerNative.getDefault().registerUidObserver(mUidObserver,
                         ActivityManager.UID_OBSERVER_IDLE);
@@ -834,7 +845,7 @@
             final boolean componentPresent;
             try {
                 componentPresent = (AppGlobals.getPackageManager().getServiceInfo(
-                        job.getServiceComponent(), PackageManager.MATCH_ENCRYPTION_DEFAULT,
+                        job.getServiceComponent(), PackageManager.MATCH_DEBUG_TRIAGED_MISSING,
                         userId) != null);
             } catch (RemoteException e) {
                 throw e.rethrowAsRuntimeException();
@@ -924,8 +935,8 @@
             final IPackageManager pm = AppGlobals.getPackageManager();
             final ComponentName service = job.getService();
             try {
-                ServiceInfo si = pm.getServiceInfo(service, PackageManager.MATCH_ENCRYPTION_DEFAULT,
-                        UserHandle.getUserId(uid));
+                ServiceInfo si = pm.getServiceInfo(service,
+                        PackageManager.MATCH_DEBUG_TRIAGED_MISSING, UserHandle.getUserId(uid));
                 if (si == null) {
                     throw new IllegalArgumentException("No such service " + service);
                 }
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index d5c3113..745f476 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -767,7 +767,7 @@
                 synchronized (mLock) {
                     // If we don't have a media button receiver to fall back on
                     // include non-playing sessions for dispatching
-                    UserRecord ur = mUserRecords.get(ActivityManager.getCurrentUser());
+                    UserRecord ur = mUserRecords.get(mCurrentUserId);
                     boolean useNotPlayingSessions = (ur == null) ||
                             (ur.mLastMediaButtonReceiver == null
                                 && ur.mRestoredMediaButtonReceiver == null);
@@ -949,8 +949,7 @@
                         mKeyEventReceiver);
             } else {
                 // Launch the last PendingIntent we had with priority
-                int userId = ActivityManager.getCurrentUser();
-                UserRecord user = mUserRecords.get(userId);
+                UserRecord user = mUserRecords.get(mCurrentUserId);
                 if (user != null && (user.mLastMediaButtonReceiver != null
                         || user.mRestoredMediaButtonReceiver != null)) {
                     if (DEBUG) {
@@ -967,11 +966,11 @@
                         if (user.mLastMediaButtonReceiver != null) {
                             user.mLastMediaButtonReceiver.send(getContext(),
                                     needWakeLock ? mKeyEventReceiver.mLastTimeoutId : -1,
-                                    mediaButtonIntent, mKeyEventReceiver, null);
+                                    mediaButtonIntent, mKeyEventReceiver, mHandler);
                         } else {
                             mediaButtonIntent.setComponent(user.mRestoredMediaButtonReceiver);
                             getContext().sendBroadcastAsUser(mediaButtonIntent,
-                                    new UserHandle(userId));
+                                    new UserHandle(mCurrentUserId));
                         }
                     } catch (CanceledException e) {
                         Log.i(TAG, "Error sending key event to media button receiver "
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
index 1997e40..5aaa930 100644
--- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -2333,7 +2333,7 @@
         @Override
         public void onAppIdleStateChanged(String packageName, int userId, boolean idle) {
             try {
-                int uid = mContext.getPackageManager().getPackageUid(packageName, userId);
+                int uid = mContext.getPackageManager().getPackageUidAsUser(packageName, userId);
                 synchronized (mRulesLock) {
                     updateRuleForAppIdleLocked(uid);
                 }
diff --git a/services/core/java/com/android/server/notification/ConditionProviders.java b/services/core/java/com/android/server/notification/ConditionProviders.java
index 1987214..ce18818 100644
--- a/services/core/java/com/android/server/notification/ConditionProviders.java
+++ b/services/core/java/com/android/server/notification/ConditionProviders.java
@@ -121,6 +121,11 @@
     }
 
     @Override
+    protected boolean checkType(IInterface service) {
+        return service instanceof IConditionProvider;
+    }
+
+    @Override
     public void onBootPhaseAppsCanStart() {
         super.onBootPhaseAppsCanStart();
         for (int i = 0; i < mSystemConditionProviders.size(); i++) {
diff --git a/services/core/java/com/android/server/notification/ManagedServices.java b/services/core/java/com/android/server/notification/ManagedServices.java
index b7662da..09e6647 100644
--- a/services/core/java/com/android/server/notification/ManagedServices.java
+++ b/services/core/java/com/android/server/notification/ManagedServices.java
@@ -141,6 +141,8 @@
 
     abstract protected IInterface asInterface(IBinder binder);
 
+    abstract protected boolean checkType(IInterface service);
+
     abstract protected void onServiceAdded(ManagedServiceInfo info);
 
     protected void onServiceRemovedLocked(ManagedServiceInfo removed) { }
@@ -169,7 +171,8 @@
             if (filter != null && !filter.matches(info.component)) continue;
             pw.println("      " + info.component
                     + " (user " + info.userid + "): " + info.service
-                    + (info.isSystem?" SYSTEM":""));
+                    + (info.isSystem?" SYSTEM":"")
+                    + (info.isGuest(this)?" GUEST":""));
         }
     }
 
@@ -266,6 +269,18 @@
         }
     }
 
+    /**
+     * Add a service to our callbacks. The lifecycle of this service is managed externally,
+     * but unlike a system service, it should not be considered privledged.
+     * */
+    public void registerGuestService(ManagedServiceInfo guest) {
+        checkNotNull(guest.service);
+        checkType(guest.service);
+        if (registerServiceImpl(guest) != null) {
+            onServiceAdded(guest);
+        }
+    }
+
     public void setCategoryState(String category, boolean enabled) {
         synchronized (mMutex) {
             final Boolean previous = mCategoryEnabled.put(category, enabled);
@@ -484,7 +499,7 @@
         synchronized (mMutex) {
             // Unbind automatically bound services, retain system services.
             for (ManagedServiceInfo service : mServices) {
-                if (!service.isSystem) {
+                if (!service.isSystem && !service.isGuest(this)) {
                     toRemove.add(service);
                 }
             }
@@ -709,11 +724,15 @@
 
     private ManagedServiceInfo registerServiceImpl(final IInterface service,
             final ComponentName component, final int userid) {
+        ManagedServiceInfo info = newServiceInfo(service, component, userid,
+                true /*isSystem*/, null /*connection*/, Build.VERSION_CODES.LOLLIPOP);
+        return registerServiceImpl(info);
+    }
+
+    private ManagedServiceInfo registerServiceImpl(ManagedServiceInfo info) {
         synchronized (mMutex) {
             try {
-                ManagedServiceInfo info = newServiceInfo(service, component, userid,
-                        true /*isSystem*/, null, Build.VERSION_CODES.LOLLIPOP);
-                service.asBinder().linkToDeath(info, 0);
+                info.service.asBinder().linkToDeath(info, 0);
                 mServices.add(info);
                 return info;
             } catch (RemoteException e) {
@@ -728,7 +747,7 @@
      */
     private void unregisterServiceImpl(IInterface service, int userid) {
         ManagedServiceInfo info = removeServiceImpl(service, userid);
-        if (info != null && info.connection != null) {
+        if (info != null && info.connection != null && !info.isGuest(this)) {
             mContext.unbindService(info.connection);
         }
     }
@@ -780,6 +799,10 @@
             this.targetSdkVersion = targetSdkVersion;
         }
 
+        public boolean isGuest(ManagedServices host) {
+            return ManagedServices.this != host;
+        }
+
         @Override
         public String toString() {
             return new StringBuilder("ManagedServiceInfo[")
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 49aa73e..9dcccc4 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -33,12 +33,14 @@
 import static android.service.notification.NotificationListenerService.Ranking.IMPORTANCE_HIGH;
 import static android.service.notification.NotificationListenerService.SUPPRESSED_EFFECT_LIGHTS;
 import static android.service.notification.NotificationListenerService.SUPPRESSED_EFFECT_PEEK;
+import static android.service.notification.NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_ON;
 import static android.service.notification.NotificationListenerService.TRIM_FULL;
 import static android.service.notification.NotificationListenerService.TRIM_LIGHT;
 import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
 import static org.xmlpull.v1.XmlPullParser.END_TAG;
 import static org.xmlpull.v1.XmlPullParser.START_TAG;
 
+import android.Manifest;
 import android.app.ActivityManager;
 import android.app.ActivityManagerNative;
 import android.app.AppGlobals;
@@ -96,6 +98,7 @@
 import android.service.notification.IConditionProvider;
 import android.service.notification.INotificationListener;
 import android.service.notification.IStatusBarNotificationHolder;
+import android.service.notification.NotificationAssistantService;
 import android.service.notification.NotificationListenerService;
 import android.service.notification.NotificationRankingUpdate;
 import android.service.notification.StatusBarNotification;
@@ -154,6 +157,7 @@
 import java.util.List;
 import java.util.Map.Entry;
 import java.util.Objects;
+import java.util.concurrent.TimeUnit;
 
 /** {@hide} */
 public class NotificationManagerService extends SystemService {
@@ -167,11 +171,13 @@
     // message codes
     static final int MESSAGE_TIMEOUT = 2;
     static final int MESSAGE_SAVE_POLICY_FILE = 3;
-    static final int MESSAGE_RECONSIDER_RANKING = 4;
-    static final int MESSAGE_RANKING_CONFIG_CHANGE = 5;
-    static final int MESSAGE_SEND_RANKING_UPDATE = 6;
-    static final int MESSAGE_LISTENER_HINTS_CHANGED = 7;
-    static final int MESSAGE_LISTENER_NOTIFICATION_FILTER_CHANGED = 8;
+    static final int MESSAGE_SEND_RANKING_UPDATE = 4;
+    static final int MESSAGE_LISTENER_HINTS_CHANGED = 5;
+    static final int MESSAGE_LISTENER_NOTIFICATION_FILTER_CHANGED = 6;
+
+    // ranking thread messages
+    private static final int MESSAGE_RECONSIDER_RANKING = 1000;
+    private static final int MESSAGE_RANKING_SORT = 1001;
 
     static final int LONG_DELAY = 3500; // 3.5 seconds
     static final int SHORT_DELAY = 2000; // 2 seconds
@@ -281,11 +287,13 @@
 
     private final UserProfiles mUserProfiles = new UserProfiles();
     private NotificationListeners mListeners;
+    private NotificationAssistant mAssistant;
     private ConditionProviders mConditionProviders;
     private NotificationUsageStats mUsageStats;
 
     private static final int MY_UID = Process.myUid();
     private static final int MY_PID = Process.myPid();
+    private RankingHandler mRankingHandler;
 
     private static class Archive {
         final int mBufferSize;
@@ -738,6 +746,7 @@
                     }
                 }
                 mListeners.onPackagesChanged(queryReplace, pkgList);
+                mAssistant.onPackagesChanged(queryReplace, pkgList);
                 mConditionProviders.onPackagesChanged(queryReplace, pkgList);
                 mRankingHelper.onPackagesChanged(queryReplace, pkgList);
             }
@@ -779,6 +788,7 @@
                 // Refresh managed services
                 mConditionProviders.onUserSwitched(user);
                 mListeners.onUserSwitched(user);
+                mAssistant.onUserSwitched(user);
                 mZenModeHelper.onUserSwitched(user);
             } else if (action.equals(Intent.ACTION_USER_ADDED)) {
                 mUserProfiles.updateCache(context);
@@ -874,8 +884,9 @@
             extractorNames = new String[0];
         }
         mUsageStats = new NotificationUsageStats(getContext());
+        mRankingHandler = new RankingHandlerWorker(mRankingThread.getLooper());
         mRankingHelper = new RankingHelper(getContext(),
-                new RankingWorkerHandler(mRankingThread.getLooper()),
+                mRankingHandler,
                 mUsageStats,
                 extractorNames);
         mConditionProviders = new ConditionProviders(getContext(), mHandler, mUserProfiles);
@@ -909,6 +920,7 @@
         importOldBlockDb();
 
         mListeners = new NotificationListeners();
+        mAssistant = new NotificationAssistant();
         mStatusBar = getLocalService(StatusBarManagerInternal.class);
         mStatusBar.setNotificationDelegate(mNotificationDelegate);
 
@@ -1025,6 +1037,7 @@
             // bind to listener services.
             mSettingsObserver.observe();
             mListeners.onBootPhaseAppsCanStart();
+            mAssistant.onBootPhaseAppsCanStart();
             mConditionProviders.onBootPhaseAppsCanStart();
         }
     }
@@ -1896,6 +1909,22 @@
                 Binder.restoreCallingIdentity(identity);
             }
         }
+
+        @Override
+        public void setImportanceFromAssistant(INotificationListener token, String key,
+                int importance, CharSequence explanation) {
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                synchronized (mNotificationList) {
+                    mAssistant.checkServiceTokenLocked(token);
+                    NotificationRecord n = mNotificationsByKey.get(key);
+                    n.setImportance(importance, explanation);
+                    mRankingHandler.requestSort();
+                }
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
     };
 
     private String disableNotificationEffects(NotificationRecord record) {
@@ -2037,6 +2066,8 @@
                     pw.print(listener.component);
                 }
                 pw.println(')');
+                pw.println("\n  Notification assistant:");
+                mAssistant.dump(pw, filter);
             }
             pw.println("\n  Policy access:");
             pw.print("    mPolicyAccess: "); pw.println(mPolicyAccess);
@@ -2075,12 +2106,12 @@
         for (UserInfo user : UserManager.get(getContext()).getUsers()) {
             final int userId = user.getUserHandle().getIdentifier();
             final PackageManager packageManager = getContext().getPackageManager();
-            List<PackageInfo> packages = packageManager.getInstalledPackages(0, userId);
+            List<PackageInfo> packages = packageManager.getInstalledPackagesAsUser(0, userId);
             final int packageCount = packages.size();
             for (int p = 0; p < packageCount; p++) {
                 final String packageName = packages.get(p).packageName;
                 if (filter == null || filter.matches(packageName)) {
-                    final int uid = packageManager.getPackageUid(packageName, userId);
+                    final int uid = packageManager.getPackageUidAsUser(packageName, userId);
                     if (!checkNotificationOp(packageName, uid)) {
                         packageNames.add(packageName);
                     }
@@ -2533,9 +2564,14 @@
             updateLightsLocked();
         }
         if (buzz || beep || blink) {
-            EventLogTags.writeNotificationAlert(record.getKey(),
-                    buzz ? 1 : 0, beep ? 1 : 0, blink ? 1 : 0);
-            mHandler.post(mBuzzBeepBlinked);
+            if (((record.getSuppressedVisualEffects()
+                    & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_ON) != 0)) {
+                if (DBG) Slog.v(TAG, "Suppressed SystemUI from triggering screen on");
+            } else {
+                EventLogTags.writeNotificationAlert(record.getKey(),
+                        buzz ? 1 : 0, beep ? 1 : 0, blink ? 1 : 0);
+                mHandler.post(mBuzzBeepBlinked);
+            }
         }
     }
 
@@ -2686,7 +2722,7 @@
         }
     }
 
-    private void handleRankingConfigChange() {
+    private void handleRankingSort() {
         synchronized (mNotificationList) {
             final int N = mNotificationList.size();
             ArrayList<String> orderBefore = new ArrayList<String>(N);
@@ -2714,7 +2750,8 @@
         record.setIntercepted(mZenModeHelper.shouldIntercept(record));
         if (record.isIntercepted()) {
             int suppressed = (mZenModeHelper.shouldSuppressLight() ? SUPPRESSED_EFFECT_LIGHTS : 0)
-                    | (mZenModeHelper.shouldSuppressPeek() ? SUPPRESSED_EFFECT_PEEK : 0);
+                    | (mZenModeHelper.shouldSuppressPeek() ? SUPPRESSED_EFFECT_PEEK : 0)
+                    | (mZenModeHelper.shouldSuppressScreenOn() ? SUPPRESSED_EFFECT_SCREEN_ON : 0);
             record.setSuppressedVisualEffects(suppressed);
         }
     }
@@ -2788,9 +2825,9 @@
 
     }
 
-    private final class RankingWorkerHandler extends Handler
+    private final class RankingHandlerWorker extends Handler implements RankingHandler
     {
-        public RankingWorkerHandler(Looper looper) {
+        public RankingHandlerWorker(Looper looper) {
             super(looper);
         }
 
@@ -2800,11 +2837,23 @@
                 case MESSAGE_RECONSIDER_RANKING:
                     handleRankingReconsideration(msg);
                     break;
-                case MESSAGE_RANKING_CONFIG_CHANGE:
-                    handleRankingConfigChange();
+                case MESSAGE_RANKING_SORT:
+                    handleRankingSort();
                     break;
             }
         }
+
+        public void requestSort() {
+            removeMessages(MESSAGE_RANKING_SORT);
+            sendEmptyMessage(MESSAGE_RANKING_SORT);
+        }
+
+        public void requestReconsideration(RankingReconsideration recon) {
+            Message m = Message.obtain(this,
+                    NotificationManagerService.MESSAGE_RECONSIDER_RANKING, recon);
+            long delay = recon.getDelay(TimeUnit.MILLISECONDS);
+            sendMessageDelayed(m, delay);
+        }
     }
 
     // Notifications
@@ -3305,6 +3354,45 @@
         return true;
     }
 
+    public class NotificationAssistant extends ManagedServices {
+
+        public NotificationAssistant() {
+            super(getContext(), mHandler, mNotificationList, mUserProfiles);
+        }
+
+        @Override
+        protected Config getConfig() {
+            Config c = new Config();
+            c.caption = "notification assistant";
+            c.serviceInterface = NotificationAssistantService.SERVICE_INTERFACE;
+            c.secureSettingName = Settings.Secure.ENABLED_NOTIFICATION_ASSISTANT;
+            c.bindPermission = Manifest.permission.BIND_NOTIFICATION_ASSISTANT_SERVICE;
+            c.settingsAction = Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS;
+            c.clientLabel = R.string.notification_assistant_binding_label;
+            return c;
+        }
+
+        @Override
+        protected IInterface asInterface(IBinder binder) {
+            return INotificationListener.Stub.asInterface(binder);
+        }
+
+        @Override
+        protected boolean checkType(IInterface service) {
+            return service instanceof INotificationListener;
+        }
+
+        @Override
+        protected void onServiceAdded(ManagedServiceInfo info) {
+            mListeners.registerGuestService(info);
+        }
+
+        @Override
+        protected void onServiceRemovedLocked(ManagedServiceInfo removed) {
+            mListeners.unregisterService(removed.service, removed.userid);
+        }
+    }
+
     public class NotificationListeners extends ManagedServices {
 
         private final ArraySet<ManagedServiceInfo> mLightTrimListeners = new ArraySet<>();
@@ -3332,6 +3420,11 @@
         }
 
         @Override
+        protected boolean checkType(IInterface service) {
+            return service instanceof INotificationListener;
+        }
+
+        @Override
         public void onServiceAdded(ManagedServiceInfo info) {
             final INotificationListener listener = (INotificationListener) info.service;
             final NotificationRankingUpdate update;
@@ -3366,7 +3459,6 @@
 
         public int getOnNotificationPostedTrim(ManagedServiceInfo info) {
             return mLightTrimListeners.contains(info) ? TRIM_LIGHT : TRIM_FULL;
-
         }
 
         /**
diff --git a/core/java/android/service/notification/NotificationAdjustment.aidl b/services/core/java/com/android/server/notification/RankingHandler.java
similarity index 77%
rename from core/java/android/service/notification/NotificationAdjustment.aidl
rename to services/core/java/com/android/server/notification/RankingHandler.java
index 805fe2c..80bb4f0 100644
--- a/core/java/android/service/notification/NotificationAdjustment.aidl
+++ b/services/core/java/com/android/server/notification/RankingHandler.java
@@ -13,7 +13,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package com.android.server.notification;
 
-package android.service.notification;
-
-parcelable NotificationAdjustment;
\ No newline at end of file
+public interface RankingHandler {
+    public void requestSort();
+    public void requestReconsideration(RankingReconsideration recon);
+}
diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java
index 3287f67..f1fd42c 100644
--- a/services/core/java/com/android/server/notification/RankingHelper.java
+++ b/services/core/java/com/android/server/notification/RankingHelper.java
@@ -19,10 +19,7 @@
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
-import android.os.Handler;
-import android.os.Message;
 import android.os.UserHandle;
-import android.service.notification.NotificationListenerService;
 import android.service.notification.NotificationListenerService.Ranking;
 import android.text.TextUtils;
 import android.util.ArrayMap;
@@ -40,7 +37,6 @@
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.TimeUnit;
 
 public class RankingHelper implements RankingConfig {
     private static final String TAG = "RankingHelper";
@@ -73,10 +69,10 @@
     private final ArrayMap<String, Record> mRestoredWithoutUids = new ArrayMap<>(); // pkg => Record
 
     private final Context mContext;
-    private final Handler mRankingHandler;
+    private final RankingHandler mRankingHandler;
 
-    public RankingHelper(Context context, Handler rankingHandler, NotificationUsageStats usageStats,
-            String[] extractorNames) {
+    public RankingHelper(Context context, RankingHandler rankingHandler,
+            NotificationUsageStats usageStats, String[] extractorNames) {
         mContext = context;
         mRankingHandler = rankingHandler;
 
@@ -119,10 +115,7 @@
             try {
                 RankingReconsideration recon = extractor.process(r);
                 if (recon != null) {
-                    Message m = Message.obtain(mRankingHandler,
-                            NotificationManagerService.MESSAGE_RECONSIDER_RANKING, recon);
-                    long delay = recon.getDelay(TimeUnit.MILLISECONDS);
-                    mRankingHandler.sendMessageDelayed(m, delay);
+                    mRankingHandler.requestReconsideration(recon);
                 }
             } catch (Throwable t) {
                 Slog.w(TAG, "NotificationSignalExtractor failed.", t);
@@ -155,7 +148,7 @@
                         if (forRestore) {
                             try {
                                 //TODO: http://b/22388012
-                                uid = pm.getPackageUid(name, UserHandle.USER_SYSTEM);
+                                uid = pm.getPackageUidAsUser(name, UserHandle.USER_SYSTEM);
                             } catch (NameNotFoundException e) {
                                 // noop
                             }
@@ -287,7 +280,7 @@
         for (int i = 0; i < N; i++) {
             mSignalExtractors[i].setConfig(this);
         }
-        mRankingHandler.sendEmptyMessage(NotificationManagerService.MESSAGE_RANKING_CONFIG_CHANGE);
+        mRankingHandler.requestSort();
     }
 
     public void sort(ArrayList<NotificationRecord> notificationList) {
@@ -544,7 +537,7 @@
             if (r != null) {
                 try {
                     //TODO: http://b/22388012
-                    r.uid = pm.getPackageUid(r.pkg, UserHandle.USER_SYSTEM);
+                    r.uid = pm.getPackageUidAsUser(r.pkg, UserHandle.USER_SYSTEM);
                     mRestoredWithoutUids.remove(pkg);
                     mRecords.put(recordKey(r.pkg, r.uid), r);
                     updated = true;
diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java
index 85c3cf8..f7043a6 100644
--- a/services/core/java/com/android/server/notification/ZenModeHelper.java
+++ b/services/core/java/com/android/server/notification/ZenModeHelper.java
@@ -155,6 +155,12 @@
         }
     }
 
+    public boolean shouldSuppressScreenOn() {
+        synchronized (mConfig) {
+            return !mConfig.allowScreenOn;
+        }
+    }
+
     public void addCallback(Callback callback) {
         mCallbacks.add(callback);
     }
@@ -435,11 +441,12 @@
             return;
         }
         pw.printf("allow(calls=%s,callsFrom=%s,repeatCallers=%s,messages=%s,messagesFrom=%s,"
-                + "events=%s,reminders=%s,lights=%s,peek=%s)\n",
+                + "events=%s,reminders=%s,lights=%s,peek=%s,screenOn=%s)\n",
                 config.allowCalls, ZenModeConfig.sourceToString(config.allowCallsFrom),
                 config.allowRepeatCallers, config.allowMessages,
                 ZenModeConfig.sourceToString(config.allowMessagesFrom),
-                config.allowEvents, config.allowReminders, config.allowLights, config.allowPeek);
+                config.allowEvents, config.allowReminders, config.allowLights, config.allowPeek,
+                config.allowScreenOn);
         pw.print(prefix); pw.print("  manualRule="); pw.println(config.manualRule);
         if (config.automaticRules.isEmpty()) return;
         final int N = config.automaticRules.size();
@@ -563,13 +570,13 @@
             ZenLog.traceConfig(reason, mConfig, config);
             final boolean policyChanged = !Objects.equals(getNotificationPolicy(mConfig),
                     getNotificationPolicy(config));
-            mConfig = config;
-            if (config.equals(mConfig)) {
+            if (!config.equals(mConfig)) {
                 dispatchOnConfigChanged();
             }
             if (policyChanged) {
                 dispatchOnPolicyChanged();
             }
+            mConfig = config;
             final String val = Integer.toString(config.hashCode());
             Global.putString(mContext.getContentResolver(), Global.ZEN_MODE_CONFIG_ETAG, val);
             if (!evaluateZenMode(reason, setRingerMode)) {
diff --git a/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java b/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java
index b254f29..6c338c1 100644
--- a/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java
+++ b/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java
@@ -261,6 +261,7 @@
                     && doesPackageSupportRuntimePermissions(setupPackage)) {
                 grantRuntimePermissionsLPw(setupPackage, PHONE_PERMISSIONS, userId);
                 grantRuntimePermissionsLPw(setupPackage, CONTACTS_PERMISSIONS, userId);
+                grantRuntimePermissionsLPw(setupPackage, LOCATION_PERMISSIONS, userId);
             }
 
             // Camera
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 7bb6d1d..9e0f3ce 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -59,6 +59,10 @@
 import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER;
 import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
 import static android.content.pm.PackageManager.MATCH_ALL;
+import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS;
+import static android.content.pm.PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE;
+import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
+import static android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES;
 import static android.content.pm.PackageManager.MOVE_FAILED_DOESNT_EXIST;
 import static android.content.pm.PackageManager.MOVE_FAILED_INTERNAL_ERROR;
 import static android.content.pm.PackageManager.MOVE_FAILED_OPERATION_PENDING;
@@ -88,6 +92,8 @@
 import static com.android.server.pm.PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED;
 
 import android.Manifest;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.app.ActivityManager;
 import android.app.ActivityManagerNative;
 import android.app.AppGlobals;
@@ -106,6 +112,7 @@
 import android.content.pm.ActivityInfo;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.AppsQueryHelper;
+import android.content.pm.ComponentInfo;
 import android.content.pm.EphemeralApplicationInfo;
 import android.content.pm.EphemeralResolveInfo;
 import android.content.pm.EphemeralResolveInfo.EphemeralResolveIntentInfo;
@@ -122,7 +129,6 @@
 import android.content.pm.InstrumentationInfo;
 import android.content.pm.IntentFilterVerificationInfo;
 import android.content.pm.KeySet;
-import android.content.pm.ManifestDigest;
 import android.content.pm.PackageCleanItem;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageInfoLite;
@@ -207,7 +213,6 @@
 
 import com.android.internal.R;
 import com.android.internal.annotations.GuardedBy;
-import com.android.internal.annotations.GuardedBy;
 import com.android.internal.app.IMediaContainerService;
 import com.android.internal.app.ResolverActivity;
 import com.android.internal.content.NativeLibraryHelper;
@@ -308,7 +313,7 @@
     private static final boolean DEBUG_DEXOPT = false;
     private static final boolean DEBUG_ABI_SELECTION = false;
     private static final boolean DEBUG_EPHEMERAL = false;
-    private static final boolean DEBUG_ENCRYPTION_AWARE = false;
+    private static final boolean DEBUG_TRIAGED_MISSING = false;
 
     static final boolean CLEAR_RUNTIME_PERMISSIONS_ON_UPGRADE = false;
 
@@ -597,7 +602,9 @@
 
     boolean mResolverReplaced = false;
 
-    private final ComponentName mIntentFilterVerifierComponent;
+    private final @Nullable ComponentName mIntentFilterVerifierComponent;
+    private final @Nullable IntentFilterVerifier<ActivityIntentInfo> mIntentFilterVerifier;
+
     private int mIntentFilterVerificationToken = 0;
 
     /** Component that knows whether or not an ephemeral application exists */
@@ -808,7 +815,7 @@
                         packageName);
             }
             if (DEBUG_DOMAIN_VERIFICATION) {
-                Slog.d(TAG, "Adding verification filter for " + packageName + " : " + filter);
+                Slog.d(TAG, "Adding verification filter for " + packageName + ": " + filter);
             }
             ivs.addFilter(filter);
             return true;
@@ -833,8 +840,6 @@
                         filter.hasDataScheme(IntentFilter.SCHEME_HTTPS));
     }
 
-    private IntentFilterVerifier mIntentFilterVerifier;
-
     // Set of pending broadcasts for aggregating enable/disable of components.
     static class PendingPackageBroadcasts {
         // for each user id, a map of <package name -> components within that package>
@@ -969,8 +974,8 @@
     private static final String TAG_DEFAULT_APPS = "da";
     private static final String TAG_INTENT_FILTER_VERIFICATION = "iv";
 
-    final String mRequiredVerifierPackage;
-    final String mRequiredInstallerPackage;
+    final @Nullable String mRequiredVerifierPackage;
+    final @Nullable String mRequiredInstallerPackage;
 
     private final PackageUsage mPackageUsage = new PackageUsage();
 
@@ -2357,15 +2362,21 @@
             EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_READY,
                     SystemClock.uptimeMillis());
 
-            mRequiredVerifierPackage = getRequiredVerifierLPr();
-            mRequiredInstallerPackage = getRequiredInstallerLPr();
+            if (!mOnlyCore) {
+                mRequiredVerifierPackage = getRequiredVerifierLPr();
+                mRequiredInstallerPackage = getRequiredInstallerLPr();
+                mIntentFilterVerifierComponent = getIntentFilterVerifierComponentNameLPr();
+                mIntentFilterVerifier = new IntentVerifierProxy(mContext,
+                        mIntentFilterVerifierComponent);
+            } else {
+                mRequiredVerifierPackage = null;
+                mRequiredInstallerPackage = null;
+                mIntentFilterVerifierComponent = null;
+                mIntentFilterVerifier = null;
+            }
 
             mInstallerService = new PackageInstallerService(context, this);
 
-            mIntentFilterVerifierComponent = getIntentFilterVerifierComponentNameLPr();
-            mIntentFilterVerifier = new IntentVerifierProxy(mContext,
-                    mIntentFilterVerifierComponent);
-
             final ComponentName ephemeralResolverComponent = getEphemeralResolverLPr();
             final ComponentName ephemeralInstallerComponent = getEphemeralInstallerLPr();
             // both the installer and resolver must be present to enable ephemeral
@@ -2427,113 +2438,60 @@
         return mIsUpgrade;
     }
 
-    private String getRequiredVerifierLPr() {
-        final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
-        // We only care about verifier that's installed under system user.
-        final List<ResolveInfo> receivers = queryIntentReceivers(verification, PACKAGE_MIME_TYPE,
-                PackageManager.GET_DISABLED_COMPONENTS, UserHandle.USER_SYSTEM);
+    private @NonNull String getRequiredVerifierLPr() {
+        final Intent intent = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
 
-        String requiredVerifier = null;
-
-        final int N = receivers.size();
-        for (int i = 0; i < N; i++) {
-            final ResolveInfo info = receivers.get(i);
-
-            if (info.activityInfo == null) {
-                continue;
-            }
-
-            final String packageName = info.activityInfo.packageName;
-
-            if (checkPermission(android.Manifest.permission.PACKAGE_VERIFICATION_AGENT,
-                    packageName, UserHandle.USER_SYSTEM) != PackageManager.PERMISSION_GRANTED) {
-                continue;
-            }
-
-            if (requiredVerifier != null) {
-                throw new RuntimeException("There can be only one required verifier");
-            }
-
-            requiredVerifier = packageName;
+        final List<ResolveInfo> matches = queryIntentReceivers(intent, PACKAGE_MIME_TYPE,
+                MATCH_SYSTEM_ONLY | MATCH_ENCRYPTION_AWARE_AND_UNAWARE, UserHandle.USER_SYSTEM);
+        if (matches.size() == 1) {
+            return matches.get(0).getComponentInfo().packageName;
+        } else {
+            throw new RuntimeException("There must be exactly one verifier; found " + matches);
         }
-
-        return requiredVerifier;
     }
 
-    private String getRequiredInstallerLPr() {
-        Intent installerIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
-        installerIntent.addCategory(Intent.CATEGORY_DEFAULT);
-        installerIntent.setDataAndType(Uri.fromFile(new File("foo.apk")), PACKAGE_MIME_TYPE);
+    private @NonNull String getRequiredInstallerLPr() {
+        final Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
+        intent.addCategory(Intent.CATEGORY_DEFAULT);
+        intent.setDataAndType(Uri.fromFile(new File("foo.apk")), PACKAGE_MIME_TYPE);
 
-        final List<ResolveInfo> installers = queryIntentActivities(installerIntent,
-                PACKAGE_MIME_TYPE, 0, UserHandle.USER_SYSTEM);
-
-        String requiredInstaller = null;
-
-        final int N = installers.size();
-        for (int i = 0; i < N; i++) {
-            final ResolveInfo info = installers.get(i);
-            final String packageName = info.activityInfo.packageName;
-
-            if (!info.activityInfo.applicationInfo.isSystemApp()) {
-                continue;
-            }
-
-            if (requiredInstaller != null) {
-                throw new RuntimeException("There must be one required installer");
-            }
-
-            requiredInstaller = packageName;
+        final List<ResolveInfo> matches = queryIntentActivities(intent, PACKAGE_MIME_TYPE,
+                MATCH_SYSTEM_ONLY | MATCH_ENCRYPTION_AWARE_AND_UNAWARE, UserHandle.USER_SYSTEM);
+        if (matches.size() == 1) {
+            return matches.get(0).getComponentInfo().packageName;
+        } else {
+            throw new RuntimeException("There must be exactly one installer; found " + matches);
         }
-
-        if (requiredInstaller == null) {
-            throw new RuntimeException("There must be one required installer");
-        }
-
-        return requiredInstaller;
     }
 
-    private ComponentName getIntentFilterVerifierComponentNameLPr() {
-        final Intent verification = new Intent(Intent.ACTION_INTENT_FILTER_NEEDS_VERIFICATION);
-        final List<ResolveInfo> receivers = queryIntentReceivers(verification, PACKAGE_MIME_TYPE,
-                PackageManager.GET_DISABLED_COMPONENTS, UserHandle.USER_SYSTEM);
+    private @NonNull ComponentName getIntentFilterVerifierComponentNameLPr() {
+        final Intent intent = new Intent(Intent.ACTION_INTENT_FILTER_NEEDS_VERIFICATION);
 
-        ComponentName verifierComponentName = null;
-
-        int priority = -1000;
-        final int N = receivers.size();
+        final List<ResolveInfo> matches = queryIntentReceivers(intent, PACKAGE_MIME_TYPE,
+                MATCH_SYSTEM_ONLY | MATCH_ENCRYPTION_AWARE_AND_UNAWARE, UserHandle.USER_SYSTEM);
+        ResolveInfo best = null;
+        final int N = matches.size();
         for (int i = 0; i < N; i++) {
-            final ResolveInfo info = receivers.get(i);
-
-            if (info.activityInfo == null) {
-                continue;
-            }
-
-            final String packageName = info.activityInfo.packageName;
-
-            final PackageSetting ps = mSettings.mPackages.get(packageName);
-            if (ps == null) {
-                continue;
-            }
-
+            final ResolveInfo cur = matches.get(i);
+            final String packageName = cur.getComponentInfo().packageName;
             if (checkPermission(android.Manifest.permission.INTENT_FILTER_VERIFICATION_AGENT,
                     packageName, UserHandle.USER_SYSTEM) != PackageManager.PERMISSION_GRANTED) {
                 continue;
             }
 
-            // Select the IntentFilterVerifier with the highest priority
-            if (priority < info.priority) {
-                priority = info.priority;
-                verifierComponentName = new ComponentName(packageName, info.activityInfo.name);
-                if (DEBUG_DOMAIN_VERIFICATION) Slog.d(TAG, "Selecting IntentFilterVerifier: "
-                        + verifierComponentName + " with priority: " + info.priority);
+            if (best == null || cur.priority > best.priority) {
+                best = cur;
             }
         }
 
-        return verifierComponentName;
+        if (best != null) {
+            return best.getComponentInfo().getComponentName();
+        } else {
+            throw new RuntimeException("There must be at least one intent filter verifier");
+        }
     }
 
-    private ComponentName getEphemeralResolverLPr() {
+    private @Nullable ComponentName getEphemeralResolverLPr() {
         final String[] packageArray =
                 mContext.getResources().getStringArray(R.array.config_ephemeralResolverPackage);
         if (packageArray.length == 0) {
@@ -2543,9 +2501,9 @@
             return null;
         }
 
-        Intent resolverIntent = new Intent(Intent.ACTION_RESOLVE_EPHEMERAL_PACKAGE);
-        final List<ResolveInfo> resolvers = queryIntentServices(resolverIntent,
-                null /*resolvedType*/, 0 /*flags*/, UserHandle.USER_SYSTEM);
+        final Intent resolverIntent = new Intent(Intent.ACTION_RESOLVE_EPHEMERAL_PACKAGE);
+        final List<ResolveInfo> resolvers = queryIntentServices(resolverIntent, null,
+                MATCH_SYSTEM_ONLY | MATCH_ENCRYPTION_AWARE_AND_UNAWARE, UserHandle.USER_SYSTEM);
 
         final int N = resolvers.size();
         if (N == 0) {
@@ -2584,36 +2542,21 @@
         return null;
     }
 
-    private ComponentName getEphemeralInstallerLPr() {
-        Intent installerIntent = new Intent(Intent.ACTION_INSTALL_EPHEMERAL_PACKAGE);
-        installerIntent.addCategory(Intent.CATEGORY_DEFAULT);
-        installerIntent.setDataAndType(Uri.fromFile(new File("foo.apk")), PACKAGE_MIME_TYPE);
-        final List<ResolveInfo> installers = queryIntentActivities(installerIntent,
-                PACKAGE_MIME_TYPE, 0 /*flags*/, 0 /*userId*/);
+    private @Nullable ComponentName getEphemeralInstallerLPr() {
+        final Intent intent = new Intent(Intent.ACTION_INSTALL_EPHEMERAL_PACKAGE);
+        intent.addCategory(Intent.CATEGORY_DEFAULT);
+        intent.setDataAndType(Uri.fromFile(new File("foo.apk")), PACKAGE_MIME_TYPE);
 
-        ComponentName ephemeralInstaller = null;
-
-        final int N = installers.size();
-        for (int i = 0; i < N; i++) {
-            final ResolveInfo info = installers.get(i);
-            final String packageName = info.activityInfo.packageName;
-
-            if (!info.activityInfo.applicationInfo.isSystemApp()) {
-                if (DEBUG_EPHEMERAL) {
-                    Slog.d(TAG, "Ephemeral installer is not system app;"
-                            + " pkg: " + packageName + ", info:" + info);
-                }
-                continue;
-            }
-
-            if (ephemeralInstaller != null) {
-                throw new RuntimeException("There must only be one ephemeral installer");
-            }
-
-            ephemeralInstaller = new ComponentName(packageName, info.activityInfo.name);
+        final List<ResolveInfo> matches = queryIntentActivities(intent, PACKAGE_MIME_TYPE,
+                MATCH_SYSTEM_ONLY | MATCH_ENCRYPTION_AWARE_AND_UNAWARE, UserHandle.USER_SYSTEM);
+        if (matches.size() == 0) {
+            return null;
+        } else if (matches.size() == 1) {
+            return matches.get(0).getComponentInfo().getComponentName();
+        } else {
+            throw new RuntimeException(
+                    "There must be at most one ephemeral installer; found " + matches);
         }
-
-        return ephemeralInstaller;
     }
 
     private void primeDomainVerificationsLPw(int userId) {
@@ -2660,7 +2603,7 @@
                             + "' does not handle web links");
                 }
             } else {
-                Slog.w(TAG, "Unknown package '" + packageName + "' in sysconfig <app-link>");
+                Slog.w(TAG, "Unknown package " + packageName + " in sysconfig <app-link>");
             }
         }
 
@@ -2848,6 +2791,7 @@
     @Override
     public PackageInfo getPackageInfo(String packageName, int flags, int userId) {
         if (!sUserManager.exists(userId)) return null;
+        flags = updateFlagsForPackage(flags, userId, packageName);
         enforceCrossUserPermission(Binder.getCallingUid(), userId, false, false, "get package info");
         // reader
         synchronized (mPackages) {
@@ -2857,7 +2801,7 @@
             if (p != null) {
                 return generatePackageInfo(p, flags, userId);
             }
-            if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) {
+            if ((flags & MATCH_UNINSTALLED_PACKAGES) != 0) {
                 return generatePackageInfoFromSettingsLPw(packageName, flags, userId);
             }
         }
@@ -2898,6 +2842,7 @@
     @Override
     public int getPackageUidEtc(String packageName, int flags, int userId) {
         if (!sUserManager.exists(userId)) return -1;
+        flags = updateFlagsForPackage(flags, userId, packageName);
         enforceCrossUserPermission(Binder.getCallingUid(), userId, false, false, "get package uid");
 
         // reader
@@ -2906,7 +2851,7 @@
             if (p != null) {
                 return UserHandle.getUid(userId, p.applicationInfo.uid);
             }
-            if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) {
+            if ((flags & MATCH_UNINSTALLED_PACKAGES) != 0) {
                 final PackageSetting ps = mSettings.mPackages.get(packageName);
                 if (ps != null) {
                     return UserHandle.getUid(userId, ps.appId);
@@ -2924,10 +2869,8 @@
 
     @Override
     public int[] getPackageGidsEtc(String packageName, int flags, int userId) {
-        if (!sUserManager.exists(userId)) {
-            return null;
-        }
-
+        if (!sUserManager.exists(userId)) return null;
+        flags = updateFlagsForPackage(flags, userId, packageName);
         enforceCrossUserPermission(Binder.getCallingUid(), userId, false, false,
                 "getPackageGids");
 
@@ -2938,7 +2881,7 @@
                 PackageSetting ps = (PackageSetting) p.mExtras;
                 return ps.getPermissionsState().computeGids(userId);
             }
-            if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) {
+            if ((flags & MATCH_UNINSTALLED_PACKAGES) != 0) {
                 final PackageSetting ps = mSettings.mPackages.get(packageName);
                 if (ps != null) {
                     return ps.getPermissionsState().computeGids(userId);
@@ -2949,8 +2892,7 @@
         return null;
     }
 
-    static PermissionInfo generatePermissionInfo(
-            BasePermission bp, int flags) {
+    static PermissionInfo generatePermissionInfo(BasePermission bp, int flags) {
         if (bp.perm != null) {
             return PackageParser.generatePermissionInfo(bp.perm, flags);
         }
@@ -3047,7 +2989,7 @@
         if (ps != null) {
             PackageParser.Package pkg = ps.pkg;
             if (pkg == null) {
-                if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) == 0) {
+                if ((flags & MATCH_UNINSTALLED_PACKAGES) == 0) {
                     return null;
                 }
                 // Only data remains, so we aren't worried about code paths
@@ -3068,6 +3010,7 @@
     @Override
     public ApplicationInfo getApplicationInfo(String packageName, int flags, int userId) {
         if (!sUserManager.exists(userId)) return null;
+        flags = updateFlagsForApplication(flags, userId, packageName);
         enforceCrossUserPermission(Binder.getCallingUid(), userId, false, false, "get application info");
         // writer
         synchronized (mPackages) {
@@ -3085,7 +3028,7 @@
             if ("android".equals(packageName)||"system".equals(packageName)) {
                 return mAndroidApplication;
             }
-            if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) {
+            if ((flags & MATCH_UNINSTALLED_PACKAGES) != 0) {
                 return generateApplicationInfoFromSettingsLPw(packageName, flags, userId);
             }
         }
@@ -3182,46 +3125,88 @@
     }
 
     /**
-     * Augment the given flags depending on current user running state. This is
-     * purposefully done before acquiring {@link #mPackages} lock.
+     * Update given flags based on encryption status of current user.
      */
-    private int augmentFlagsForUser(int flags, int userId, Object cookie) {
-        if (cookie instanceof Intent) {
-            // If intent claims to be triaged, then we're fine with default
-            // matching behavior below
-            final Intent intent = (Intent) cookie;
-            if ((intent.getFlags() & Intent.FLAG_DEBUG_ENCRYPTION_TRIAGED) != 0) {
-                flags |= PackageManager.MATCH_ENCRYPTION_DEFAULT;
-            }
-        }
-
-        if ((flags & (PackageManager.MATCH_ENCRYPTION_UNAWARE_ONLY
-                | PackageManager.MATCH_ENCRYPTION_AWARE_ONLY)) != 0) {
-            // Caller expressed an opinion about what components they want to
-            // see, so fall through and give them what they want
+    private int updateFlagsForEncryption(int flags, int userId) {
+        if ((flags & (PackageManager.MATCH_ENCRYPTION_UNAWARE
+                | PackageManager.MATCH_ENCRYPTION_AWARE)) != 0) {
+            // Caller expressed an explicit opinion about what encryption
+            // aware/unaware components they want to see, so fall through and
+            // give them what they want
         } else {
             // Caller expressed no opinion, so match based on user state
             if (isUserKeyUnlocked(userId)) {
                 flags |= PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE;
             } else {
-                flags |= PackageManager.MATCH_ENCRYPTION_AWARE_ONLY;
-
-                // If we have a system caller that hasn't done their homework to
-                // decide they want this default behavior, yell at them
-                if (DEBUG_ENCRYPTION_AWARE && (Binder.getCallingUid() == Process.SYSTEM_UID)
-                        && ((flags & PackageManager.MATCH_ENCRYPTION_DEFAULT) == 0)) {
-                    Log.v(TAG, "Caller hasn't been triaged for FBE; they asked about " + cookie,
-                            new Throwable());
-                }
+                flags |= PackageManager.MATCH_ENCRYPTION_AWARE;
             }
         }
         return flags;
     }
 
+    /**
+     * Update given flags when being used to request {@link PackageInfo}.
+     */
+    private int updateFlagsForPackage(int flags, int userId, Object cookie) {
+        boolean triaged = true;
+        if ((flags & PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS
+                | PackageManager.GET_SERVICES | PackageManager.GET_PROVIDERS) != 0) {
+            // Caller is asking for component details, so they'd better be
+            // asking for specific encryption matching behavior, or be triaged
+            if ((flags & (PackageManager.MATCH_ENCRYPTION_UNAWARE
+                    | PackageManager.MATCH_ENCRYPTION_AWARE
+                    | PackageManager.MATCH_DEBUG_TRIAGED_MISSING)) == 0) {
+                triaged = false;
+            }
+        }
+        if ((flags & (PackageManager.MATCH_UNINSTALLED_PACKAGES
+                | PackageManager.MATCH_DEBUG_TRIAGED_MISSING)) == 0) {
+            triaged = false;
+        }
+        if (DEBUG_TRIAGED_MISSING && (Binder.getCallingUid() == Process.SYSTEM_UID) && !triaged) {
+            Log.w(TAG, "Caller hasn't been triaged for missing apps; they asked about " + cookie,
+                    new Throwable());
+        }
+        return updateFlagsForEncryption(flags, userId);
+    }
+
+    /**
+     * Update given flags when being used to request {@link ApplicationInfo}.
+     */
+    private int updateFlagsForApplication(int flags, int userId, Object cookie) {
+        return updateFlagsForPackage(flags, userId, cookie);
+    }
+
+    /**
+     * Update given flags when being used to request {@link ComponentInfo}.
+     */
+    private int updateFlagsForComponent(int flags, int userId, Object cookie) {
+        boolean triaged = true;
+        // Caller is asking for component details, so they'd better be
+        // asking for specific encryption matching behavior, or be triaged
+        if ((flags & (PackageManager.MATCH_ENCRYPTION_UNAWARE
+                | PackageManager.MATCH_ENCRYPTION_AWARE
+                | PackageManager.MATCH_DEBUG_TRIAGED_MISSING)) == 0) {
+            triaged = false;
+        }
+        if (DEBUG_TRIAGED_MISSING && (Binder.getCallingUid() == Process.SYSTEM_UID) && !triaged) {
+            Log.w(TAG, "Caller hasn't been triaged for missing apps; they asked about " + cookie,
+                    new Throwable());
+        }
+        return updateFlagsForEncryption(flags, userId);
+    }
+
+    /**
+     * Update given flags when being used to request {@link ResolveInfo}.
+     */
+    private int updateFlagsForResolve(int flags, int userId, Object cookie) {
+        return updateFlagsForComponent(flags, userId, cookie);
+    }
+
     @Override
     public ActivityInfo getActivityInfo(ComponentName component, int flags, int userId) {
         if (!sUserManager.exists(userId)) return null;
-        flags = augmentFlagsForUser(flags, userId, component);
+        flags = updateFlagsForComponent(flags, userId, component);
         enforceCrossUserPermission(Binder.getCallingUid(), userId, false, false, "get activity info");
         synchronized (mPackages) {
             PackageParser.Activity a = mActivities.mActivities.get(component);
@@ -3266,7 +3251,7 @@
     @Override
     public ActivityInfo getReceiverInfo(ComponentName component, int flags, int userId) {
         if (!sUserManager.exists(userId)) return null;
-        flags = augmentFlagsForUser(flags, userId, component);
+        flags = updateFlagsForComponent(flags, userId, component);
         enforceCrossUserPermission(Binder.getCallingUid(), userId, false, false, "get receiver info");
         synchronized (mPackages) {
             PackageParser.Activity a = mReceivers.mActivities.get(component);
@@ -3285,7 +3270,7 @@
     @Override
     public ServiceInfo getServiceInfo(ComponentName component, int flags, int userId) {
         if (!sUserManager.exists(userId)) return null;
-        flags = augmentFlagsForUser(flags, userId, component);
+        flags = updateFlagsForComponent(flags, userId, component);
         enforceCrossUserPermission(Binder.getCallingUid(), userId, false, false, "get service info");
         synchronized (mPackages) {
             PackageParser.Service s = mServices.mServices.get(component);
@@ -3304,7 +3289,7 @@
     @Override
     public ProviderInfo getProviderInfo(ComponentName component, int flags, int userId) {
         if (!sUserManager.exists(userId)) return null;
-        flags = augmentFlagsForUser(flags, userId, component);
+        flags = updateFlagsForComponent(flags, userId, component);
         enforceCrossUserPermission(Binder.getCallingUid(), userId, false, false, "get provider info");
         synchronized (mPackages) {
             PackageParser.Provider p = mProviders.mProviders.get(component);
@@ -3732,8 +3717,8 @@
 
             final int flags = permissionsState.getPermissionFlags(name, userId);
             if ((flags & PackageManager.FLAG_PERMISSION_SYSTEM_FIXED) != 0) {
-                throw new SecurityException("Cannot grant system fixed permission: "
-                        + name + " for package: " + packageName);
+                throw new SecurityException("Cannot grant system fixed permission "
+                        + name + " for package " + packageName);
             }
 
             if (bp.isDevelopment()) {
@@ -3841,8 +3826,8 @@
 
             final int flags = permissionsState.getPermissionFlags(name, userId);
             if ((flags & PackageManager.FLAG_PERMISSION_SYSTEM_FIXED) != 0) {
-                throw new SecurityException("Cannot revoke system fixed permission: "
-                        + name + " for package: " + packageName);
+                throw new SecurityException("Cannot revoke system fixed permission "
+                        + name + " for package " + packageName);
             }
 
             if (bp.isDevelopment()) {
@@ -4429,7 +4414,7 @@
     public ResolveInfo resolveIntent(Intent intent, String resolvedType,
             int flags, int userId) {
         if (!sUserManager.exists(userId)) return null;
-        flags = augmentFlagsForUser(flags, userId, intent);
+        flags = updateFlagsForResolve(flags, userId, intent);
         enforceCrossUserPermission(Binder.getCallingUid(), userId, false, false, "resolve intent");
         List<ResolveInfo> query = queryIntentActivities(intent, resolvedType, flags, userId);
         final ResolveInfo bestChoice =
@@ -4647,7 +4632,7 @@
                     ppa.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), "  ");
                 }
                 final ActivityInfo ai = getActivityInfo(ppa.mComponent,
-                        flags | PackageManager.GET_DISABLED_COMPONENTS, userId);
+                        flags | MATCH_DISABLED_COMPONENTS, userId);
                 if (DEBUG_PREFERRED || debug) {
                     Slog.v(TAG, "Found persistent preferred activity:");
                     if (ai != null) {
@@ -4687,7 +4672,7 @@
             List<ResolveInfo> query, int priority, boolean always,
             boolean removeMatches, boolean debug, int userId) {
         if (!sUserManager.exists(userId)) return null;
-        flags = augmentFlagsForUser(flags, userId, intent);
+        flags = updateFlagsForResolve(flags, userId, intent);
         // writer
         synchronized (mPackages) {
             if (intent.getSelector() != null) {
@@ -4756,7 +4741,7 @@
                             continue;
                         }
                         final ActivityInfo ai = getActivityInfo(pa.mPref.mComponent,
-                                flags | PackageManager.GET_DISABLED_COMPONENTS, userId);
+                                flags | MATCH_DISABLED_COMPONENTS, userId);
                         if (DEBUG_PREFERRED || debug) {
                             Slog.v(TAG, "Found preferred activity:");
                             if (ai != null) {
@@ -4886,7 +4871,7 @@
     public List<ResolveInfo> queryIntentActivities(Intent intent,
             String resolvedType, int flags, int userId) {
         if (!sUserManager.exists(userId)) return Collections.emptyList();
-        flags = augmentFlagsForUser(flags, userId, intent);
+        flags = updateFlagsForResolve(flags, userId, intent);
         enforceCrossUserPermission(Binder.getCallingUid(), userId, false, false, "query intent activities");
         ComponentName comp = intent.getComponent();
         if (comp == null) {
@@ -5370,7 +5355,7 @@
             Intent[] specifics, String[] specificTypes, Intent intent,
             String resolvedType, int flags, int userId) {
         if (!sUserManager.exists(userId)) return Collections.emptyList();
-        flags = augmentFlagsForUser(flags, userId, intent);
+        flags = updateFlagsForResolve(flags, userId, intent);
         enforceCrossUserPermission(Binder.getCallingUid(), userId, false,
                 false, "query intent activity options");
         final String resultsAction = intent.getAction();
@@ -5543,7 +5528,7 @@
     public List<ResolveInfo> queryIntentReceivers(Intent intent, String resolvedType, int flags,
             int userId) {
         if (!sUserManager.exists(userId)) return Collections.emptyList();
-        flags = augmentFlagsForUser(flags, userId, intent);
+        flags = updateFlagsForResolve(flags, userId, intent);
         ComponentName comp = intent.getComponent();
         if (comp == null) {
             if (intent.getSelector() != null) {
@@ -5580,7 +5565,7 @@
     @Override
     public ResolveInfo resolveService(Intent intent, String resolvedType, int flags, int userId) {
         if (!sUserManager.exists(userId)) return null;
-        flags = augmentFlagsForUser(flags, userId, intent);
+        flags = updateFlagsForResolve(flags, userId, intent);
         List<ResolveInfo> query = queryIntentServices(intent, resolvedType, flags, userId);
         if (query != null) {
             if (query.size() >= 1) {
@@ -5596,7 +5581,7 @@
     public List<ResolveInfo> queryIntentServices(Intent intent, String resolvedType, int flags,
             int userId) {
         if (!sUserManager.exists(userId)) return Collections.emptyList();
-        flags = augmentFlagsForUser(flags, userId, intent);
+        flags = updateFlagsForResolve(flags, userId, intent);
         ComponentName comp = intent.getComponent();
         if (comp == null) {
             if (intent.getSelector() != null) {
@@ -5634,7 +5619,7 @@
     public List<ResolveInfo> queryIntentContentProviders(
             Intent intent, String resolvedType, int flags, int userId) {
         if (!sUserManager.exists(userId)) return Collections.emptyList();
-        flags = augmentFlagsForUser(flags, userId, intent);
+        flags = updateFlagsForResolve(flags, userId, intent);
         ComponentName comp = intent.getComponent();
         if (comp == null) {
             if (intent.getSelector() != null) {
@@ -5670,8 +5655,9 @@
 
     @Override
     public ParceledListSlice<PackageInfo> getInstalledPackages(int flags, int userId) {
-        final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
-
+        if (!sUserManager.exists(userId)) return ParceledListSlice.emptyList();
+        flags = updateFlagsForPackage(flags, userId, null);
+        final boolean listUninstalled = (flags & MATCH_UNINSTALLED_PACKAGES) != 0;
         enforceCrossUserPermission(Binder.getCallingUid(), userId, true, false, "get installed packages");
 
         // writer
@@ -5750,8 +5736,9 @@
     @Override
     public ParceledListSlice<PackageInfo> getPackagesHoldingPermissions(
             String[] permissions, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
+        if (!sUserManager.exists(userId)) return ParceledListSlice.emptyList();
+        flags = updateFlagsForPackage(flags, userId, permissions);
+        final boolean listUninstalled = (flags & MATCH_UNINSTALLED_PACKAGES) != 0;
 
         // writer
         synchronized (mPackages) {
@@ -5777,8 +5764,9 @@
 
     @Override
     public ParceledListSlice<ApplicationInfo> getInstalledApplications(int flags, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
+        if (!sUserManager.exists(userId)) return ParceledListSlice.emptyList();
+        flags = updateFlagsForApplication(flags, userId, null);
+        final boolean listUninstalled = (flags & MATCH_UNINSTALLED_PACKAGES) != 0;
 
         // writer
         synchronized (mPackages) {
@@ -5920,7 +5908,7 @@
     @Override
     public ProviderInfo resolveContentProvider(String name, int flags, int userId) {
         if (!sUserManager.exists(userId)) return null;
-        flags = augmentFlagsForUser(flags, userId, name);
+        flags = updateFlagsForComponent(flags, userId, name);
         // reader
         synchronized (mPackages) {
             final PackageParser.Provider provider = mProvidersByAuthority.get(name);
@@ -5972,7 +5960,7 @@
         final int userId = processName != null ? UserHandle.getUserId(uid)
                 : UserHandle.getCallingUserId();
         if (!sUserManager.exists(userId)) return null;
-        flags = augmentFlagsForUser(flags, userId, processName);
+        flags = updateFlagsForComponent(flags, userId, processName);
 
         ArrayList<ProviderInfo> finalList = null;
         // reader
@@ -6009,8 +5997,7 @@
     }
 
     @Override
-    public InstrumentationInfo getInstrumentationInfo(ComponentName name,
-            int flags) {
+    public InstrumentationInfo getInstrumentationInfo(ComponentName name, int flags) {
         // reader
         synchronized (mPackages) {
             final PackageParser.Instrumentation i = mInstrumentation.get(name);
@@ -6205,7 +6192,6 @@
 
         try {
             pp.collectCertificates(pkg, parseFlags);
-            pp.collectManifestDigest(pkg);
         } catch (PackageParserException e) {
             throw PackageManagerException.from(e);
         }
@@ -6293,7 +6279,7 @@
                             + " ignored: updated version " + ps.versionCode
                             + " better than this " + pkg.mVersionCode);
                     if (!updatedPkg.codePath.equals(scanFile)) {
-                        Slog.w(PackageManagerService.TAG, "Code path for hidden system pkg : "
+                        Slog.w(PackageManagerService.TAG, "Code path for hidden system pkg "
                                 + ps.name + " changing from " + updatedPkg.codePathString
                                 + " to " + scanFile);
                         updatedPkg.codePath = scanFile;
@@ -6418,7 +6404,7 @@
                 baseResourcePath = ps.resourcePathString;
             } else {
                 // Should not happen at all. Just log an error.
-                Slog.e(TAG, "Resource path not set for pkg : " + pkg.packageName);
+                Slog.e(TAG, "Resource path not set for package " + pkg.packageName);
             }
         } else {
             resourcePath = pkg.codePath;
@@ -6667,7 +6653,7 @@
         synchronized (mPackages) {
             pkg = mPackages.get(packageName);
             if (pkg == null) {
-                throw new IllegalArgumentException("Missing package: " + packageName);
+                throw new IllegalArgumentException("Unknown package: " + packageName);
             }
         }
 
@@ -7177,7 +7163,7 @@
                                               pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) {
                             throw new PackageManagerException(
                                     INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES,
-                                            "Signature mismatch for shared user : "
+                                            "Signature mismatch for shared user: "
                                             + pkgSetting.sharedUser);
                         }
                     }
@@ -7429,7 +7415,7 @@
         if ((scanFlags & SCAN_NO_DEX) == 0 && (scanFlags & SCAN_NEW_INSTALL) != 0) {
             if (cpuAbiOverride == null && pkgSetting.cpuAbiOverrideString != null) {
                 Slog.w(TAG, "Ignoring persisted ABI override " + cpuAbiOverride +
-                        " for package: " + pkg.packageName);
+                        " for package " + pkg.packageName);
             }
         }
 
@@ -8136,7 +8122,7 @@
                     ps.primaryCpuAbiString = adjustedAbi;
                     if (ps.pkg != null && ps.pkg.applicationInfo != null) {
                         ps.pkg.applicationInfo.primaryCpuAbi = adjustedAbi;
-                        Slog.i(TAG, "Adjusting ABI for : " + ps.name + " to " + adjustedAbi);
+                        Slog.i(TAG, "Adjusting ABI for " + ps.name + " to " + adjustedAbi);
                         mInstaller.rmdex(ps.codePathString,
                                 getDexCodeInstructionSet(getPreferredInstructionSet()));
                     }
@@ -8374,7 +8360,7 @@
             // 64 bit apps will see a 64 bit primary ABI,
 
             if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_MULTIARCH) == 0) {
-                Slog.e(TAG, "Package: " + pkg + " has multiple bundled libs, but is not multiarch.");
+                Slog.e(TAG, "Package " + pkg + " has multiple bundled libs, but is not multiarch.");
             }
 
             if (VMRuntime.is64BitInstructionSet(getPreferredInstructionSet())) {
@@ -10037,7 +10023,7 @@
         }
         final VerificationParams verifParams = new VerificationParams(
                 null, sessionParams.originatingUri, sessionParams.referrerUri,
-                sessionParams.originatingUid, null);
+                sessionParams.originatingUid);
         verifParams.setInstallerUid(installerUid);
 
         final OriginInfo origin;
@@ -10620,7 +10606,7 @@
                     throw new SecurityException("Bad object " + obj + " for uid " + uid);
                 }
             } else {
-                throw new SecurityException("Unknown calling uid " + uid);
+                throw new SecurityException("Unknown calling UID: " + uid);
             }
 
             // Verify: can't set installerPackageName to a package that is
@@ -11019,13 +11005,6 @@
                     + " file=" + origin.file + " cid=" + origin.cid + "}";
         }
 
-        public ManifestDigest getManifestDigest() {
-            if (verificationParams == null) {
-                return null;
-            }
-            return verificationParams.getManifestDigest();
-        }
-
         private int installLocationPolicy(PackageInfoLite pkgLite) {
             String packageName = pkgLite.packageName;
             int installLocation = pkgLite.installLocation;
@@ -11228,9 +11207,9 @@
                             PACKAGE_MIME_TYPE);
                     verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
 
+                    // Query all live verifiers based on current user state
                     final List<ResolveInfo> receivers = queryIntentReceivers(verification,
-                            PACKAGE_MIME_TYPE, PackageManager.GET_DISABLED_COMPONENTS,
-                            verifierUser.getIdentifier());
+                            PACKAGE_MIME_TYPE, 0, verifierUser.getIdentifier());
 
                     if (DEBUG_VERIFY) {
                         Slog.d(TAG, "Found " + receivers.size() + " verifiers for intent "
@@ -11444,7 +11423,6 @@
         final int installFlags;
         final String installerPackageName;
         final String volumeUuid;
-        final ManifestDigest manifestDigest;
         final UserHandle user;
         final String abiOverride;
         final String[] installGrantPermissions;
@@ -11459,7 +11437,7 @@
 
         InstallArgs(OriginInfo origin, MoveInfo move, IPackageInstallObserver2 observer,
                 int installFlags, String installerPackageName, String volumeUuid,
-                ManifestDigest manifestDigest, UserHandle user, String[] instructionSets,
+                UserHandle user, String[] instructionSets,
                 String abiOverride, String[] installGrantPermissions,
                 String traceMethod, int traceCookie) {
             this.origin = origin;
@@ -11468,7 +11446,6 @@
             this.observer = observer;
             this.installerPackageName = installerPackageName;
             this.volumeUuid = volumeUuid;
-            this.manifestDigest = manifestDigest;
             this.user = user;
             this.instructionSets = instructionSets;
             this.abiOverride = abiOverride;
@@ -11543,8 +11520,8 @@
                 for (String dexCodeInstructionSet : dexCodeInstructionSets) {
                     int retCode = mInstaller.rmdex(codePath, dexCodeInstructionSet);
                     if (retCode < 0) {
-                        Slog.w(TAG, "Couldn't remove dex file for package: "
-                                + " at location " + codePath + ", retcode=" + retCode);
+                        Slog.w(TAG, "Couldn't remove dex file for package at location " + codePath
+                                + ", retcode=" + retCode);
                         // we don't consider this to be a failure of the core package deletion
                     }
                 }
@@ -11570,7 +11547,7 @@
         /** New install */
         FileInstallArgs(InstallParams params) {
             super(params.origin, params.move, params.observer, params.installFlags,
-                    params.installerPackageName, params.volumeUuid, params.getManifestDigest(),
+                    params.installerPackageName, params.volumeUuid,
                     params.getUser(), null /* instruction sets */, params.packageAbiOverride,
                     params.grantedRuntimePermissions,
                     params.traceMethod, params.traceCookie);
@@ -11581,7 +11558,7 @@
 
         /** Existing install */
         FileInstallArgs(String codePath, String resourcePath, String[] instructionSets) {
-            super(OriginInfo.fromNothing(), null, null, 0, null, null, null, null, instructionSets,
+            super(OriginInfo.fromNothing(), null, null, 0, null, null, null, instructionSets,
                     null, null, null, 0);
             this.codeFile = (codePath != null) ? new File(codePath) : null;
             this.resourceFile = (resourcePath != null) ? new File(resourcePath) : null;
@@ -11808,7 +11785,7 @@
         /** New install */
         AsecInstallArgs(InstallParams params) {
             super(params.origin, params.move, params.observer, params.installFlags,
-                    params.installerPackageName, params.volumeUuid, params.getManifestDigest(),
+                    params.installerPackageName, params.volumeUuid,
                     params.getUser(), null /* instruction sets */, params.packageAbiOverride,
                     params.grantedRuntimePermissions,
                     params.traceMethod, params.traceCookie);
@@ -11818,7 +11795,7 @@
         AsecInstallArgs(String fullCodePath, String[] instructionSets,
                         boolean isExternal, boolean isForwardLocked) {
             super(OriginInfo.fromNothing(), null, null, (isExternal ? INSTALL_EXTERNAL : 0)
-                    | (isForwardLocked ? INSTALL_FORWARD_LOCK : 0), null, null, null, null,
+                    | (isForwardLocked ? INSTALL_FORWARD_LOCK : 0), null, null, null,
                     instructionSets, null, null, null, 0);
             // Hackily pretend we're still looking at a full code path
             if (!fullCodePath.endsWith(RES_FILE_NAME)) {
@@ -11835,7 +11812,7 @@
 
         AsecInstallArgs(String cid, String[] instructionSets, boolean isForwardLocked) {
             super(OriginInfo.fromNothing(), null, null, (isAsecExternal(cid) ? INSTALL_EXTERNAL : 0)
-                    | (isForwardLocked ? INSTALL_FORWARD_LOCK : 0), null, null, null, null,
+                    | (isForwardLocked ? INSTALL_FORWARD_LOCK : 0), null, null, null,
                     instructionSets, null, null, null, 0);
             this.cid = cid;
             setMountPath(PackageHelper.getSdDir(cid));
@@ -12102,7 +12079,7 @@
         /** New install */
         MoveInstallArgs(InstallParams params) {
             super(params.origin, params.move, params.observer, params.installFlags,
-                    params.installerPackageName, params.volumeUuid, params.getManifestDigest(),
+                    params.installerPackageName, params.volumeUuid,
                     params.getUser(), null /* instruction sets */, params.packageAbiOverride,
                     params.grantedRuntimePermissions,
                     params.traceMethod, params.traceCookie);
@@ -12578,7 +12555,7 @@
             if((oldPkg == null) || (oldPkg.applicationInfo == null) ||
                     (oldPkgSetting == null)) {
                 res.setError(INSTALL_FAILED_REPLACE_COULDNT_DELETE,
-                        "Couldn't find package:" + packageName + " information");
+                        "Couldn't find package " + packageName + " information");
                 return;
             }
         }
@@ -12876,35 +12853,6 @@
             Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
         }
 
-        /* If the installer passed in a manifest digest, compare it now. */
-        if (args.manifestDigest != null) {
-            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectManifestDigest");
-            try {
-                pp.collectManifestDigest(pkg);
-            } catch (PackageParserException e) {
-                res.setError("Failed collect during installPackageLI", e);
-                return;
-            } finally {
-                Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
-            }
-
-            if (DEBUG_INSTALL) {
-                final String parsedManifest = pkg.manifestDigest == null ? "null"
-                        : pkg.manifestDigest.toString();
-                Slog.d(TAG, "Comparing manifests: " + args.manifestDigest.toString() + " vs. "
-                        + parsedManifest);
-            }
-
-            if (!args.manifestDigest.equals(pkg.manifestDigest)) {
-                res.setError(INSTALL_FAILED_PACKAGE_CHANGED, "Manifest digest changed");
-                return;
-            }
-        } else if (DEBUG_INSTALL) {
-            final String parsedManifest = pkg.manifestDigest == null
-                    ? "null" : pkg.manifestDigest.toString();
-            Slog.d(TAG, "manifestDigest was not present, but parser got: " + parsedManifest);
-        }
-
         // Get rid of all references to package scan path via parser.
         pp = null;
         String oldCodePath = null;
@@ -13692,7 +13640,7 @@
         try {
             newPkg = scanPackageTracedLI(disabledPs.codePath, parseFlags, SCAN_NO_PATHS, 0, null);
         } catch (PackageManagerException e) {
-            Slog.w(TAG, "Failed to restore system package:" + newPs.name + ": " + e.getMessage());
+            Slog.w(TAG, "Failed to restore system package " + newPs.name + ": " + e.getMessage());
             return false;
         }
 
@@ -13910,13 +13858,13 @@
 
         boolean ret = false;
         if (isSystemApp(ps)) {
-            if (DEBUG_REMOVE) Slog.d(TAG, "Removing system package:" + ps.name);
+            if (DEBUG_REMOVE) Slog.d(TAG, "Removing system package: " + ps.name);
             // When an updated system application is deleted we delete the existing resources as well and
             // fall back to existing code in system partition
             ret = deleteSystemPackageLI(ps, allUserHandles, perUserInstalled,
                     flags, outInfo, writeSettings);
         } else {
-            if (DEBUG_REMOVE) Slog.d(TAG, "Removing non-system package:" + ps.name);
+            if (DEBUG_REMOVE) Slog.d(TAG, "Removing non-system package: " + ps.name);
             // Kill application pre-emptively especially for apps on sd.
             killApplication(packageName, ps.appId, "uninstall pkg");
             ret = deleteInstalledPackageLI(ps, deleteCodeAndResources, flags,
@@ -14065,7 +14013,7 @@
         // resorting to a full data wipe.
         int retCode = mInstaller.clearUserData(pkg.volumeUuid, packageName, userId);
         if (retCode < 0) {
-            Slog.w(TAG, "Couldn't remove cache files for package: " + packageName);
+            Slog.w(TAG, "Couldn't remove cache files for package " + packageName);
             return false;
         }
 
@@ -14295,7 +14243,7 @@
         }
         int retCode = mInstaller.deleteCacheFiles(p.volumeUuid, packageName, userId);
         if (retCode < 0) {
-            Slog.w(TAG, "Couldn't remove cache files for package: "
+            Slog.w(TAG, "Couldn't remove cache files for package "
                        + packageName + " u" + userId);
             return false;
         }
@@ -14740,7 +14688,7 @@
         }
         synchronized (mPackages) {
             Slog.i(TAG, "Adding persistent preferred activity " + activity + " for user " + userId +
-                    " :");
+                    ":");
             filter.dump(new LogPrinter(Log.INFO, TAG), "  ");
             mSettings.editPersistentPreferredActivitiesLPw(userId).addFilter(
                     new PersistentPreferredActivity(filter, activity));
@@ -15145,12 +15093,10 @@
             pkgSetting = mSettings.mPackages.get(packageName);
             if (pkgSetting == null) {
                 if (className == null) {
-                    throw new IllegalArgumentException(
-                            "Unknown package: " + packageName);
+                    throw new IllegalArgumentException("Unknown package: " + packageName);
                 }
                 throw new IllegalArgumentException(
-                        "Unknown component: " + packageName
-                        + "/" + className);
+                        "Unknown component: " + packageName + "/" + className);
             }
             // Allow root and verify that userId is not being specified by a different user
             if (!allowedByPermission && !UserHandle.isSameApp(uid, pkgSetting.appId)) {
@@ -17192,7 +17138,7 @@
         synchronized(mPackages) {
             final PackageParser.Package pkg = mPackages.get(packageName);
             if (pkg == null) {
-                Slog.w(TAG, "KeySet requested for unknown package:" + packageName);
+                Slog.w(TAG, "KeySet requested for unknown package: " + packageName);
                 throw new IllegalArgumentException("Unknown package: " + packageName);
             }
             KeySetManagerService ksms = mSettings.mKeySetManagerService;
@@ -17208,7 +17154,7 @@
         synchronized(mPackages) {
             final PackageParser.Package pkg = mPackages.get(packageName);
             if (pkg == null) {
-                Slog.w(TAG, "KeySet requested for unknown package:" + packageName);
+                Slog.w(TAG, "KeySet requested for unknown package: " + packageName);
                 throw new IllegalArgumentException("Unknown package: " + packageName);
             }
             if (pkg.applicationInfo.uid != Binder.getCallingUid()
@@ -17228,7 +17174,7 @@
         synchronized(mPackages) {
             final PackageParser.Package pkg = mPackages.get(packageName);
             if (pkg == null) {
-                Slog.w(TAG, "KeySet requested for unknown package:" + packageName);
+                Slog.w(TAG, "KeySet requested for unknown package: " + packageName);
                 throw new IllegalArgumentException("Unknown package: " + packageName);
             }
             IBinder ksh = ks.getToken();
@@ -17248,7 +17194,7 @@
         synchronized(mPackages) {
             final PackageParser.Package pkg = mPackages.get(packageName);
             if (pkg == null) {
-                Slog.w(TAG, "KeySet requested for unknown package:" + packageName);
+                Slog.w(TAG, "KeySet requested for unknown package: " + packageName);
                 throw new IllegalArgumentException("Unknown package: " + packageName);
             }
             IBinder ksh = ks.getToken();
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index d2a3ede..3f9ce7a 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -16,23 +16,42 @@
 
 package com.android.server.pm;
 
+import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED;
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER;
 import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
-import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
 import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS;
 import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
-import static android.os.Process.SYSTEM_UID;
+import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
+import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS;
+import static android.content.pm.PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS;
+import static android.content.pm.PackageManager.MATCH_ENCRYPTION_AWARE;
+import static android.content.pm.PackageManager.MATCH_ENCRYPTION_UNAWARE;
+import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
 import static android.os.Process.PACKAGE_INFO_GID;
+import static android.os.Process.SYSTEM_UID;
+
 import static com.android.server.pm.PackageManagerService.DEBUG_DOMAIN_VERIFICATION;
 
 import android.annotation.NonNull;
+import android.content.ComponentName;
+import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.ComponentInfo;
 import android.content.pm.IntentFilterVerificationInfo;
+import android.content.pm.PackageCleanItem;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageParser;
+import android.content.pm.PackageUserState;
+import android.content.pm.PermissionInfo;
 import android.content.pm.ResolveInfo;
+import android.content.pm.Signature;
+import android.content.pm.UserInfo;
+import android.content.pm.VerifierDeviceIdentity;
 import android.net.Uri;
 import android.os.Binder;
 import android.os.Build;
@@ -47,11 +66,18 @@
 import android.os.UserManager;
 import android.os.storage.StorageManager;
 import android.os.storage.VolumeInfo;
-import android.util.AtomicFile;
 import android.text.TextUtils;
+import android.util.ArrayMap;
+import android.util.ArraySet;
+import android.util.AtomicFile;
+import android.util.Log;
 import android.util.LogPrinter;
+import android.util.Slog;
+import android.util.SparseArray;
 import android.util.SparseBooleanArray;
+import android.util.SparseIntArray;
 import android.util.SparseLongArray;
+import android.util.Xml;
 
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.os.BackgroundThread;
@@ -65,58 +91,37 @@
 import com.android.server.pm.PackageManagerService.DumpState;
 import com.android.server.pm.PermissionsState.PermissionState;
 
-import java.io.BufferedInputStream;
-import java.io.BufferedWriter;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.nio.charset.Charset;
-import java.util.Collection;
+import libcore.io.IoUtils;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 import org.xmlpull.v1.XmlSerializer;
 
-import android.content.ComponentName;
-import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.ComponentInfo;
-import android.content.pm.PackageCleanItem;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageParser;
-import android.content.pm.PermissionInfo;
-import android.content.pm.Signature;
-import android.content.pm.UserInfo;
-import android.content.pm.PackageUserState;
-import android.content.pm.VerifierDeviceIdentity;
-import android.util.ArrayMap;
-import android.util.ArraySet;
-import android.util.Log;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.SparseIntArray;
-import android.util.Xml;
-
+import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
+import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.Set;
-import java.util.Map.Entry;
-
-import libcore.io.IoUtils;
 
 /**
  * Holds information about dynamic settings.
@@ -426,7 +431,7 @@
     boolean disableSystemPackageLPw(String name) {
         final PackageSetting p = mPackages.get(name);
         if(p == null) {
-            Log.w(PackageManagerService.TAG, "Package:"+name+" is not an installed package");
+            Log.w(PackageManagerService.TAG, "Package " + name + " is not an installed package");
             return false;
         }
         final PackageSetting dp = mDisabledSysPackages.get(name);
@@ -451,7 +456,7 @@
     PackageSetting enableSystemPackageLPw(String name) {
         PackageSetting p = mDisabledSysPackages.get(name);
         if(p == null) {
-            Log.w(PackageManagerService.TAG, "Package:"+name+" is not disabled");
+            Log.w(PackageManagerService.TAG, "Package " + name + " is not disabled");
             return null;
         }
         // Reset flag in ApplicationInfo object
@@ -1338,7 +1343,7 @@
             throws XmlPullParserException, IOException {
         IntentFilterVerificationInfo ivi = new IntentFilterVerificationInfo(parser);
         packageSetting.setIntentFilterVerificationInfo(ivi);
-        Log.d(TAG, "Read domain verification for package:" + ivi.getPackageName());
+        Log.d(TAG, "Read domain verification for package: " + ivi.getPackageName());
     }
 
     private void readRestoredIntentFilterVerifications(XmlPullParser parser)
@@ -1472,7 +1477,7 @@
                     String name = parser.getAttributeValue(null, ATTR_NAME);
                     ps = mPackages.get(name);
                     if (ps == null) {
-                        Slog.w(PackageManagerService.TAG, "No package known for stopped package: "
+                        Slog.w(PackageManagerService.TAG, "No package known for stopped package "
                                 + name);
                         XmlUtils.skipCurrentTag(parser);
                         continue;
@@ -2036,7 +2041,7 @@
                         }
                     } else {
                         Slog.w(PackageManagerService.TAG,
-                                "No package known for stopped package: " + name);
+                                "No package known for stopped package " + name);
                     }
                     XmlUtils.skipCurrentTag(parser);
                 } else {
@@ -2857,7 +2862,7 @@
         for (int i=0; i<tmpPa.countCategories(); i++) {
             String cat = tmpPa.getCategory(i);
             if (cat.equals(Intent.CATEGORY_DEFAULT)) {
-                flags |= PackageManager.MATCH_DEFAULT_ONLY;
+                flags |= MATCH_DEFAULT_ONLY;
             } else {
                 intent.addCategory(cat);
             }
@@ -3007,7 +3012,7 @@
                         filter.addCategory(cat);
                     }
                 }
-                if ((flags&PackageManager.MATCH_DEFAULT_ONLY) != 0) {
+                if ((flags & MATCH_DEFAULT_ONLY) != 0) {
                     filter.addCategory(Intent.CATEGORY_DEFAULT);
                 }
                 if (scheme != null) {
@@ -3799,7 +3804,7 @@
     }
 
     private boolean isEnabledLPr(ComponentInfo componentInfo, int flags, int userId) {
-        if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
+        if ((flags & MATCH_DISABLED_COMPONENTS) != 0) {
             return true;
         }
         final PackageSetting packageSettings = mPackages.get(componentInfo.packageName);
@@ -3815,7 +3820,7 @@
             return false;
         }
         PackageUserState ustate = packageSettings.readUserState(userId);
-        if ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0) {
+        if ((flags & MATCH_DISABLED_UNTIL_USED_COMPONENTS) != 0) {
             if (ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
                 return true;
             }
@@ -3839,16 +3844,16 @@
     }
 
     private boolean isMatchLPr(ComponentInfo componentInfo, int flags) {
-        if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) {
+        if ((flags & MATCH_SYSTEM_ONLY) != 0) {
             final PackageSetting ps = mPackages.get(componentInfo.packageName);
             if ((ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                 return false;
             }
         }
 
-        final boolean matchesUnaware = ((flags & PackageManager.MATCH_ENCRYPTION_UNAWARE_ONLY) != 0)
+        final boolean matchesUnaware = ((flags & MATCH_ENCRYPTION_UNAWARE) != 0)
                 && !componentInfo.encryptionAware;
-        final boolean matchesAware = ((flags & PackageManager.MATCH_ENCRYPTION_AWARE_ONLY) != 0)
+        final boolean matchesAware = ((flags & MATCH_ENCRYPTION_AWARE) != 0)
                 && componentInfo.encryptionAware;
         return matchesUnaware || matchesAware;
     }
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index 13f4826..3d614a3 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -69,6 +69,7 @@
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.app.IAppOpsService;
+import com.android.internal.logging.MetricsLogger;
 import com.android.internal.util.FastXmlSerializer;
 import com.android.internal.util.Preconditions;
 import com.android.internal.util.XmlUtils;
@@ -166,6 +167,10 @@
 
     private static final String XATTR_SERIAL = "user.serial";
 
+    // Tron counters
+    private static final String TRON_GUEST_CREATED = "users_guest_created";
+    private static final String TRON_USER_CREATED = "users_user_created";
+
     private final Context mContext;
     private final PackageManagerService mPm;
     private final Object mPackagesLock;
@@ -1830,6 +1835,7 @@
             addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
             mContext.sendBroadcastAsUser(addedIntent, UserHandle.ALL,
                     android.Manifest.permission.MANAGE_USERS);
+            MetricsLogger.count(mContext, isGuest ? TRON_GUEST_CREATED : TRON_USER_CREATED, 1);
         } finally {
             Binder.restoreCallingIdentity(ident);
         }
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 6fcf1d6..f13d964 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -18,6 +18,8 @@
 
 import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
 import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
+import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
+import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
 import static android.view.WindowManager.LayoutParams.*;
 import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
 import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
@@ -313,8 +315,10 @@
     boolean mCanHideNavigationBar = false;
     boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
     boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
-    int[] mNavigationBarHeightForRotation = new int[4];
-    int[] mNavigationBarWidthForRotation = new int[4];
+    int[] mNavigationBarHeightForRotationDefault = new int[4];
+    int[] mNavigationBarWidthForRotationDefault = new int[4];
+    int[] mNavigationBarHeightForRotationInCarMode = new int[4];
+    int[] mNavigationBarWidthForRotationInCarMode = new int[4];
 
     // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
     // This is for car dock and this is updated from resource.
@@ -1674,20 +1678,37 @@
                 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
 
         // Height of the navigation bar when presented horizontally at bottom
-        mNavigationBarHeightForRotation[mPortraitRotation] =
-        mNavigationBarHeightForRotation[mUpsideDownRotation] =
+        mNavigationBarHeightForRotationDefault[mPortraitRotation] =
+        mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
                 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
-        mNavigationBarHeightForRotation[mLandscapeRotation] =
-        mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
+        mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
+        mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
                 com.android.internal.R.dimen.navigation_bar_height_landscape);
 
         // Width of the navigation bar when presented vertically along one side
-        mNavigationBarWidthForRotation[mPortraitRotation] =
-        mNavigationBarWidthForRotation[mUpsideDownRotation] =
-        mNavigationBarWidthForRotation[mLandscapeRotation] =
-        mNavigationBarWidthForRotation[mSeascapeRotation] =
+        mNavigationBarWidthForRotationDefault[mPortraitRotation] =
+        mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
+        mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
+        mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
                 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
 
+        // Height of the navigation bar when presented horizontally at bottom
+        mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
+        mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
+                res.getDimensionPixelSize(
+                        com.android.internal.R.dimen.navigation_bar_height_car_mode);
+        mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
+        mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
+                com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
+
+        // Width of the navigation bar when presented vertically along one side
+        mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
+        mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
+        mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
+        mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
+                res.getDimensionPixelSize(
+                        com.android.internal.R.dimen.navigation_bar_width_car_mode);
+
         // SystemUI (status bar) layout policy
         int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
         int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
@@ -2239,42 +2260,61 @@
         return windowTypeToLayerLw(TYPE_STATUS_BAR);
     }
 
+    private int getNavigationBarWidth(int rotation, int uiMode) {
+        if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
+            return mNavigationBarWidthForRotationInCarMode[rotation];
+        } else {
+            return mNavigationBarWidthForRotationDefault[rotation];
+        }
+    }
+
     @Override
-    public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
+    public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
+            int uiMode) {
         if (mHasNavigationBar) {
             // For a basic navigation bar, when we are in landscape mode we place
             // the navigation bar to the side.
             if (mNavigationBarCanMove && fullWidth > fullHeight) {
-                return fullWidth - mNavigationBarWidthForRotation[rotation];
+                return fullWidth - getNavigationBarWidth(rotation, uiMode);
             }
         }
         return fullWidth;
     }
 
+    private int getNavigationBarHeight(int rotation, int uiMode) {
+        if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
+            return mNavigationBarHeightForRotationInCarMode[rotation];
+        } else {
+            return mNavigationBarHeightForRotationDefault[rotation];
+        }
+    }
+
     @Override
-    public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
+    public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
+            int uiMode) {
         if (mHasNavigationBar) {
             // For a basic navigation bar, when we are in portrait mode we place
             // the navigation bar to the bottom.
             if (!mNavigationBarCanMove || fullWidth < fullHeight) {
-                return fullHeight - mNavigationBarHeightForRotation[rotation];
+                return fullHeight - getNavigationBarHeight(rotation, uiMode);
             }
         }
         return fullHeight;
     }
 
     @Override
-    public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
-        return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
+    public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
+        return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
     }
 
     @Override
-    public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
+    public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
         // There is a separate status bar at the top of the display.  We don't count that as part
         // of the fixed decor, since it can hide; however, for purposes of configurations,
         // we do want to exclude it since applications can't generally use that part
         // of the screen.
-        return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
+        return getNonDecorDisplayHeight(
+                fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
     }
 
     @Override
@@ -2879,7 +2919,7 @@
         } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
             if (down) {
                 if (repeatCount == 0) {
-                    showKeyboardShortcutsMenu();
+                    toggleKeyboardShortcutsMenu();
                 }
             }
         } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
@@ -3311,11 +3351,11 @@
         }
     }
 
-    private void showKeyboardShortcutsMenu() {
+    private void toggleKeyboardShortcutsMenu() {
         try {
             IStatusBarService statusbar = getStatusBarService();
             if (statusbar != null) {
-                statusbar.showKeyboardShortcutsMenu();
+                statusbar.toggleKeyboardShortcutsMenu();
             }
         } catch (RemoteException e) {
             Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
@@ -3381,7 +3421,6 @@
             if (awakenFromDreams) {
                 awakenDreams();
             }
-            sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
             hideRecentApps(false, true);
         } else {
             // Otherwise, just launch Home
@@ -3551,7 +3590,7 @@
     /** {@inheritDoc} */
     @Override
     public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
-                              int displayRotation) {
+                              int displayRotation, int uiMode) {
         mDisplayRotation = displayRotation;
         final int overscanLeft, overscanTop, overscanRight, overscanBottom;
         if (isDefaultDisplay) {
@@ -3662,7 +3701,7 @@
             navVisible |= !canHideNavigationBar();
 
             boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
-                    displayRotation, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
+                    displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
                     navAllowedHidden);
             if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
                     mDockLeft, mDockTop, mDockRight, mDockBottom));
@@ -3741,7 +3780,7 @@
     }
 
     private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
-            int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
+            int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
             boolean navTranslucent, boolean navAllowedHidden) {
         if (mNavigationBar != null) {
             boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
@@ -3753,7 +3792,7 @@
             if (mNavigationBarOnBottom) {
                 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
                 int top = displayHeight - overscanBottom
-                        - mNavigationBarHeightForRotation[displayRotation];
+                        - getNavigationBarHeight(displayRotation, uiMode);
                 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
                 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
                 if (transientNavBarShowing) {
@@ -3778,7 +3817,7 @@
             } else {
                 // Landscape screen; nav bar goes to the right.
                 int left = displayWidth - overscanRight
-                        - mNavigationBarWidthForRotation[displayRotation];
+                        - getNavigationBarWidth(displayRotation, uiMode);
                 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
                 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
                 if (transientNavBarShowing) {
@@ -4243,6 +4282,7 @@
                         && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
                         && (attrs.type == TYPE_STATUS_BAR
                             || attrs.type == TYPE_TOAST
+                            || attrs.type == TYPE_DOCK_DIVIDER
                             || attrs.type == TYPE_VOICE_INTERACTION_STARTING
                             || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
                             && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
diff --git a/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java b/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java
index 29e3c63..549d2dc 100644
--- a/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java
+++ b/services/core/java/com/android/server/policy/keyguard/KeyguardServiceDelegate.java
@@ -126,7 +126,7 @@
 
         final ComponentName keyguardComponent = ComponentName.unflattenFromString(
                 resources.getString(com.android.internal.R.string.config_keyguardComponent));
-        intent.addFlags(Intent.FLAG_DEBUG_ENCRYPTION_TRIAGED);
+        intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
         intent.setComponent(keyguardComponent);
 
         if (!context.bindServiceAsUser(intent, mKeyguardConnection,
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 6498dd9..290019c 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -16,21 +16,8 @@
 
 package com.android.server.power;
 
-import android.app.ActivityManager;
-import android.util.SparseIntArray;
-import com.android.internal.app.IAppOpsService;
-import com.android.internal.app.IBatteryStats;
-import com.android.internal.os.BackgroundThread;
-import com.android.server.EventLogTags;
-import com.android.server.ServiceThread;
-import com.android.server.SystemService;
-import com.android.server.am.BatteryStatsService;
-import com.android.server.lights.Light;
-import com.android.server.lights.LightsManager;
-import com.android.server.Watchdog;
-
 import android.Manifest;
-import android.app.AppOpsManager;
+import android.app.ActivityManager;
 import android.content.BroadcastReceiver;
 import android.content.ContentResolver;
 import android.content.Context;
@@ -65,22 +52,32 @@
 import android.service.dreams.DreamManagerInternal;
 import android.util.EventLog;
 import android.util.Slog;
+import android.util.SparseIntArray;
 import android.util.TimeUtils;
 import android.view.Display;
 import android.view.WindowManagerPolicy;
+import com.android.internal.app.IAppOpsService;
+import com.android.internal.app.IBatteryStats;
+import com.android.internal.os.BackgroundThread;
+import com.android.server.EventLogTags;
+import com.android.server.ServiceThread;
+import com.android.server.SystemService;
+import com.android.server.Watchdog;
+import com.android.server.am.BatteryStatsService;
+import com.android.server.lights.Light;
+import com.android.server.lights.LightsManager;
+import libcore.util.Objects;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Arrays;
 
-import libcore.util.Objects;
-
 import static android.os.PowerManagerInternal.POWER_HINT_INTERACTION;
 import static android.os.PowerManagerInternal.WAKEFULNESS_ASLEEP;
 import static android.os.PowerManagerInternal.WAKEFULNESS_AWAKE;
-import static android.os.PowerManagerInternal.WAKEFULNESS_DREAMING;
 import static android.os.PowerManagerInternal.WAKEFULNESS_DOZING;
+import static android.os.PowerManagerInternal.WAKEFULNESS_DREAMING;
 
 /**
  * The power manager service is responsible for coordinating power management
@@ -771,6 +768,10 @@
                     intent = new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
                     intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
                     mContext.sendBroadcast(intent);
+                    // Send internal version that requires signature permission.
+                    mContext.sendBroadcastAsUser(new Intent(
+                            PowerManager.ACTION_POWER_SAVE_MODE_CHANGED_INTERNAL), UserHandle.ALL,
+                            Manifest.permission.DEVICE_POWER);
                 }
             });
         }
diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
index fc27170..2d38da5 100644
--- a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
+++ b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
@@ -503,10 +503,10 @@
     }
 
     @Override
-    public void showKeyboardShortcutsMenu() {
+    public void toggleKeyboardShortcutsMenu() {
         if (mBar != null) {
             try {
-                mBar.showKeyboardShortcutsMenu();
+                mBar.toggleKeyboardShortcutsMenu();
             } catch (RemoteException ex) {}
         }
     }
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index b49641f..751f871 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -16,6 +16,7 @@
 
 package com.android.server.wm;
 
+import static android.app.ActivityManager.StackId;
 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
@@ -24,12 +25,14 @@
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
 import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
 import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
+import static com.android.server.wm.WindowManagerService.WINDOW_REPLACEMENT_TIMEOUT_DURATION;
 
 import com.android.server.input.InputApplicationHandle;
 import com.android.server.wm.WindowManagerService.H;
 
 import android.annotation.NonNull;
 import android.content.pm.ActivityInfo;
+import android.graphics.Rect;
 import android.os.Message;
 import android.os.RemoteException;
 import android.util.Slog;
@@ -38,6 +41,7 @@
 import android.view.WindowManager;
 
 import java.io.PrintWriter;
+import java.util.ArrayDeque;
 import java.util.ArrayList;
 
 class AppTokenList extends ArrayList<AppWindowToken> {
@@ -123,6 +127,10 @@
     // True if the windows associated with this token should be cropped to their stack bounds.
     boolean mCropWindowsToStack;
 
+    boolean mAlwaysFocusable;
+
+    ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
+
     AppWindowToken(WindowManagerService _service, IApplicationToken _token,
             boolean _voiceInteraction) {
         super(_service, _token.asBinder(),
@@ -256,8 +264,8 @@
         return candidate;
     }
 
-    boolean stackCanReceiveKeys() {
-        return (windows.size() > 0) ? windows.get(windows.size() - 1).stackCanReceiveKeys() : false;
+    boolean windowsAreFocusable() {
+        return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable;
     }
 
     boolean isVisible() {
@@ -396,12 +404,28 @@
         }
     }
 
+    void resetReplacingWindows() {
+        if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Resetting app token " + appWindowToken
+                + " of replacing window marks.");
+
+        for (int i = allAppWindows.size() - 1; i >= 0; i--) {
+            final WindowState w = allAppWindows.get(i);
+            w.resetReplacing();
+        }
+    }
+
     void addWindow(WindowState w) {
         for (int i = allAppWindows.size() - 1; i >= 0; i--) {
             WindowState candidate = allAppWindows.get(i);
             if (candidate.mWillReplaceWindow && candidate.mReplacingWindow == null &&
                     candidate.getWindowTag().equals(w.getWindowTag().toString())) {
                 candidate.mReplacingWindow = w;
+
+                // if we got a replacement window, reset the timeout to give drawing more time
+                service.mH.removeMessages(H.WINDOW_REPLACEMENT_TIMEOUT);
+                service.mH.sendMessageDelayed(
+                        service.mH.obtainMessage(H.WINDOW_REPLACEMENT_TIMEOUT, this),
+                            WINDOW_REPLACEMENT_TIMEOUT_DURATION);
             }
         }
         allAppWindows.add(w);
@@ -417,7 +441,7 @@
         return false;
     }
 
-    void clearTimedoutReplaceesLocked() {
+    void clearTimedoutReplacesLocked() {
         for (int i = allAppWindows.size() - 1; i >= 0;
              // removeWindowLocked at bottom of loop may remove multiple entries from
              // allAppWindows if the window to be removed has child windows. It also may
@@ -430,10 +454,31 @@
                 continue;
             }
             candidate.mWillReplaceWindow = false;
-            service.removeWindowLocked(candidate);
+            // Since the window already timed out, remove it immediately now.
+            // Use removeWindowInnerLocked() instead of removeWindowLocked(), as the latter
+            // delays removal on certain conditions, which will leave the stale window in the
+            // stack and marked mWillReplaceWindow=false, so the window will never be removed.
+            service.removeWindowInnerLocked(candidate);
         }
     }
 
+    /**
+     * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
+     * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
+     * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
+     * with a queue.
+     */
+    void freezeBounds() {
+        mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds));
+    }
+
+    /**
+     * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
+     */
+    void unfreezeBounds() {
+        mFrozenBounds.remove();
+    }
+
     @Override
     void dump(PrintWriter pw, String prefix) {
         super.dump(pw, prefix);
@@ -480,6 +525,9 @@
                     pw.print(" startingDisplayed="); pw.print(startingDisplayed);
                     pw.print(" startingMoved"); pw.println(startingMoved);
         }
+        if (!mFrozenBounds.isEmpty()) {
+            pw.print(prefix); pw.print("mFrozenBounds="); pw.print(mFrozenBounds);
+        }
     }
 
     @Override
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index 5942198..51787b0 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -570,38 +570,19 @@
             pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
             pw.print(subPrefix); pw.print("deferred="); pw.print(mDeferredRemoval);
                 pw.print(" layoutNeeded="); pw.println(layoutNeeded);
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final TaskStack stack = mStacks.get(stackNdx);
-            pw.print(prefix); pw.print("mStacks[" + stackNdx + "]"); pw.println(stack.mStackId);
-            stack.dump(prefix + "  ", pw);
-        }
+
         pw.println();
         pw.println("  Application tokens in top down Z order:");
-        int ndx = 0;
         for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
             final TaskStack stack = mStacks.get(stackNdx);
-            pw.print("  mStackId="); pw.println(stack.mStackId);
-            ArrayList<Task> tasks = stack.getTasks();
-            for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
-                final Task task = tasks.get(taskNdx);
-                pw.print("    mTaskId="); pw.println(task.mTaskId);
-                AppTokenList tokens = task.mAppTokens;
-                for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx, ++ndx) {
-                    final AppWindowToken wtoken = tokens.get(tokenNdx);
-                    pw.print("    Activity #"); pw.print(tokenNdx);
-                            pw.print(' '); pw.print(wtoken); pw.println(":");
-                    wtoken.dump(pw, "      ");
-                }
-            }
+            stack.dump(prefix + "  ", pw);
         }
-        if (ndx == 0) {
-            pw.println("    None");
-        }
+
         pw.println();
         if (!mExitingTokens.isEmpty()) {
             pw.println();
             pw.println("  Exiting tokens:");
-            for (int i=mExitingTokens.size()-1; i>=0; i--) {
+            for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
                 WindowToken token = mExitingTokens.get(i);
                 pw.print("  Exiting #"); pw.print(i);
                 pw.print(' '); pw.print(token);
diff --git a/services/core/java/com/android/server/wm/DockedStackDividerController.java b/services/core/java/com/android/server/wm/DockedStackDividerController.java
index 8f3d3e3..7295318 100644
--- a/services/core/java/com/android/server/wm/DockedStackDividerController.java
+++ b/services/core/java/com/android/server/wm/DockedStackDividerController.java
@@ -18,11 +18,17 @@
 
 import android.content.Context;
 import android.graphics.Rect;
+import android.os.RemoteCallbackList;
 import android.os.RemoteException;
 import android.util.Slog;
-import android.view.IDockDividerVisibilityListener;
+import android.view.DisplayInfo;
+import android.view.IDockedStackListener;
+import android.view.SurfaceControl;
+
+import com.android.server.wm.DimLayer.DimLayerUser;
 
 import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
+import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
 import static android.view.WindowManager.DOCKED_BOTTOM;
 import static android.view.WindowManager.DOCKED_LEFT;
 import static android.view.WindowManager.DOCKED_RIGHT;
@@ -33,7 +39,7 @@
 /**
  * Keeps information about the docked stack divider.
  */
-public class DockedStackDividerController {
+public class DockedStackDividerController implements DimLayerUser {
 
     private static final String TAG = TAG_WITH_CLASS_NAME ? "DockedStackDividerController" : TAG_WM;
 
@@ -44,9 +50,10 @@
     private WindowState mWindow;
     private final Rect mTmpRect = new Rect();
     private final Rect mLastRect = new Rect();
-    private IDockDividerVisibilityListener mListener;
     private boolean mLastVisibility = false;
-    private boolean mForceVisibilityReevaluation;
+    private final RemoteCallbackList<IDockedStackListener> mDockedStackListeners
+            = new RemoteCallbackList<>();
+    private final DimLayer mDimLayer;
 
     DockedStackDividerController(Context context, DisplayContent displayContent) {
         mDisplayContent = displayContent;
@@ -54,6 +61,7 @@
                 com.android.internal.R.dimen.docked_stack_divider_thickness);
         mDividerInsets = context.getResources().getDimensionPixelSize(
                 com.android.internal.R.dimen.docked_stack_divider_insets);
+        mDimLayer = new DimLayer(displayContent.mService, this, displayContent.getDisplayId());
     }
 
     boolean isResizing() {
@@ -83,15 +91,16 @@
             return;
         }
         mLastVisibility = visible;
-        if (mListener != null) {
-            try {
-                mListener.onDockDividerVisibilityChanged(visible);
-            } catch (RemoteException e) {
-                Slog.e(TAG, "visibility call failed: " + e);
-            }
+        notifyDockedDividerVisibilityChanged(visible);
+        if (!visible) {
+            setResizeDimLayer(false, INVALID_STACK_ID, 0f);
         }
     }
 
+    boolean wasVisible() {
+        return mLastVisibility;
+    }
+
     void positionDockedStackedDivider(Rect frame) {
         TaskStack stack = mDisplayContent.getDockedStackLocked();
         if (stack == null) {
@@ -127,11 +136,76 @@
         mLastRect.set(frame);
     }
 
-    public void registerDockDividerVisibilityListener(IDockDividerVisibilityListener listener) {
-        if (mListener != null && listener != null) {
-            throw new IllegalStateException("Dock divider visibility listener already set!");
+    void notifyDockedDividerVisibilityChanged(boolean visible) {
+        final int size = mDockedStackListeners.beginBroadcast();
+        for (int i = 0; i < size; ++i) {
+            final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
+            try {
+                listener.onDividerVisibilityChanged(visible);
+            } catch (RemoteException e) {
+                Slog.e(TAG_WM, "Error delivering divider visibility changed event.", e);
+            }
         }
-        mListener = listener;
-        reevaluateVisibility(true);
+        mDockedStackListeners.finishBroadcast();
+    }
+
+    void notifyDockedStackExistsChanged(boolean exists) {
+        final int size = mDockedStackListeners.beginBroadcast();
+        for (int i = 0; i < size; ++i) {
+            final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i);
+            try {
+                listener.onDockedStackExistsChanged(exists);
+            } catch (RemoteException e) {
+                Slog.e(TAG_WM, "Error delivering docked stack exists changed event.", e);
+            }
+        }
+        mDockedStackListeners.finishBroadcast();
+    }
+
+    void registerDockedStackListener(IDockedStackListener listener) {
+        mDockedStackListeners.register(listener);
+        notifyDockedDividerVisibilityChanged(wasVisible());
+        notifyDockedStackExistsChanged(
+                mDisplayContent.mService.mStackIdToStack.get(DOCKED_STACK_ID) != null);
+    }
+
+    void setResizeDimLayer(boolean visible, int targetStackId, float alpha) {
+        SurfaceControl.openTransaction();
+        TaskStack stack = mDisplayContent.mService.mStackIdToStack.get(targetStackId);
+        boolean visibleAndValid = visible && stack != null;
+        if (visibleAndValid) {
+            stack.getDimBounds(mTmpRect);
+            if (mTmpRect.height() > 0 && mTmpRect.width() > 0) {
+                mDimLayer.setBounds(mTmpRect);
+                mDimLayer.show(mDisplayContent.mService.mLayersController.getResizeDimLayer(),
+                        alpha, 0 /* duration */);
+            } else {
+                visibleAndValid = false;
+            }
+        }
+        if (!visibleAndValid) {
+            mDimLayer.hide();
+        }
+        SurfaceControl.closeTransaction();
+    }
+
+    @Override
+    public boolean isFullscreen() {
+        return false;
+    }
+
+    @Override
+    public DisplayInfo getDisplayInfo() {
+        return mDisplayContent.getDisplayInfo();
+    }
+
+    @Override
+    public void getDimBounds(Rect outBounds) {
+        // This dim layer user doesn't need this.
+    }
+
+    @Override
+    public String toShortString() {
+        return TAG;
     }
 }
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 27e7a31..72970f6 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -61,6 +61,10 @@
 
     // Content limits relative to the DisplayContent this sits in.
     private Rect mBounds = new Rect();
+    final Rect mPreparedFrozenBounds = new Rect();
+
+    // Bounds used to calculate the insets.
+    private final Rect mTempInsetBounds = new Rect();
 
     // Device rotation as of the last time {@link #mBounds} was set.
     int mRotation;
@@ -197,8 +201,7 @@
     boolean removeAppToken(AppWindowToken wtoken) {
         boolean removed = mAppTokens.remove(wtoken);
         if (mAppTokens.size() == 0) {
-            EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId,
-                    "removeAppToken: last token");
+            EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeAppToken: last token");
             if (mDeferRemoval) {
                 removeLocked();
             }
@@ -267,6 +270,26 @@
         return boundsChange;
     }
 
+    /**
+     * Sets the bounds used to calculate the insets. See
+     * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
+     */
+    void setTempInsetBounds(Rect tempInsetBounds) {
+        if (tempInsetBounds != null) {
+            mTempInsetBounds.set(tempInsetBounds);
+        } else {
+            mTempInsetBounds.setEmpty();
+        }
+    }
+
+    /**
+     * Gets the bounds used to calculate the insets. See
+     * {@link android.app.IActivityManager#resizeDockedStack} why this is needed.
+     */
+    void getTempInsetBounds(Rect out) {
+        out.set(mTempInsetBounds);
+    }
+
     void setResizeable(boolean resizeable) {
         mResizeable = resizeable;
     }
@@ -291,6 +314,14 @@
         return true;
     }
 
+    /**
+     * Prepares the task bounds to be frozen with the current size. See
+     * {@link AppWindowToken#freezeBounds}.
+     */
+    void prepareFreezingBounds() {
+        mPreparedFrozenBounds.set(mBounds);
+    }
+
     boolean scrollLocked(Rect bounds) {
         // shift the task bound if it doesn't fully cover the stack area
         mStack.getDimBounds(mTmpRect);
@@ -357,7 +388,6 @@
         mStack.getDisplayContent().getLogicalDisplayRect(out);
     }
 
-
     /**
      * Calculate the maximum visible area of this task. If the task has only one app,
      * the result will be visible frame of that app. If the task has more than one apps,
@@ -573,11 +603,23 @@
         return "Task=" + mTaskId;
     }
 
-    public void printTo(String prefix, PrintWriter pw) {
-        pw.print(prefix); pw.print("taskId="); pw.println(mTaskId);
-            pw.print(prefix + prefix); pw.print("mFullscreen="); pw.println(mFullscreen);
-            pw.print(prefix + prefix); pw.print("mBounds="); pw.println(mBounds.toShortString());
-            pw.print(prefix + prefix); pw.print("mdr="); pw.println(mDeferRemoval);
-            pw.print(prefix + prefix); pw.print("appTokens="); pw.println(mAppTokens);
+    public void dump(String prefix, PrintWriter pw) {
+        final String doublePrefix = prefix + "  ";
+
+        pw.println(prefix + "taskId=" + mTaskId);
+        pw.println(doublePrefix + "mFullscreen=" + mFullscreen);
+        pw.println(doublePrefix + "mBounds=" + mBounds.toShortString());
+        pw.println(doublePrefix + "mdr=" + mDeferRemoval);
+        pw.println(doublePrefix + "appTokens=" + mAppTokens);
+        pw.println(doublePrefix + "mTempInsetBounds=" + mTempInsetBounds.toShortString());
+
+        final String triplePrefix = doublePrefix + "  ";
+
+        for (int i = mAppTokens.size() - 1; i >= 0; i--) {
+            final AppWindowToken wtoken = mAppTokens.get(i);
+            pw.println(triplePrefix + "Activity #" + i + " " + wtoken);
+            wtoken.dump(pw, triplePrefix);
+        }
+
     }
 }
diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java
index b961879..fc6ad70 100644
--- a/services/core/java/com/android/server/wm/TaskStack.java
+++ b/services/core/java/com/android/server/wm/TaskStack.java
@@ -114,7 +114,8 @@
      * @return True if the stack bounds was changed.
      * */
     boolean setBounds(
-            Rect stackBounds, SparseArray<Configuration> configs, SparseArray<Rect> taskBounds) {
+            Rect stackBounds, SparseArray<Configuration> configs, SparseArray<Rect> taskBounds,
+            SparseArray<Rect> taskTempInsetBounds) {
         if (!setBounds(stackBounds)) {
             return false;
         }
@@ -136,6 +137,9 @@
                     task.scrollLocked(mTmpRect);
                 } else {
                     task.setBounds(bounds, config);
+                    task.setTempInsetBounds(
+                            taskTempInsetBounds != null ? taskTempInsetBounds.get(task.mTaskId)
+                                    : null);
                 }
             } else {
                 Slog.wtf(TAG_WM, "No config for task: " + task + ", is there a mismatch with AM?");
@@ -144,6 +148,13 @@
         return true;
     }
 
+    void prepareFreezingTaskBounds() {
+        for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) {
+            final Task task = mTasks.get(taskNdx);
+            task.prepareFreezingBounds();
+        }
+    }
+
     boolean isFullscreenBounds(Rect bounds) {
         if (mDisplayContent == null || bounds == null) {
             return true;
@@ -608,16 +619,15 @@
     }
 
     public void dump(String prefix, PrintWriter pw) {
-        pw.print(prefix); pw.print("mStackId="); pw.println(mStackId);
-        pw.print(prefix); pw.print("mDeferDetach="); pw.println(mDeferDetach);
-        pw.print(prefix); pw.print("mFullscreen="); pw.println(mFullscreen);
-        pw.print(prefix); pw.print("mBounds="); pw.println(mBounds.toShortString());
-        for (int taskNdx = 0; taskNdx < mTasks.size(); ++taskNdx) {
-            pw.print(prefix);
-            mTasks.get(taskNdx).printTo(prefix + " ", pw);
+        pw.println(prefix + "mStackId=" + mStackId);
+        pw.println(prefix + "mDeferDetach=" + mDeferDetach);
+        pw.println(prefix + "mFullscreen=" + mFullscreen);
+        pw.println(prefix + "mBounds=" + mBounds.toShortString());
+        for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; taskNdx--) {
+            mTasks.get(taskNdx).dump(prefix + "  ", pw);
         }
         if (mAnimationBackgroundSurface.isDimming()) {
-            pw.print(prefix); pw.println("mWindowAnimationBackgroundSurface:");
+            pw.println(prefix + "mWindowAnimationBackgroundSurface:");
             mAnimationBackgroundSurface.printTo(prefix + "  ", pw);
         }
         if (!mExitingAppTokens.isEmpty()) {
diff --git a/services/core/java/com/android/server/wm/WindowLayersController.java b/services/core/java/com/android/server/wm/WindowLayersController.java
index 263b411..2cf2618 100644
--- a/services/core/java/com/android/server/wm/WindowLayersController.java
+++ b/services/core/java/com/android/server/wm/WindowLayersController.java
@@ -1,9 +1,20 @@
-package com.android.server.wm;
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
-import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
-import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
-import static com.android.server.wm.WindowManagerService.WINDOW_LAYER_MULTIPLIER;
+package com.android.server.wm;
 
 import android.app.ActivityManager.StackId;
 import android.util.Slog;
@@ -11,6 +22,11 @@
 
 import java.io.PrintWriter;
 
+import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
+import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
+import static com.android.server.wm.WindowManagerService.WINDOW_LAYER_MULTIPLIER;
+
 /**
  * Controller for assigning layers to windows on the display.
  *
@@ -42,7 +58,6 @@
     private WindowState mPinnedWindow = null;
     private WindowState mDockedWindow = null;
     private WindowState mDockDivider = null;
-    private WindowState mImeWindow = null;
     private WindowState mReplacingWindow = null;
 
     final void assignLayersLocked(WindowList windows) {
@@ -133,6 +148,14 @@
         return 0;
     }
 
+    /**
+     * @return The layer used for dimming the apps when dismissing docked/fullscreen stack. Just
+     *         above all application surfaces.
+     */
+    int getResizeDimLayer() {
+        return mDockDivider.mLayer - 1;
+    }
+
     private void logDebugLayers(WindowList windows) {
         for (int i = 0, n = windows.size(); i < n; i++) {
             final WindowState w = windows.get(i);
@@ -146,16 +169,13 @@
 
     private void clear() {
         mHighestApplicationLayer = 0;
-        mImeWindow = null;
         mPinnedWindow = null;
         mDockedWindow = null;
         mDockDivider = null;
     }
 
     private void collectSpecialWindows(WindowState w) {
-        if (w.mIsImWindow) {
-            mImeWindow = w;
-        } else if (w.mAttrs.type == TYPE_DOCK_DIVIDER) {
+        if (w.mAttrs.type == TYPE_DOCK_DIVIDER) {
             mDockDivider = w;
         } else {
             final TaskStack stack = w.getStack();
@@ -175,18 +195,17 @@
         // For pinned and docked stack window, we want to make them above other windows
         // also when these windows are animating.
         layer = assignAndIncreaseLayerIfNeeded(mDockedWindow, layer);
+
+        // Leave some space here so the dim layer while dismissing docked/fullscreen stack has space
+        // below the divider but above the app windows. It needs to be below the divider in because
+        // the divider sometimes overlaps the app windows.
+        layer++;
         layer = assignAndIncreaseLayerIfNeeded(mDockDivider, layer);
         // We know that we will be animating a relaunching window in the near future,
         // which will receive a z-order increase. We want the replaced window to
         // immediately receive the same treatment, e.g. to be above the dock divider.
         layer = assignAndIncreaseLayerIfNeeded(mReplacingWindow, layer);
         layer = assignAndIncreaseLayerIfNeeded(mPinnedWindow, layer);
-        final WindowState inputMethodTarget = mService.mInputMethodTarget;
-        // There might be no applications windows yet, so we need to make sure we uplift the input
-        // method above the target.
-        layer = Math.max(layer,
-                inputMethodTarget != null ? inputMethodTarget.mWinAnimator.mAnimLayer + 1 : 0);
-        layer = assignAndIncreaseLayerIfNeeded(mImeWindow, layer);
     }
 
     private int assignAndIncreaseLayerIfNeeded(WindowState win, int layer) {
diff --git a/services/core/java/com/android/server/wm/WindowManagerDebugConfig.java b/services/core/java/com/android/server/wm/WindowManagerDebugConfig.java
index 845100d..4c3a422 100644
--- a/services/core/java/com/android/server/wm/WindowManagerDebugConfig.java
+++ b/services/core/java/com/android/server/wm/WindowManagerDebugConfig.java
@@ -35,7 +35,7 @@
 
     static final boolean DEBUG_RESIZE = false;
     static final boolean DEBUG = false;
-    static final boolean DEBUG_ADD_REMOVE = false;
+    static final boolean DEBUG_ADD_REMOVE = true;
     static final boolean DEBUG_FOCUS = true;
     static final boolean DEBUG_FOCUS_LIGHT = DEBUG_FOCUS || false;
     static final boolean DEBUG_ANIM = false;
@@ -50,8 +50,8 @@
     static final boolean DEBUG_ORIENTATION = false;
     static final boolean DEBUG_APP_ORIENTATION = false;
     static final boolean DEBUG_CONFIGURATION = false;
-    static final boolean DEBUG_APP_TRANSITIONS = false;
-    static final boolean DEBUG_STARTING_WINDOW = false;
+    static final boolean DEBUG_APP_TRANSITIONS = true;
+    static final boolean DEBUG_STARTING_WINDOW = true;
     static final boolean DEBUG_WALLPAPER = false;
     static final boolean DEBUG_WALLPAPER_LIGHT = false || DEBUG_WALLPAPER;
     static final boolean DEBUG_DRAG = false;
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 48bcb1f..45e28e1 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -16,81 +16,11 @@
 
 package com.android.server.wm;
 
-import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT;
-import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
-import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
-import static android.app.StatusBarManager.DISABLE_MASK;
-import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
-import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
-import static android.view.WindowManager.DOCKED_INVALID;
-import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
-import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
-import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
-import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
-import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
-import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
-import static android.view.WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
-import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
-import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
-import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
-import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
-import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
-import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
-import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
-import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
-import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
-import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
-import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
-import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
-import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
-import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
-import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG;
-import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
-import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
-import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
-import static android.view.WindowManagerGlobal.RELAYOUT_DEFER_SURFACE_DESTROY;
-import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
-import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
-import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_END;
-import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_START;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_ORIENTATION;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEYGUARD;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
-import static com.android.server.wm.WindowManagerDebugConfig.HIDE_STACK_CRAWLS;
-import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
-import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
-import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
-import static com.android.server.wm.WindowManagerDebugConfig.SHOW_VERBOSE_TRANSACTIONS;
-import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
-
 import android.Manifest;
 import android.animation.ValueAnimator;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
+import android.app.ActivityManager.StackId;
 import android.app.ActivityManagerNative;
 import android.app.AppOpsManager;
 import android.app.IActivityManager;
@@ -127,6 +57,7 @@
 import android.os.PowerManager;
 import android.os.PowerManagerInternal;
 import android.os.Process;
+import android.os.RemoteCallbackList;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.StrictMode;
@@ -154,7 +85,7 @@
 import android.view.Gravity;
 import android.view.IAppTransitionAnimationSpecsFuture;
 import android.view.IApplicationToken;
-import android.view.IDockDividerVisibilityListener;
+import android.view.IDockedStackListener;
 import android.view.IInputFilter;
 import android.view.IOnKeyguardExitResult;
 import android.view.IRotationWatcher;
@@ -224,9 +155,83 @@
 import java.util.Iterator;
 import java.util.List;
 
+import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT;
+import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
+import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
+import static android.app.StatusBarManager.DISABLE_MASK;
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+import static android.view.WindowManager.DOCKED_INVALID;
+import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
+import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
+import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
+import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
+import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
+import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
+import static android.view.WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
+import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
+import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
+import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
+import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
+import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
+import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
+import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
+import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
+import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
+import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
+import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
+import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
+import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
+import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
+import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG;
+import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
+import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
+import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
+import static android.view.WindowManagerGlobal.RELAYOUT_DEFER_SURFACE_DESTROY;
+import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
+import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
+import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_END;
+import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_START;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_ORIENTATION;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEYGUARD;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
+import static com.android.server.wm.WindowManagerDebugConfig.HIDE_STACK_CRAWLS;
+import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
+import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
+import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
+import static com.android.server.wm.WindowManagerDebugConfig.SHOW_VERBOSE_TRANSACTIONS;
+import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
+import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
+
 /** {@hide} */
 public class WindowManagerService extends IWindowManager.Stub
         implements Watchdog.Monitor, WindowManagerPolicy.WindowManagerFuncs {
+    private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowManagerService" : TAG_WM;
+
     static final int LAYOUT_REPEAT_THRESHOLD = 4;
 
     static final boolean PROFILE_ORIENTATION = false;
@@ -573,31 +578,23 @@
     final ArrayList<WindowState> mTmpWindows = new ArrayList<>();
 
     boolean mHardKeyboardAvailable;
-    boolean mShowImeWithHardKeyboard;
     WindowManagerInternal.OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener;
     SettingsObserver mSettingsObserver;
 
     private final class SettingsObserver extends ContentObserver {
-        private final Uri mShowImeWithHardKeyboardUri =
-                Settings.Secure.getUriFor(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD);
-
         private final Uri mDisplayInversionEnabledUri =
                 Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);
 
         public SettingsObserver() {
             super(new Handler());
             ContentResolver resolver = mContext.getContentResolver();
-            resolver.registerContentObserver(mShowImeWithHardKeyboardUri, false, this,
-                    UserHandle.USER_ALL);
             resolver.registerContentObserver(mDisplayInversionEnabledUri, false, this,
                     UserHandle.USER_ALL);
         }
 
         @Override
         public void onChange(boolean selfChange, Uri uri) {
-            if (mShowImeWithHardKeyboardUri.equals(uri)) {
-                updateShowImeWithHardKeyboard();
-            } else if (mDisplayInversionEnabledUri.equals(uri)) {
+            if (mDisplayInversionEnabledUri.equals(uri)) {
                 updateCircularDisplayMaskIfNeeded();
             }
         }
@@ -941,7 +938,6 @@
         mContext.registerReceiver(mBroadcastReceiver, filter);
 
         mSettingsObserver = new SettingsObserver();
-        updateShowImeWithHardKeyboard();
 
         mHoldingScreenWakeLock = mPowerManager.newWakeLock(
                 PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG_WM);
@@ -2425,13 +2421,17 @@
         }
     }
 
-    void setInsetsWindow(Session session, IWindow client,
-            int touchableInsets, Rect contentInsets,
+    void setInsetsWindow(Session session, IWindow client, int touchableInsets, Rect contentInsets,
             Rect visibleInsets, Region touchableRegion) {
         long origId = Binder.clearCallingIdentity();
         try {
             synchronized (mWindowMap) {
                 WindowState w = windowForClientLocked(session, client, false);
+                if (DEBUG_LAYOUT) Slog.d(TAG, "setInsetsWindow " + w
+                        + ", contentInsets=" + w.mGivenContentInsets + " -> " + contentInsets
+                        + ", visibleInsets=" + w.mGivenVisibleInsets + " -> " + visibleInsets
+                        + ", touchableRegion=" + w.mGivenTouchableRegion + " -> " + touchableRegion
+                        + ", touchableInsets " + w.mTouchableInsets + " -> " + touchableInsets);
                 if (w != null) {
                     w.mGivenInsetsPending = false;
                     w.mGivenContentInsets.set(contentInsets);
@@ -3202,7 +3202,8 @@
     public void addAppToken(int addPos, IApplicationToken token, int taskId, int stackId,
             int requestedOrientation, boolean fullscreen, boolean showForAllUsers, int userId,
             int configChanges, boolean voiceInteraction, boolean launchTaskBehind,
-            Rect taskBounds, Configuration config, boolean cropWindowsToStack) {
+            Rect taskBounds, Configuration config, boolean cropWindowsToStack,
+            boolean alwaysFocusable) {
         if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
                 "addAppToken()")) {
             throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
@@ -3237,6 +3238,7 @@
                     (ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_ORIENTATION)) != 0;
             atoken.mLaunchTaskBehind = launchTaskBehind;
             atoken.mCropWindowsToStack = cropWindowsToStack;
+            atoken.mAlwaysFocusable = alwaysFocusable;
             if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "addAppToken: " + atoken
                     + " to stack=" + stackId + " task=" + taskId + " at " + addPos);
 
@@ -3466,6 +3468,7 @@
             // the value of the previous configuration.
             mTempConfiguration.setToDefaults();
             mTempConfiguration.fontScale = currentConfig.fontScale;
+            mTempConfiguration.uiMode = currentConfig.uiMode;
             computeScreenConfigurationLocked(mTempConfiguration);
             if (currentConfig.diff(mTempConfiguration) != 0) {
                 mWaitingForConfig = true;
@@ -3876,7 +3879,7 @@
             return false;
         }
         WindowState startingWindow = ttoken.startingWindow;
-        if (startingWindow != null) {
+        if (startingWindow != null && ttoken.startingView != null) {
             // In this case, the starting icon has already been displayed, so start
             // letting windows get shown immediately without any more transitions.
             mSkipAppTransitionAnimation = true;
@@ -4650,6 +4653,10 @@
                         if (DEBUG_STACK) Slog.d(TAG_WM, "attachStack: stackId=" + stackId);
                         stack = new TaskStack(this, stackId);
                         mStackIdToStack.put(stackId, stack);
+                        if (stackId == DOCKED_STACK_ID) {
+                            getDefaultDisplayContentLocked().mDividerControllerLocked
+                                    .notifyDockedStackExistsChanged(true);
+                        }
                     }
                     stack.attachDisplayContent(displayContent);
                     displayContent.attachStack(stack, onTop);
@@ -4675,6 +4682,10 @@
     void detachStackLocked(DisplayContent displayContent, TaskStack stack) {
         displayContent.detachStack(stack);
         stack.detachDisplay();
+        if (stack.mStackId == DOCKED_STACK_ID) {
+            getDefaultDisplayContentLocked().mDividerControllerLocked
+                    .notifyDockedStackExistsChanged(false);
+        }
     }
 
     public void detachStack(int stackId) {
@@ -4821,14 +4832,16 @@
      * @return True if the stack is now fullscreen.
      * */
     public boolean resizeStack(int stackId, Rect bounds,
-            SparseArray<Configuration> configs, SparseArray<Rect> taskBounds) {
+            SparseArray<Configuration> configs, SparseArray<Rect> taskBounds,
+            SparseArray<Rect> taskTempInsetBounds) {
         synchronized (mWindowMap) {
             final TaskStack stack = mStackIdToStack.get(stackId);
             if (stack == null) {
                 throw new IllegalArgumentException("resizeStack: stackId " + stackId
                         + " not found.");
             }
-            if (stack.setBounds(bounds, configs, taskBounds) && stack.isVisibleLocked()) {
+            if (stack.setBounds(bounds, configs, taskBounds, taskTempInsetBounds)
+                    && stack.isVisibleLocked()) {
                 stack.resizeWindows();
                 stack.getDisplayContent().layoutNeeded = true;
                 mWindowPlacerLocked.performSurfacePlacement();
@@ -4837,6 +4850,17 @@
         }
     }
 
+    public void prepareFreezingTaskBounds(int stackId) {
+        synchronized (mWindowMap) {
+            final TaskStack stack = mStackIdToStack.get(stackId);
+            if (stack == null) {
+                throw new IllegalArgumentException("prepareFreezingTaskBounds: stackId " + stackId
+                        + " not found.");
+            }
+            stack.prepareFreezingTaskBounds();
+        }
+    }
+
     public void positionTaskInStack(int taskId, int stackId, int position, Rect bounds,
             Configuration config) {
         synchronized (mWindowMap) {
@@ -6262,7 +6286,7 @@
         // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
         // By updating the Display info here it will be available to
         // computeScreenConfigurationLocked later.
-        updateDisplayAndOrientationLocked();
+        updateDisplayAndOrientationLocked(mCurConfiguration.uiMode);
 
         final DisplayInfo displayInfo = displayContent.getDisplayInfo();
         if (!inTransaction) {
@@ -6829,16 +6853,17 @@
         return config;
     }
 
-    private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, int dw, int dh) {
+    private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, int uiMode,
+            int dw, int dh) {
         // TODO: Multidisplay: for now only use with default display.
-        final int width = mPolicy.getConfigDisplayWidth(dw, dh, rotation);
+        final int width = mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode);
         if (width < displayInfo.smallestNominalAppWidth) {
             displayInfo.smallestNominalAppWidth = width;
         }
         if (width > displayInfo.largestNominalAppWidth) {
             displayInfo.largestNominalAppWidth = width;
         }
-        final int height = mPolicy.getConfigDisplayHeight(dw, dh, rotation);
+        final int height = mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode);
         if (height < displayInfo.smallestNominalAppHeight) {
             displayInfo.smallestNominalAppHeight = height;
         }
@@ -6848,11 +6873,11 @@
     }
 
     private int reduceConfigLayout(int curLayout, int rotation, float density,
-            int dw, int dh) {
+            int dw, int dh, int uiMode) {
         // TODO: Multidisplay: for now only use with default display.
         // Get the app screen size at this rotation.
-        int w = mPolicy.getNonDecorDisplayWidth(dw, dh, rotation);
-        int h = mPolicy.getNonDecorDisplayHeight(dw, dh, rotation);
+        int w = mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode);
+        int h = mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode);
 
         // Compute the screen layout size class for this rotation.
         int longSize = w;
@@ -6868,7 +6893,7 @@
     }
 
     private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated,
-                  int dw, int dh, float density, Configuration outConfig) {
+                  int uiMode, int dw, int dh, float density, Configuration outConfig) {
         // TODO: Multidisplay: for now only use with default display.
 
         // We need to determine the smallest width that will occur under normal
@@ -6887,24 +6912,24 @@
         displayInfo.smallestNominalAppHeight = 1<<30;
         displayInfo.largestNominalAppWidth = 0;
         displayInfo.largestNominalAppHeight = 0;
-        adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, unrotDw, unrotDh);
-        adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, unrotDh, unrotDw);
-        adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, unrotDw, unrotDh);
-        adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, unrotDh, unrotDw);
+        adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, uiMode, unrotDw, unrotDh);
+        adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, uiMode, unrotDh, unrotDw);
+        adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, uiMode, unrotDw, unrotDh);
+        adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, uiMode, unrotDh, unrotDw);
         int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
-        sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh);
-        sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw);
-        sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh);
-        sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw);
+        sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode);
+        sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode);
+        sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode);
+        sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode);
         outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
         outConfig.screenLayout = sl;
     }
 
-    private int reduceCompatConfigWidthSize(int curSize, int rotation, DisplayMetrics dm,
-            int dw, int dh) {
+    private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
+            DisplayMetrics dm, int dw, int dh) {
         // TODO: Multidisplay: for now only use with default display.
-        dm.noncompatWidthPixels = mPolicy.getNonDecorDisplayWidth(dw, dh, rotation);
-        dm.noncompatHeightPixels = mPolicy.getNonDecorDisplayHeight(dw, dh, rotation);
+        dm.noncompatWidthPixels = mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode);
+        dm.noncompatHeightPixels = mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode);
         float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
         int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
         if (curSize == 0 || size < curSize) {
@@ -6913,7 +6938,7 @@
         return curSize;
     }
 
-    private int computeCompatSmallestWidth(boolean rotated, DisplayMetrics dm, int dw, int dh) {
+    private int computeCompatSmallestWidth(boolean rotated, int uiMode, DisplayMetrics dm, int dw, int dh) {
         // TODO: Multidisplay: for now only use with default display.
         mTmpDisplayMetrics.setTo(dm);
         final DisplayMetrics tmpDm = mTmpDisplayMetrics;
@@ -6925,15 +6950,15 @@
             unrotDw = dw;
             unrotDh = dh;
         }
-        int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, tmpDm, unrotDw, unrotDh);
-        sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, tmpDm, unrotDh, unrotDw);
-        sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, tmpDm, unrotDw, unrotDh);
-        sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, tmpDm, unrotDh, unrotDw);
+        int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh);
+        sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw);
+        sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh);
+        sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw);
         return sw;
     }
 
     /** Do not call if mDisplayReady == false */
-    DisplayInfo updateDisplayAndOrientationLocked() {
+    DisplayInfo updateDisplayAndOrientationLocked(int uiMode) {
         // TODO(multidisplay): For now, apply Configuration to main screen only.
         final DisplayContent displayContent = getDefaultDisplayContentLocked();
 
@@ -6964,8 +6989,8 @@
         }
 
         // Update application display metrics.
-        final int appWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation);
-        final int appHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation);
+        final int appWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode);
+        final int appHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode);
         final DisplayInfo displayInfo = displayContent.getDisplayInfo();
         displayInfo.rotation = mRotation;
         displayInfo.logicalWidth = dw;
@@ -6997,20 +7022,24 @@
 
     /** Do not call if mDisplayReady == false */
     void computeScreenConfigurationLocked(Configuration config) {
-        final DisplayInfo displayInfo = updateDisplayAndOrientationLocked();
+        final DisplayInfo displayInfo = updateDisplayAndOrientationLocked(
+                config.uiMode);
 
         final int dw = displayInfo.logicalWidth;
         final int dh = displayInfo.logicalHeight;
         config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT :
                 Configuration.ORIENTATION_LANDSCAPE;
         config.screenWidthDp =
-                (int)(mPolicy.getConfigDisplayWidth(dw, dh, mRotation) / mDisplayMetrics.density);
+                (int)(mPolicy.getConfigDisplayWidth(dw, dh, mRotation, config.uiMode) /
+                        mDisplayMetrics.density);
         config.screenHeightDp =
-                (int)(mPolicy.getConfigDisplayHeight(dw, dh, mRotation) / mDisplayMetrics.density);
+                (int)(mPolicy.getConfigDisplayHeight(dw, dh, mRotation, config.uiMode) /
+                        mDisplayMetrics.density);
         final boolean rotated = (mRotation == Surface.ROTATION_90
                 || mRotation == Surface.ROTATION_270);
-        computeSizeRangesAndScreenLayout(displayInfo, rotated, dw, dh, mDisplayMetrics.density,
-                config);
+
+        computeSizeRangesAndScreenLayout(displayInfo, rotated, config.uiMode, dw, dh,
+                mDisplayMetrics.density, config);
 
         config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
                 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
@@ -7019,7 +7048,7 @@
 
         config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
         config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
-        config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated,
+        config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode,
                 mDisplayMetrics, dw, dh);
         config.densityDpi = displayInfo.logicalDensityDpi;
 
@@ -7078,9 +7107,6 @@
             mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
             mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
         }
-        if (mShowImeWithHardKeyboard) {
-            config.keyboard = Configuration.KEYBOARD_NOKEYS;
-        }
 
         // Let the policy update hidden states.
         config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
@@ -7089,18 +7115,6 @@
         mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
     }
 
-    public void updateShowImeWithHardKeyboard() {
-        synchronized (mWindowMap) {
-            final boolean showImeWithHardKeyboard = Settings.Secure.getIntForUser(
-                    mContext.getContentResolver(), Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0,
-                    mCurrentUserId) == 1;
-            if (mShowImeWithHardKeyboard != showImeWithHardKeyboard) {
-                mShowImeWithHardKeyboard = showImeWithHardKeyboard;
-                mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
-            }
-        }
-    }
-
     void notifyHardKeyboardStatusChange() {
         final boolean available;
         final WindowManagerInternal.OnHardKeyboardStatusChangeListener listener;
@@ -8073,7 +8087,7 @@
                 case WINDOW_REPLACEMENT_TIMEOUT: {
                     final AppWindowToken token = (AppWindowToken) msg.obj;
                     synchronized (mWindowMap) {
-                        token.clearTimedoutReplaceesLocked();
+                        token.clearTimedoutReplacesLocked();
                     }
                 }
                 break;
@@ -8438,6 +8452,7 @@
         boolean configChanged = updateOrientationFromAppTokensLocked(false);
         mTempConfiguration.setToDefaults();
         mTempConfiguration.fontScale = mCurConfiguration.fontScale;
+        mTempConfiguration.uiMode = mCurConfiguration.uiMode;
         computeScreenConfigurationLocked(mTempConfiguration);
         configChanged |= mCurConfiguration.diff(mTempConfiguration) != 0;
 
@@ -9077,8 +9092,8 @@
                         if (wtoken == token) {
                             break;
                         }
-                        if (mFocusedApp == token && token.stackCanReceiveKeys()) {
-                            // Whoops, we are below the focused app whose stack can receive keys...
+                        if (mFocusedApp == token && token.windowsAreFocusable()) {
+                            // Whoops, we are below the focused app whose windows are focusable...
                             // No focus for you!!!
                             if (localLOGV || DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
                                     "findFocusedWindow: Reached focused app=" + mFocusedApp);
@@ -9463,6 +9478,32 @@
         }
     }
 
+    public void notifyAppRelaunching(IBinder token) {
+        synchronized (mWindowMap) {
+            AppWindowToken appWindow = findAppWindowToken(token);
+            if (canFreezeBounds(appWindow)) {
+                appWindow.freezeBounds();
+            }
+        }
+    }
+
+    public void notifyAppRelaunchingFinished(IBinder token) {
+        synchronized (mWindowMap) {
+            AppWindowToken appWindow = findAppWindowToken(token);
+            if (canFreezeBounds(appWindow)) {
+                appWindow.unfreezeBounds();
+            }
+        }
+    }
+
+    private boolean canFreezeBounds(AppWindowToken appWindow) {
+
+        // For freeform windows, we can't freeze the bounds at the moment because this would make
+        // the resizing unresponsive.
+        return appWindow != null && appWindow.mTask != null
+                && !appWindow.mTask.inFreeformWorkspace();
+    }
+
     void dumpPolicyLocked(PrintWriter pw, String[] args, boolean dumpAll) {
         pw.println("WINDOW MANAGER POLICY STATE (dumpsys window policy)");
         mPolicy.dump("    ", pw, args);
@@ -9731,6 +9772,10 @@
         if ("visible".equals(name) || "visible-apps".equals(name)) {
             final boolean appsOnly = "visible-apps".equals(name);
             synchronized(mWindowMap) {
+                if (appsOnly) {
+                    dumpDisplayContentsLocked(pw, true);
+                }
+
                 final int numDisplays = mDisplayContents.size();
                 for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
                     final WindowList windowList =
@@ -10127,16 +10172,40 @@
         synchronized (mWindowMap) {
             appWindowToken = findAppWindowToken(token);
             if (appWindowToken == null || !appWindowToken.isVisible()) {
-                Slog.w(TAG_WM, "Attempted to set replacing window on non-existing app token " + token);
+                Slog.w(TAG_WM, "Attempted to set replacing window on non-existing app token "
+                        + token);
                 return;
             }
             appWindowToken.setReplacingWindows(animate);
         }
+    }
 
-        if (appWindowToken != null) {
-            mH.removeMessages(H.WINDOW_REPLACEMENT_TIMEOUT);
-            mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_REPLACEMENT_TIMEOUT, appWindowToken),
-                    WINDOW_REPLACEMENT_TIMEOUT_DURATION);
+    /**
+     * If we're replacing the window, schedule a timer to clear the replaced window
+     * after a timeout, in case the replacing window is not coming.
+     *
+     * If we're not replacing the window, clear the replace window settings of the app.
+     *
+     * @param token Application token for the activity whose window might be replaced.
+     * @param replacing Whether the window is being replaced or not.
+     */
+    public void scheduleClearReplacingWindowIfNeeded(IBinder token, boolean replacing) {
+        AppWindowToken appWindowToken = null;
+        synchronized (mWindowMap) {
+            appWindowToken = findAppWindowToken(token);
+            if (appWindowToken == null) {
+                Slog.w(TAG_WM, "Attempted to reset replacing window on non-existing app token "
+                        + token);
+                return;
+            }
+            if (replacing) {
+                mH.removeMessages(H.WINDOW_REPLACEMENT_TIMEOUT);
+                mH.sendMessageDelayed(
+                        mH.obtainMessage(H.WINDOW_REPLACEMENT_TIMEOUT, appWindowToken),
+                        WINDOW_REPLACEMENT_TIMEOUT_DURATION);
+            } else {
+                appWindowToken.resetReplacingWindows();
+            }
         }
     }
 
@@ -10156,6 +10225,14 @@
         }
     }
 
+    @Override
+    public void setResizeDimLayer(boolean visible, int targetStackId, float alpha) {
+        synchronized (mWindowMap) {
+            getDefaultDisplayContentLocked().getDockedDividerController().setResizeDimLayer(
+                    visible, targetStackId, alpha);
+        }
+    }
+
     public void setTaskResizeable(int taskId, boolean resizeable) {
         synchronized (mWindowMap) {
             Task task = mTaskIdToTask.get(taskId);
@@ -10174,26 +10251,14 @@
     }
 
     @Override
-    public void registerDockDividerVisibilityListener(IDockDividerVisibilityListener listener) {
+    public void registerDockedStackListener(IDockedStackListener listener) {
         if (!checkCallingPermission(android.Manifest.permission.REGISTER_WINDOW_MANAGER_LISTENERS,
-                "registerDockDividerVisibilityListener()")) {
+                "registerDockedStackListener()")) {
             return;
         }
         // TODO(multi-display): The listener is registered on the default display only.
-        final DockedStackDividerController controller =
-                getDefaultDisplayContentLocked().getDockedDividerController();
-        controller.registerDockDividerVisibilityListener(listener);
-        try {
-            listener.asBinder().linkToDeath(new IBinder.DeathRecipient() {
-                @Override
-                public void binderDied() {
-                    getDefaultDisplayContentLocked().getDockedDividerController()
-                            .registerDockDividerVisibilityListener(null);
-                }
-            }, 0);
-        } catch (RemoteException e) {
-            controller.registerDockDividerVisibilityListener(null);
-        }
+        getDefaultDisplayContentLocked().mDividerControllerLocked.registerDockedStackListener(
+                listener);
     }
 
     private final class LocalService extends WindowManagerInternal {
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 733bc29..b7fd60f 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -309,6 +309,12 @@
     // possible to draw.
     final Rect mOutsetFrame = new Rect();
 
+    /**
+     * Usually empty. Set to the task's tempInsetFrame. See
+     *{@link android.app.IActivityManager#resizeDockedStack}.
+     */
+    final Rect mInsetFrame = new Rect();
+
     boolean mContentChanged;
 
     // If a window showing a wallpaper: the requested offset for the
@@ -614,8 +620,18 @@
             // We use the parent frame as the containing frame for fullscreen and child windows
             mContainingFrame.set(pf);
             mDisplayFrame.set(df);
+            mInsetFrame.setEmpty();
         } else {
             task.getBounds(mContainingFrame);
+            task.getTempInsetBounds(mInsetFrame);
+            if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
+
+                // If the bounds are frozen, we still want to translate the window freely and only
+                // freeze the size.
+                Rect frozen = mAppToken.mFrozenBounds.peek();
+                mContainingFrame.right = mContainingFrame.left + frozen.width();
+                mContainingFrame.bottom = mContainingFrame.top + frozen.height();
+            }
             final WindowState imeWin = mService.mInputMethodWindow;
             if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
                     && mContainingFrame.bottom > cf.bottom) {
@@ -674,6 +690,12 @@
             mOutsets.set(0, 0, 0, 0);
         }
 
+        // Denotes the actual frame used to calculate the insets. When resizing in docked mode,
+        // we'd like to freeze the layout, so we also need to freeze the insets temporarily. By the
+        // notion of a task having a different inset frame, we can achieve that while still moving
+        // the task around.
+        final Rect frame = !mInsetFrame.isEmpty() ? mInsetFrame : mFrame;
+
         // Make sure the content and visible frames are inside of the
         // final window frame.
         if (freeformWorkspace && !mFrame.isEmpty()) {
@@ -709,42 +731,69 @@
                 mContentFrame.set(mFrame);
             }
         } else {
-            mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
-                    Math.max(mContentFrame.top, mFrame.top),
-                    Math.min(mContentFrame.right, mFrame.right),
-                    Math.min(mContentFrame.bottom, mFrame.bottom));
+            mContentFrame.set(Math.max(mContentFrame.left, frame.left),
+                    Math.max(mContentFrame.top, frame.top),
+                    Math.min(mContentFrame.right, frame.right),
+                    Math.min(mContentFrame.bottom, frame.bottom));
 
-            mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
-                    Math.max(mVisibleFrame.top, mFrame.top),
-                    Math.min(mVisibleFrame.right, mFrame.right),
-                    Math.min(mVisibleFrame.bottom, mFrame.bottom));
+            mVisibleFrame.set(Math.max(mVisibleFrame.left, frame.left),
+                    Math.max(mVisibleFrame.top, frame.top),
+                    Math.min(mVisibleFrame.right, frame.right),
+                    Math.min(mVisibleFrame.bottom, frame.bottom));
 
-            mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
-                    Math.max(mStableFrame.top, mFrame.top),
-                    Math.min(mStableFrame.right, mFrame.right),
-                    Math.min(mStableFrame.bottom, mFrame.bottom));
+            mStableFrame.set(Math.max(mStableFrame.left, frame.left),
+                    Math.max(mStableFrame.top, frame.top),
+                    Math.min(mStableFrame.right, frame.right),
+                    Math.min(mStableFrame.bottom, frame.bottom));
         }
 
-        mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
-                Math.max(mOverscanFrame.top - mFrame.top, 0),
-                Math.max(mFrame.right - mOverscanFrame.right, 0),
-                Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
+        mOverscanInsets.set(Math.max(mOverscanFrame.left - frame.left, 0),
+                Math.max(mOverscanFrame.top - frame.top, 0),
+                Math.max(frame.right - mOverscanFrame.right, 0),
+                Math.max(frame.bottom - mOverscanFrame.bottom, 0));
 
-        mContentInsets.set(mContentFrame.left - mFrame.left,
-                mContentFrame.top - mFrame.top,
-                mFrame.right - mContentFrame.right,
-                mFrame.bottom - mContentFrame.bottom);
+        mContentInsets.set(mContentFrame.left - frame.left,
+                mContentFrame.top - frame.top,
+                frame.right - mContentFrame.right,
+                frame.bottom - mContentFrame.bottom);
 
-        mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
-                mVisibleFrame.top - mFrame.top,
-                mFrame.right - mVisibleFrame.right,
-                mFrame.bottom - mVisibleFrame.bottom);
+        mVisibleInsets.set(mVisibleFrame.left - frame.left,
+                mVisibleFrame.top - frame.top,
+                frame.right - mVisibleFrame.right,
+                frame.bottom - mVisibleFrame.bottom);
 
-        mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
-                Math.max(mStableFrame.top - mFrame.top, 0),
-                Math.max(mFrame.right - mStableFrame.right, 0),
-                Math.max(mFrame.bottom - mStableFrame.bottom, 0));
+        if (mAttrs.type == TYPE_DOCK_DIVIDER) {
 
+            // For the docked divider, we calculate the stable insets like a full-screen window
+            // so it can use it to calculate the snap positions.
+            mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
+                    Math.max(mStableFrame.top - mDisplayFrame.top, 0),
+                    Math.max(mDisplayFrame.right - mStableFrame.right, 0),
+                    Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
+        } else {
+            mStableInsets.set(Math.max(mStableFrame.left - frame.left, 0),
+                    Math.max(mStableFrame.top - frame.top, 0),
+                    Math.max(frame.right - mStableFrame.right, 0),
+                    Math.max(frame.bottom - mStableFrame.bottom, 0));
+        }
+
+        if (!mInsetFrame.isEmpty()) {
+            mContentFrame.set(mFrame);
+            mContentFrame.top += mContentInsets.top;
+            mContentFrame.bottom += mContentInsets.bottom;
+            mContentFrame.left += mContentInsets.left;
+            mContentFrame.right += mContentInsets.right;
+            mVisibleFrame.set(mFrame);
+            mVisibleFrame.top += mVisibleInsets.top;
+            mVisibleFrame.bottom += mVisibleInsets.bottom;
+            mVisibleFrame.left += mVisibleInsets.left;
+            mVisibleFrame.right += mVisibleInsets.right;
+            mStableFrame.set(mFrame);
+            mStableFrame.top += mStableInsets.top;
+            mStableFrame.bottom += mStableInsets.bottom;
+            mStableFrame.left += mStableInsets.left;
+            mStableFrame.right += mStableInsets.right;
+        }
         mCompatFrame.set(mFrame);
         if (mEnforceSizeCompat) {
             // If there is a size compatibility scale being applied to the
@@ -1558,12 +1607,7 @@
         return isVisibleOrAdding()
                 && (mViewVisibility == View.VISIBLE)
                 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
-                && stackCanReceiveKeys();
-    }
-
-    boolean stackCanReceiveKeys() {
-        final TaskStack stack = getStack();
-        return stack != null && StackId.canReceiveKeys(stack.mStackId);
+                && (mAppToken == null || mAppToken.windowsAreFocusable());
     }
 
     @Override
@@ -1955,8 +1999,8 @@
         // isDragResizing() or isDragResizeChanged() is true.
         boolean resizing = isDragResizing() || isDragResizeChanged();
         final Rect backDropFrame = (inFreeformWorkspace() || !resizing) ? frame : mTmpRect;
-        mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
-                outsets, reportDraw, newConfig, backDropFrame);
+        mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
+                reportDraw, newConfig, backDropFrame);
     }
 
     public void registerFocusObserver(IWindowFocusObserver observer) {
@@ -2003,7 +2047,13 @@
         if (task.isDragResizing()) {
             return true;
         }
-        return mDisplayContent.mDividerControllerLocked.isResizing() &&
+
+        // If the bounds are currently frozen, it means that the layout size that the app sees
+        // and the bounds we clip this window to might be different. In order to avoid holes, we
+        // simulate that we are still resizing so the app fills the hole with the resizing
+        // background.
+        return (mDisplayContent.mDividerControllerLocked.isResizing()
+                        || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
                 !task.inFreeformWorkspace() && !task.isFullscreen();
     }
 
@@ -2302,10 +2352,21 @@
     }
 
     void setReplacing(boolean animate) {
-        if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) == 0) {
-            mWillReplaceWindow = true;
-            mReplacingWindow = null;
-            mAnimateReplacingWindow = animate;
+        if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
+                || mAttrs.type == TYPE_APPLICATION_STARTING) {
+            // We don't set replacing on starting windows since they are added by window manager and
+            // not the client so won't be replaced by the client.
+            return;
         }
+
+        mWillReplaceWindow = true;
+        mReplacingWindow = null;
+        mAnimateReplacingWindow = animate;
+    }
+
+    void resetReplacing() {
+        mWillReplaceWindow = false;
+        mReplacingWindow = null;
+        mAnimateReplacingWindow = false;
     }
 }
diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java
index 381db56..83ab190 100644
--- a/services/core/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java
@@ -37,6 +37,7 @@
 import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
 import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
 import static com.android.server.wm.WindowManagerService.localLOGV;
+import static com.android.server.wm.WindowState.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
 import static com.android.server.wm.WindowState.DRAG_RESIZE_MODE_FREEFORM;
 import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
 import static com.android.server.wm.WindowSurfacePlacer.SET_TURN_ON_SCREEN;
@@ -1063,7 +1064,16 @@
         final int top = w.mYOffset + w.mFrame.top;
 
         // Initialize the decor rect to the entire frame.
-        mSystemDecorRect.set(0, 0, width, height);
+        if (w.isDragResizing() && w.getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER) {
+
+            // If we are resizing with the divider, the task bounds might be smaller than the
+            // stack bounds. The system decor is used to clip to the task bounds, which we don't
+            // want in this case in order to avoid holes.
+            final DisplayInfo displayInfo = w.getDisplayContent().getDisplayInfo();
+            mSystemDecorRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
+        } else {
+            mSystemDecorRect.set(0, 0, width, height);
+        }
 
         // If a freeform window is animating from a position where it would be cutoff, it would be
         // cutoff during the animation. We don't want that, so for the duration of the animation
diff --git a/services/core/java/com/android/server/wm/WindowSurfacePlacer.java b/services/core/java/com/android/server/wm/WindowSurfacePlacer.java
index 6ebda07..f77e5a6 100644
--- a/services/core/java/com/android/server/wm/WindowSurfacePlacer.java
+++ b/services/core/java/com/android/server/wm/WindowSurfacePlacer.java
@@ -739,13 +739,15 @@
                             }
                         }
                     }
-                    /*
-                     * Updates the shown frame before we set up the surface. This is needed because
-                     * the resizing could change the top-left position (in addition to size) of the
-                     * window. setSurfaceBoundariesLocked uses mShownPosition to position the
-                      * surface.
-                     */
-                    winAnimator.computeShownFrameLocked();
+                    if (!winAnimator.isAnimating()) {
+                        // Updates the shown frame before we set up the surface. This is needed
+                        // because the resizing could change the top-left position (in addition to
+                        // size) of the window. setSurfaceBoundariesLocked uses mShownPosition to
+                        // position the surface. We only apply it to windows that aren't animating,
+                        // because we depend on the animation to calculate the correct shown frame
+                        // on the next animation step.
+                        winAnimator.computeShownFrameLocked();
+                    }
                     winAnimator.setSurfaceBoundariesLocked(recoveringMemory);
                 }
 
@@ -857,7 +859,8 @@
                     + displayContent.layoutNeeded + " dw=" + dw + " dh=" + dh);
         }
 
-        mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mService.mRotation);
+        mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mService.mRotation,
+                mService.mCurConfiguration.uiMode);
         if (isDefaultDisplay) {
             // Not needed on non-default displays.
             mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index cf661ce..dd58b3c 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -129,6 +129,7 @@
 import com.android.server.LocalServices;
 import com.android.server.SystemService;
 import com.android.server.devicepolicy.DevicePolicyManagerService.ActiveAdmin.TrustAgentInfo;
+import com.android.server.pm.UserManagerService;
 import com.android.server.pm.UserRestrictionsUtils;
 
 import org.xmlpull.v1.XmlPullParser;
@@ -424,6 +425,9 @@
         private static final String TAG_PACKAGE_LIST_ITEM  = "item";
         private static final String TAG_KEEP_UNINSTALLED_PACKAGES  = "keep-uninstalled-packages";
         private static final String TAG_USER_RESTRICTIONS = "user-restrictions";
+        private static final String TAG_SHORT_SUPPORT_MESSAGE = "short-support-message";
+        private static final String TAG_LONG_SUPPORT_MESSAGE = "long-support-message";
+        private static final String TAG_PARENT_ADMIN = "parent-admin";
 
         final DeviceAdminInfo info;
 
@@ -476,6 +480,9 @@
         boolean disableScreenCapture = false; // Can only be set by a device/profile owner.
         boolean requireAutoTime = false; // Can only be set by a device owner.
 
+        ActiveAdmin parentAdmin;
+        final boolean isParent;
+
         static class TrustAgentInfo {
             public PersistableBundle options;
             TrustAgentInfo(PersistableBundle bundle) {
@@ -509,8 +516,20 @@
 
         Bundle userRestrictions;
 
-        ActiveAdmin(DeviceAdminInfo _info) {
+        // Support text provided by the admin to display to the user.
+        String shortSupportMessage = null;
+        String longSupportMessage = null;
+
+        ActiveAdmin(DeviceAdminInfo _info, boolean parent) {
             info = _info;
+            isParent = parent;
+        }
+
+        ActiveAdmin getParentActiveAdmin() {
+            if (parentAdmin == null && !isParent) {
+                parentAdmin = new ActiveAdmin(info, /* parent */ true);
+            }
+            return parentAdmin;
         }
 
         int getUid() { return info.getActivityInfo().applicationInfo.uid; }
@@ -688,6 +707,21 @@
                 UserRestrictionsUtils.writeRestrictions(
                         out, userRestrictions, TAG_USER_RESTRICTIONS);
             }
+            if (!TextUtils.isEmpty(shortSupportMessage)) {
+                out.startTag(null, TAG_SHORT_SUPPORT_MESSAGE);
+                out.text(shortSupportMessage);
+                out.endTag(null, TAG_SHORT_SUPPORT_MESSAGE);
+            }
+            if (!TextUtils.isEmpty(longSupportMessage)) {
+                out.startTag(null, TAG_LONG_SUPPORT_MESSAGE);
+                out.text(longSupportMessage);
+                out.endTag(null, TAG_LONG_SUPPORT_MESSAGE);
+            }
+            if (parentAdmin != null) {
+                out.startTag(null, TAG_PARENT_ADMIN);
+                parentAdmin.writeToXml(out);
+                out.endTag(null, TAG_PARENT_ADMIN);
+            }
         }
 
         void writePackageListToXml(XmlSerializer out, String outerTag,
@@ -801,6 +835,23 @@
                     keepUninstalledPackages = readPackageList(parser, tag);
                 } else if (TAG_USER_RESTRICTIONS.equals(tag)) {
                     UserRestrictionsUtils.readRestrictions(parser, ensureUserRestrictions());
+                } else if (TAG_SHORT_SUPPORT_MESSAGE.equals(tag)) {
+                    type = parser.next();
+                    if (type == XmlPullParser.TEXT) {
+                        shortSupportMessage = parser.getText();
+                    } else {
+                        Log.w(LOG_TAG, "Missing text when loading short support message");
+                    }
+                } else if (TAG_LONG_SUPPORT_MESSAGE.equals(tag)) {
+                    type = parser.next();
+                    if (type == XmlPullParser.TEXT) {
+                        longSupportMessage = parser.getText();
+                    } else {
+                        Log.w(LOG_TAG, "Missing text when loading long support message");
+                    }
+                } else if (TAG_PARENT_ADMIN.equals(tag)) {
+                    parentAdmin = new ActiveAdmin(info, /* parent */ true);
+                    parentAdmin.readFromXml(parser);
                 } else {
                     Slog.w(LOG_TAG, "Unknown admin tag: " + tag);
                     XmlUtils.skipCurrentTag(parser);
@@ -1599,6 +1650,23 @@
         }
     }
 
+    /**
+     * Find the admin for the component and userId bit of the uid, then check
+     * the admin's uid matches the uid.
+     */
+    private ActiveAdmin getActiveAdminForUidLocked(ComponentName who, int uid) {
+        final int userId = UserHandle.getUserId(uid);
+        final DevicePolicyData policy = getUserData(userId);
+        ActiveAdmin admin = policy.mAdminMap.get(who);
+        if (admin == null) {
+            throw new SecurityException("No active admin " + who);
+        }
+        if (admin.getUid() != uid) {
+            throw new SecurityException("Admin " + who + " is not owned by uid " + uid);
+        }
+        return admin;
+    }
+
     private ActiveAdmin getActiveAdminWithPolicyForUidLocked(ComponentName who, int reqPolicy,
             int uid) {
         // Try to find an admin which can use reqPolicy
@@ -1610,8 +1678,7 @@
                 throw new SecurityException("No active admin " + who);
             }
             if (admin.getUid() != uid) {
-                throw new SecurityException("Admin " + who + " is not owned by uid "
-                        + mInjector.binderGetCallingUid());
+                throw new SecurityException("Admin " + who + " is not owned by uid " + uid);
             }
             if (isActiveAdminWithPolicyForUserLocked(admin, reqPolicy, userId)) {
                 return admin;
@@ -1744,7 +1811,7 @@
         enforceCrossUserPermission(userHandle);
         Intent resolveIntent = new Intent();
         resolveIntent.setComponent(adminName);
-        List<ResolveInfo> infos = mContext.getPackageManager().queryBroadcastReceivers(
+        List<ResolveInfo> infos = mContext.getPackageManager().queryBroadcastReceiversAsUser(
                 resolveIntent,
                 PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
                 userHandle);
@@ -1968,7 +2035,7 @@
                                     + userHandle);
                         }
                         if (dai != null) {
-                            ActiveAdmin ap = new ActiveAdmin(dai);
+                            ActiveAdmin ap = new ActiveAdmin(dai, /* parent */ false);
                             ap.readFromXml(parser);
                             policy.mAdminMap.put(ap.info.getComponent(), ap);
                         }
@@ -2359,7 +2426,7 @@
                         && getActiveAdminUncheckedLocked(adminReceiver, userHandle) != null) {
                     throw new IllegalArgumentException("Admin is already added");
                 }
-                ActiveAdmin newAdmin = new ActiveAdmin(info);
+                ActiveAdmin newAdmin = new ActiveAdmin(info, /* parent */ false);
                 policy.mAdminMap.put(adminReceiver, newAdmin);
                 int replaceIndex = -1;
                 final int N = policy.mAdminList.size();
@@ -2494,8 +2561,14 @@
         }
     }
 
+    private boolean isAdminApiLevelPreN(@NonNull ComponentName who, int userHandle) {
+        DeviceAdminInfo adminInfo = findAdmin(who, userHandle, false);
+        return adminInfo.getActivityInfo().applicationInfo.targetSdkVersion
+                < Build.VERSION_CODES.N;
+    }
+
     @Override
-    public void setPasswordQuality(ComponentName who, int quality) {
+    public void setPasswordQuality(ComponentName who, int quality, boolean parent) {
         if (!mHasFeature) {
             return;
         }
@@ -2506,6 +2579,9 @@
         synchronized (this) {
             ActiveAdmin ap = getActiveAdminForCallerLocked(who,
                     DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
+            if (parent) {
+                ap = ap.getParentActiveAdmin();
+            }
             if (ap.passwordQuality != quality) {
                 ap.passwordQuality = quality;
                 saveSettingsLocked(userHandle);
@@ -2514,7 +2590,7 @@
     }
 
     @Override
-    public int getPasswordQuality(ComponentName who, int userHandle) {
+    public int getPasswordQuality(ComponentName who, int userHandle, boolean parent) {
         if (!mHasFeature) {
             return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
         }
@@ -2524,20 +2600,43 @@
 
             if (who != null) {
                 ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                if (parent && admin != null) {
+                    admin = admin.getParentActiveAdmin();
+                }
                 return admin != null ? admin.passwordQuality : mode;
             }
 
-            // Return strictest policy for this user and profiles that are visible from this user.
-            List<UserInfo> profiles = mUserManager.getProfiles(userHandle);
-            for (UserInfo userInfo : profiles) {
-                DevicePolicyData policy = getUserDataUnchecked(userInfo.id);
+            if (LockPatternUtils.isSeparateWorkChallengeEnabled() && !parent) {
+                // If a Work Challenge is in use, only return its restrictions.
+                DevicePolicyData policy = getUserDataUnchecked(userHandle);
                 final int N = policy.mAdminList.size();
-                for (int i=0; i<N; i++) {
+                for (int i = 0; i < N; i++) {
                     ActiveAdmin admin = policy.mAdminList.get(i);
                     if (mode < admin.passwordQuality) {
                         mode = admin.passwordQuality;
                     }
                 }
+            } else {
+                // Return strictest policy for this user and profiles that are visible from this
+                // user that do not use a separate work challenge.
+                // TODO: When there are separate parent restrictions the profile should just
+                // obey its own.
+                List<UserInfo> profiles = mUserManager.getProfiles(userHandle);
+                for (UserInfo userInfo : profiles) {
+                    // Only aggregate data for the parent profile plus the non-work challenge
+                    // enabled profiles.
+                    if (!(userInfo.isManagedProfile()
+                            && LockPatternUtils.isSeparateWorkChallengeEnabled())) {
+                        DevicePolicyData policy = getUserDataUnchecked(userInfo.id);
+                        final int N = policy.mAdminList.size();
+                        for (int i = 0; i < N; i++) {
+                            ActiveAdmin admin = policy.mAdminList.get(i);
+                            if (mode < admin.passwordQuality) {
+                                mode = admin.passwordQuality;
+                            }
+                        }
+                    }
+                }
             }
             return mode;
         }
@@ -3097,7 +3196,7 @@
     }
 
     @Override
-    public boolean isActivePasswordSufficient(int userHandle) {
+    public boolean isActivePasswordSufficient(int userHandle, boolean parent) {
         if (!mHasFeature) {
             return true;
         }
@@ -3109,8 +3208,14 @@
 
             // This API can only be called by an active device admin,
             // so try to retrieve it to check that the caller is one.
-            getActiveAdminForCallerLocked(null, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
-            if (policy.mActivePasswordQuality < getPasswordQuality(null, userHandle)
+            ActiveAdmin admin =
+                    getActiveAdminForCallerLocked(null, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
+            ComponentName adminComponentName = admin.info.getComponent();
+            // TODO: Include the Admin sdk level check in LockPatternUtils check.
+            ComponentName who = !isAdminApiLevelPreN(adminComponentName, userHandle)
+                    && LockPatternUtils.isSeparateWorkChallengeEnabled()
+                        ? adminComponentName : null;
+            if (policy.mActivePasswordQuality < getPasswordQuality(who, userHandle, parent)
                     || policy.mActivePasswordLength < getPasswordMinimumLength(null, userHandle)) {
                 return false;
             }
@@ -3275,7 +3380,7 @@
                     }
                 }
             }
-            quality = getPasswordQuality(null, userHandle);
+            quality = getPasswordQuality(null, userHandle, false);
             if (quality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                 int realQuality = LockPatternUtils.computePasswordQuality(password);
                 if (realQuality < quality
@@ -3572,7 +3677,7 @@
             }
 
             try {
-                int uid = mContext.getPackageManager().getPackageUid(
+                int uid = mContext.getPackageManager().getPackageUidAsUser(
                         policy.mDelegatedCertInstallerPackage, userHandle);
                 return uid == callingUid;
             } catch (NameNotFoundException e) {
@@ -4732,7 +4837,7 @@
         Preconditions.checkNotNull(packageName, "packageName is null");
         final int callingUid = mInjector.binderGetCallingUid();
         try {
-            int uid = mContext.getPackageManager().getPackageUid(packageName, 0);
+            int uid = mContext.getPackageManager().getPackageUidAsUser(packageName, 0);
             if (uid != callingUid) {
                 throw new SecurityException("Invalid packageName");
             }
@@ -5241,7 +5346,7 @@
             }
 
             try {
-                int uid = mContext.getPackageManager().getPackageUid(
+                int uid = mContext.getPackageManager().getPackageUidAsUser(
                         policy.mApplicationRestrictionsManagingPackage, userHandle);
                 return uid == callingUid;
             } catch (NameNotFoundException e) {
@@ -7104,4 +7209,99 @@
         }
     }
 
+    @Override
+    public void setShortSupportMessage(@NonNull ComponentName who, String message) {
+        if (!mHasFeature) {
+            return;
+        }
+        Preconditions.checkNotNull(who, "ComponentName is null");
+        final int userHandle = mInjector.userHandleGetCallingUserId();
+        synchronized (this) {
+            ActiveAdmin admin = getActiveAdminForUidLocked(who,
+                    mInjector.binderGetCallingUid());
+            if (!TextUtils.equals(admin.shortSupportMessage, message)) {
+                admin.shortSupportMessage = message;
+                saveSettingsLocked(userHandle);
+            }
+        }
+    }
+
+    @Override
+    public String getShortSupportMessage(@NonNull ComponentName who) {
+        if (!mHasFeature) {
+            return null;
+        }
+        Preconditions.checkNotNull(who, "ComponentName is null");
+        synchronized (this) {
+            ActiveAdmin admin = getActiveAdminForUidLocked(who,
+                    mInjector.binderGetCallingUid());
+            return admin.shortSupportMessage;
+        }
+    }
+
+    @Override
+    public void setLongSupportMessage(@NonNull ComponentName who, String message) {
+        if (!mHasFeature) {
+            return;
+        }
+        Preconditions.checkNotNull(who, "ComponentName is null");
+        final int userHandle = mInjector.userHandleGetCallingUserId();
+        synchronized (this) {
+            ActiveAdmin admin = getActiveAdminForUidLocked(who,
+                    mInjector.binderGetCallingUid());
+            if (!TextUtils.equals(admin.longSupportMessage, message)) {
+                admin.longSupportMessage = message;
+                saveSettingsLocked(userHandle);
+            }
+        }
+    }
+
+    @Override
+    public String getLongSupportMessage(@NonNull ComponentName who) {
+        if (!mHasFeature) {
+            return null;
+        }
+        Preconditions.checkNotNull(who, "ComponentName is null");
+        synchronized (this) {
+            ActiveAdmin admin = getActiveAdminForUidLocked(who,
+                    mInjector.binderGetCallingUid());
+            return admin.longSupportMessage;
+        }
+    }
+
+    @Override
+    public String getShortSupportMessageForUser(@NonNull ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return null;
+        }
+        Preconditions.checkNotNull(who, "ComponentName is null");
+        if (!UserHandle.isSameApp(mInjector.binderGetCallingUid(), Process.SYSTEM_UID)) {
+            throw new SecurityException("Only the system can query support message for user");
+        }
+        synchronized (this) {
+            ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+            if (admin != null) {
+                return admin.shortSupportMessage;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public String getLongSupportMessageForUser(@NonNull ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return null;
+        }
+        Preconditions.checkNotNull(who, "ComponentName is null");
+        if (!UserHandle.isSameApp(mInjector.binderGetCallingUid(), Process.SYSTEM_UID)) {
+            throw new SecurityException("Only the system can query support message for user");
+        }
+        synchronized (this) {
+            ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+            if (admin != null) {
+                return admin.longSupportMessage;
+            }
+        }
+        return null;
+    }
 }
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 0bbd23e..dd6493c 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -1322,7 +1322,7 @@
         Intent intent = new Intent();
         intent.setComponent(new ComponentName("com.android.systemui",
                     "com.android.systemui.SystemUIService"));
-        intent.addFlags(Intent.FLAG_DEBUG_ENCRYPTION_TRIAGED);
+        intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
         //Slog.d(TAG, "Starting service: " + intent);
         context.startServiceAsUser(intent, UserHandle.SYSTEM);
     }
diff --git a/services/print/java/com/android/server/print/PrintManagerService.java b/services/print/java/com/android/server/print/PrintManagerService.java
index d5f384d..d250739 100644
--- a/services/print/java/com/android/server/print/PrintManagerService.java
+++ b/services/print/java/com/android/server/print/PrintManagerService.java
@@ -24,7 +24,6 @@
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
 import android.content.pm.UserInfo;
 import android.database.ContentObserver;
 import android.graphics.drawable.Icon;
@@ -56,7 +55,6 @@
 import java.io.PrintWriter;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 
 /**
  * SystemService wrapper for the PrintManager implementation. Publishes
@@ -88,11 +86,6 @@
     }
 
     class PrintManagerImpl extends IPrintManager.Stub {
-        private static final char COMPONENT_NAME_SEPARATOR = ':';
-
-        private static final String EXTRA_PRINT_SERVICE_COMPONENT_NAME =
-                "EXTRA_PRINT_SERVICE_COMPONENT_NAME";
-
         private static final int BACKGROUND_USER_ID = -10;
 
         private final Object mLock = new Object();
@@ -487,7 +480,7 @@
 
         private void registerContentObservers() {
             final Uri enabledPrintServicesUri = Settings.Secure.getUriFor(
-                    Settings.Secure.ENABLED_PRINT_SERVICES);
+                    Settings.Secure.DISABLED_PRINT_SERVICES);
             ContentObserver observer = new ContentObserver(BackgroundThread.getHandler()) {
                 @Override
                 public void onChange(boolean selfChange, Uri uri, int userId) {
@@ -511,8 +504,7 @@
 
         private void registerBroadcastReceivers() {
             PackageMonitor monitor = new PackageMonitor() {
-                @Override
-                public void onPackageModified(String packageName) {
+                private void updateServices(String packageName) {
                     if (!mUserManager.isUserUnlocked(getChangingUserId())) return;
                     synchronized (mLock) {
                         // A background user/profile's print jobs are running but there is
@@ -520,11 +512,15 @@
                         // to handle it as the change may affect ongoing print jobs.
                         boolean servicesChanged = false;
                         UserState userState = getOrCreateUserStateLocked(getChangingUserId());
-                        Iterator<ComponentName> iterator = userState.getEnabledServices().iterator();
-                        while (iterator.hasNext()) {
-                            ComponentName componentName = iterator.next();
-                            if (packageName.equals(componentName.getPackageName())) {
+
+                        List<PrintServiceInfo> installedServices = userState
+                                .getInstalledPrintServices();
+                        final int numInstalledServices = installedServices.size();
+                        for (int i = 0; i < numInstalledServices; i++) {
+                            if (installedServices.get(i).getResolveInfo().serviceInfo.packageName
+                                    .equals(packageName)) {
                                 servicesChanged = true;
+                                break;
                             }
                         }
                         if (servicesChanged) {
@@ -534,30 +530,15 @@
                 }
 
                 @Override
+                public void onPackageModified(String packageName) {
+                    updateServices(packageName);
+                    getOrCreateUserStateLocked(getChangingUserId()).prunePrintServices();
+                }
+
+                @Override
                 public void onPackageRemoved(String packageName, int uid) {
-                    if (!mUserManager.isUserUnlocked(getChangingUserId())) return;
-                    synchronized (mLock) {
-                        // A background user/profile's print jobs are running but there is
-                        // no UI shown. Hence, if the packages of such a user change we need
-                        // to handle it as the change may affect ongoing print jobs.
-                        boolean servicesRemoved = false;
-                        UserState userState = getOrCreateUserStateLocked(getChangingUserId());
-                        Iterator<ComponentName> iterator = userState.getEnabledServices().iterator();
-                        while (iterator.hasNext()) {
-                            ComponentName componentName = iterator.next();
-                            if (packageName.equals(componentName.getPackageName())) {
-                                userState.removeApprovedPrintService(componentName);
-                                iterator.remove();
-                                servicesRemoved = true;
-                            }
-                        }
-                        if (servicesRemoved) {
-                            persistComponentNamesToSettingLocked(
-                                    Settings.Secure.ENABLED_PRINT_SERVICES,
-                                    userState.getEnabledServices(), getChangingUserId());
-                            userState.updateIfNeededLocked();
-                        }
-                    }
+                    updateServices(packageName);
+                    getOrCreateUserStateLocked(getChangingUserId()).prunePrintServices();
                 }
 
                 @Override
@@ -570,10 +551,10 @@
                         // to handle it as the change may affect ongoing print jobs.
                         UserState userState = getOrCreateUserStateLocked(getChangingUserId());
                         boolean stoppedSomePackages = false;
-                        Iterator<ComponentName> iterator = userState.getEnabledServices()
+                        Iterator<PrintServiceInfo> iterator = userState.getEnabledPrintServices()
                                 .iterator();
                         while (iterator.hasNext()) {
-                            ComponentName componentName = iterator.next();
+                            ComponentName componentName = iterator.next().getComponentName();
                             String componentPackage = componentName.getPackageName();
                             for (String stoppedPackage : stoppedPackages) {
                                 if (componentPackage.equals(stoppedPackage)) {
@@ -606,48 +587,11 @@
                             .queryIntentServicesAsUser(intent, PackageManager.GET_SERVICES,
                                     getChangingUserId());
 
-                    if (installedServices == null) {
-                        return;
-                    }
-
-                    // Enable all added services by default
-                    synchronized (mLock) {
+                    if (installedServices != null) {
                         UserState userState = getOrCreateUserStateLocked(getChangingUserId());
-
-                        Set<ComponentName> enabledServices = userState.getEnabledServices();
-                        boolean servicesAdded = false;
-
-                        final int installedServiceCount = installedServices.size();
-                        for (int i = 0; i < installedServiceCount; i++) {
-                            ServiceInfo serviceInfo = installedServices.get(i).serviceInfo;
-                            ComponentName component = new ComponentName(serviceInfo.packageName,
-                                    serviceInfo.name);
-
-                            enabledServices.add(component);
-                            servicesAdded = true;
-                        }
-
-                        if (servicesAdded) {
-                            persistComponentNamesToSettingLocked(
-                                    Settings.Secure.ENABLED_PRINT_SERVICES, enabledServices,
-                                    getChangingUserId());
-                            userState.updateIfNeededLocked();
-                        }
+                        userState.updateIfNeededLocked();
                     }
                 }
-
-                private void persistComponentNamesToSettingLocked(String settingName,
-                        Set<ComponentName> componentNames, int userId) {
-                    StringBuilder builder = new StringBuilder();
-                    for (ComponentName componentName : componentNames) {
-                        if (builder.length() > 0) {
-                            builder.append(COMPONENT_NAME_SEPARATOR);
-                        }
-                        builder.append(componentName.flattenToShortString());
-                    }
-                    Settings.Secure.putStringForUser(mContext.getContentResolver(),
-                            settingName, builder.toString(), userId);
-                }
             };
 
             // package changes
diff --git a/services/print/java/com/android/server/print/RemotePrintSpooler.java b/services/print/java/com/android/server/print/RemotePrintSpooler.java
index 40a8880..d179b95 100644
--- a/services/print/java/com/android/server/print/RemotePrintSpooler.java
+++ b/services/print/java/com/android/server/print/RemotePrintSpooler.java
@@ -37,17 +37,18 @@
 import android.print.PrintJobId;
 import android.print.PrintJobInfo;
 import android.print.PrinterId;
+import android.printservice.PrintService;
 import android.util.Slog;
 import android.util.TimedRemoteCaller;
 
+import libcore.io.IoUtils;
+
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
 import java.lang.ref.WeakReference;
 import java.util.List;
 import java.util.concurrent.TimeoutException;
 
-import libcore.io.IoUtils;
-
 /**
  * This represents the remote print spooler as a local object to the
  * PrintManagerService. It is responsible to connecting to the remote
@@ -439,26 +440,24 @@
     }
 
     /**
-     * Connect to the print spooler service and remove an approved print service.
+     * Remove all approved {@link PrintService print services} that are not in the given set.
      *
-     * @param serviceToRemove The {@link ComponentName} of the service to be removed.
+     * @param servicesToKeep The {@link ComponentName names } of the services to keep
      */
-    public final void removeApprovedPrintService(ComponentName serviceToRemove) {
+    public final void pruneApprovedPrintServices(List<ComponentName> servicesToKeep) {
         throwIfCalledOnMainThread();
         synchronized (mLock) {
             throwIfDestroyedLocked();
             mCanUnbind = false;
         }
         try {
-            getRemoteInstanceLazy().removeApprovedPrintService(serviceToRemove);
-        } catch (RemoteException re) {
-            Slog.e(LOG_TAG, "Error removing approved print service.", re);
-        } catch (TimeoutException te) {
-            Slog.e(LOG_TAG, "Error removing approved print service.", te);
+            getRemoteInstanceLazy().pruneApprovedPrintServices(servicesToKeep);
+        } catch (RemoteException|TimeoutException re) {
+            Slog.e(LOG_TAG, "Error pruning approved print services.", re);
         } finally {
             if (DEBUG) {
                 Slog.i(LOG_TAG, "[user: " + mUserHandle.getIdentifier()
-                        + "] removing approved print service()");
+                        + "] pruneApprovedPrintServices()");
             }
             synchronized (mLock) {
                 mCanUnbind = true;
diff --git a/services/print/java/com/android/server/print/UserState.java b/services/print/java/com/android/server/print/UserState.java
index 63d3301..dcc02a3 100644
--- a/services/print/java/com/android/server/print/UserState.java
+++ b/services/print/java/com/android/server/print/UserState.java
@@ -21,11 +21,9 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentSender;
-import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ParceledListSlice;
 import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
 import android.graphics.drawable.Icon;
 import android.net.Uri;
 import android.os.AsyncTask;
@@ -98,7 +96,7 @@
     private final List<PrintServiceInfo> mInstalledServices =
             new ArrayList<PrintServiceInfo>();
 
-    private final Set<ComponentName> mEnabledServices =
+    private final Set<ComponentName> mDisabledServices =
             new ArraySet<ComponentName>();
 
     private final PrintJobForAppCache mPrintJobForAppCache =
@@ -126,8 +124,15 @@
         mLock = lock;
         mSpooler = new RemotePrintSpooler(context, userId, this);
         mHandler = new UserStateHandler(context.getMainLooper());
+
         synchronized (mLock) {
-            enableSystemPrintServicesLocked();
+            readInstalledPrintServicesLocked();
+            upgradePersistentStateIfNeeded();
+            readDisabledPrintServicesLocked();
+
+            // Some print services might have gotten installed before the User State came up
+            prunePrintServices();
+
             onConfigurationChangedLocked();
         }
     }
@@ -320,15 +325,6 @@
         }
     }
 
-    /**
-     * Remove an approved print service.
-     *
-     * @param serviceToRemove The {@link ComponentName} of the service to be removed.
-     */
-    public void removeApprovedPrintService(ComponentName serviceToRemove) {
-        mSpooler.removeApprovedPrintService(serviceToRemove);
-    }
-
     public void restartPrintJob(PrintJobId printJobId, int appId) {
         PrintJobInfo printJobInfo = getPrintJobInfo(printJobId, appId);
         if (printJobInfo == null || printJobInfo.getState() != PrintJobInfo.STATE_FAILED) {
@@ -597,13 +593,6 @@
         }
     }
 
-    public Set<ComponentName> getEnabledServices() {
-        synchronized(mLock) {
-            throwIfDestroyedLocked();
-            return mEnabledServices;
-        }
-    }
-
     public void destroyLocked() {
         throwIfDestroyedLocked();
         mSpooler.destroy();
@@ -612,7 +601,7 @@
         }
         mActiveServices.clear();
         mInstalledServices.clear();
-        mEnabledServices.clear();
+        mDisabledServices.clear();
         if (mPrinterDiscoverySession != null) {
             mPrinterDiscoverySession.destroyLocked();
             mPrinterDiscoverySession = null;
@@ -646,12 +635,12 @@
                    .append(installedService.getAdvancedOptionsActivityName()).println();
         }
 
-        pw.append(prefix).append(tab).append("enabled services:").println();
-        for (ComponentName enabledService : mEnabledServices) {
-            String enabledServicePrefix = prefix + tab + tab;
-            pw.append(enabledServicePrefix).append("service:").println();
-            pw.append(enabledServicePrefix).append(tab).append("componentName=")
-                    .append(enabledService.flattenToString());
+        pw.append(prefix).append(tab).append("disabled services:").println();
+        for (ComponentName disabledService : mDisabledServices) {
+            String disabledServicePrefix = prefix + tab + tab;
+            pw.append(disabledServicePrefix).append("service:").println();
+            pw.append(disabledServicePrefix).append(tab).append("componentName=")
+                    .append(disabledService.flattenToString());
             pw.println();
         }
 
@@ -679,7 +668,7 @@
     private boolean readConfigurationLocked() {
         boolean somethingChanged = false;
         somethingChanged |= readInstalledPrintServicesLocked();
-        somethingChanged |= readEnabledPrintServicesLocked();
+        somethingChanged |= readDisabledPrintServicesLocked();
         return somethingChanged;
     }
 
@@ -742,13 +731,50 @@
         return false;
     }
 
-    private boolean readEnabledPrintServicesLocked() {
-        Set<ComponentName> tempEnabledServiceNameSet = new HashSet<ComponentName>();
-        readPrintServicesFromSettingLocked(Settings.Secure.ENABLED_PRINT_SERVICES,
-                tempEnabledServiceNameSet);
-        if (!tempEnabledServiceNameSet.equals(mEnabledServices)) {
-            mEnabledServices.clear();
-            mEnabledServices.addAll(tempEnabledServiceNameSet);
+    /**
+     * Update persistent state from a previous version of Android.
+     */
+    private void upgradePersistentStateIfNeeded() {
+        String enabledSettingValue = Settings.Secure.getStringForUser(mContext.getContentResolver(),
+                Settings.Secure.ENABLED_PRINT_SERVICES, mUserId);
+
+        // Pre N we store the enabled services, in N and later we store the disabled services.
+        // Hence if enabledSettingValue is still set, we need to upgrade.
+        if (enabledSettingValue != null) {
+            Set<ComponentName> enabledServiceNameSet = new HashSet<ComponentName>();
+            readPrintServicesFromSettingLocked(Settings.Secure.ENABLED_PRINT_SERVICES,
+                    enabledServiceNameSet);
+
+            ArraySet<ComponentName> disabledServices = new ArraySet<>();
+            final int numInstalledServices = mInstalledServices.size();
+            for (int i = 0; i < numInstalledServices; i++) {
+                ComponentName serviceName = mInstalledServices.get(i).getComponentName();
+                if (!enabledServiceNameSet.contains(serviceName)) {
+                    disabledServices.add(serviceName);
+                }
+            }
+
+            writeDisabledPrintServicesLocked(disabledServices);
+
+            // We won't needed ENABLED_PRINT_SERVICES anymore, set to null to prevent upgrade to run
+            // again.
+            Settings.Secure.putStringForUser(mContext.getContentResolver(),
+                    Settings.Secure.ENABLED_PRINT_SERVICES, null, mUserId);
+        }
+    }
+
+    /**
+     * Read the set of disabled print services from the secure settings.
+     *
+     * @return true if the state changed.
+     */
+    private boolean readDisabledPrintServicesLocked() {
+        Set<ComponentName> tempDisabledServiceNameSet = new HashSet<ComponentName>();
+        readPrintServicesFromSettingLocked(Settings.Secure.DISABLED_PRINT_SERVICES,
+                tempDisabledServiceNameSet);
+        if (!tempDisabledServiceNameSet.equals(mDisabledServices)) {
+            mDisabledServices.clear();
+            mDisabledServices.addAll(tempDisabledServiceNameSet);
             return true;
         }
         return false;
@@ -774,70 +800,28 @@
         }
     }
 
-    private void enableSystemPrintServicesLocked() {
-        // Load enabled and installed services.
-        readEnabledPrintServicesLocked();
-        readInstalledPrintServicesLocked();
-
-        // Load the system services once enabled on first boot.
-        Set<ComponentName> enabledOnFirstBoot = new HashSet<ComponentName>();
-        readPrintServicesFromSettingLocked(
-                Settings.Secure.ENABLED_ON_FIRST_BOOT_SYSTEM_PRINT_SERVICES,
-                enabledOnFirstBoot);
-
+    /**
+     * Persist the disabled print services to the secure settings.
+     */
+    private void writeDisabledPrintServicesLocked(Set<ComponentName> disabledServices) {
         StringBuilder builder = new StringBuilder();
-
-        final int serviceCount = mInstalledServices.size();
-        for (int i = 0; i < serviceCount; i++) {
-            ServiceInfo serviceInfo = mInstalledServices.get(i).getResolveInfo().serviceInfo;
-            // Enable system print services if we never did that and are not enabled.
-            if ((serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
-                ComponentName serviceName = new ComponentName(
-                        serviceInfo.packageName, serviceInfo.name);
-                if (!mEnabledServices.contains(serviceName)
-                        && !enabledOnFirstBoot.contains(serviceName)) {
-                    if (builder.length() > 0) {
-                        builder.append(":");
-                    }
-                    builder.append(serviceName.flattenToString());
-                }
+        for (ComponentName componentName : disabledServices) {
+            if (builder.length() > 0) {
+                builder.append(COMPONENT_NAME_SEPARATOR);
             }
-        }
-
-        // Nothing to be enabled - done.
-        if (builder.length() <= 0) {
-            return;
-        }
-
-        String servicesToEnable = builder.toString();
-
-        // Update the enabled services setting.
-        String enabledServices = Settings.Secure.getStringForUser(
-                mContext.getContentResolver(), Settings.Secure.ENABLED_PRINT_SERVICES, mUserId);
-        if (TextUtils.isEmpty(enabledServices)) {
-            enabledServices = servicesToEnable;
-        } else {
-            enabledServices = enabledServices + ":" + servicesToEnable;
+            builder.append(componentName.flattenToShortString());
         }
         Settings.Secure.putStringForUser(mContext.getContentResolver(),
-                Settings.Secure.ENABLED_PRINT_SERVICES, enabledServices, mUserId);
-
-        // Update the enabled on first boot services setting.
-        String enabledOnFirstBootServices = Settings.Secure.getStringForUser(
-                mContext.getContentResolver(),
-                Settings.Secure.ENABLED_ON_FIRST_BOOT_SYSTEM_PRINT_SERVICES, mUserId);
-        if (TextUtils.isEmpty(enabledOnFirstBootServices)) {
-            enabledOnFirstBootServices = servicesToEnable;
-        } else {
-            enabledOnFirstBootServices = enabledOnFirstBootServices + ":" + enabledServices;
-        }
-        Settings.Secure.putStringForUser(mContext.getContentResolver(),
-                Settings.Secure.ENABLED_ON_FIRST_BOOT_SYSTEM_PRINT_SERVICES,
-                enabledOnFirstBootServices, mUserId);
+                Settings.Secure.DISABLED_PRINT_SERVICES, builder.toString(), mUserId);
     }
 
-    private void onConfigurationChangedLocked() {
-        Set<ComponentName> installedComponents = new ArraySet<ComponentName>();
+    /**
+     * Get the {@link ComponentName names} of the installed print services
+     *
+     * @return The names of the installed print services
+     */
+    private ArrayList<ComponentName> getInstalledComponents() {
+        ArrayList<ComponentName> installedComponents = new ArrayList<ComponentName>();
 
         final int installedCount = mInstalledServices.size();
         for (int i = 0; i < installedCount; i++) {
@@ -846,8 +830,37 @@
                     resolveInfo.serviceInfo.name);
 
             installedComponents.add(serviceName);
+        }
 
-            if (mEnabledServices.contains(serviceName)) {
+        return installedComponents;
+    }
+
+    /**
+     * Prune persistent state if a print service was uninstalled
+     */
+    public void prunePrintServices() {
+        synchronized (mLock) {
+            ArrayList<ComponentName> installedComponents = getInstalledComponents();
+
+            // Remove unnecessary entries from persistent state "disabled services"
+            boolean disabledServicesUninstalled = mDisabledServices.retainAll(installedComponents);
+            if (disabledServicesUninstalled) {
+                writeDisabledPrintServicesLocked(mDisabledServices);
+            }
+
+            // Remove unnecessary entries from persistent state "approved services"
+            mSpooler.pruneApprovedPrintServices(installedComponents);
+        }
+    }
+
+    private void onConfigurationChangedLocked() {
+        ArrayList<ComponentName> installedComponents = getInstalledComponents();
+
+        final int installedCount = installedComponents.size();
+        for (int i = 0; i < installedCount; i++) {
+            ComponentName serviceName = installedComponents.get(i);
+
+            if (!mDisabledServices.contains(serviceName)) {
                 if (!mActiveServices.containsKey(serviceName)) {
                     RemotePrintService service = new RemotePrintService(
                             mContext, serviceName, mUserId, mSpooler, this);
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
index 568e1d5..672058b 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
@@ -758,7 +758,7 @@
         when(mContext.userManager.getUserRestrictions()).thenReturn(new Bundle());
 
         // Now call clear.
-        doReturn(DpmMockContext.CALLER_SYSTEM_USER_UID).when(mContext.packageManager).getPackageUid(
+        doReturn(DpmMockContext.CALLER_SYSTEM_USER_UID).when(mContext.packageManager).getPackageUidAsUser(
                 eq(admin1.getPackageName()),
                 anyInt());
         dpm.clearDeviceOwnerApp(admin1.getPackageName());
@@ -797,7 +797,7 @@
         mContext.binder.callingUid = DpmMockContext.CALLER_UID;
 
         // Now call clear.
-        doReturn(DpmMockContext.CALLER_UID).when(mContext.packageManager).getPackageUid(
+        doReturn(DpmMockContext.CALLER_UID).when(mContext.packageManager).getPackageUidAsUser(
                 eq(admin1.getPackageName()),
                 anyInt());
         try {
@@ -951,7 +951,7 @@
         final int appRestrictionsManagerAppId = 20987;
         final int appRestrictionsManagerUid = UserHandle.getUid(
                 DpmMockContext.CALLER_USER_HANDLE, appRestrictionsManagerAppId);
-        doReturn(appRestrictionsManagerUid).when(mContext.packageManager).getPackageUid(
+        doReturn(appRestrictionsManagerUid).when(mContext.packageManager).getPackageUidAsUser(
                 eq(appRestrictionsManagerPackage),
                 eq(DpmMockContext.CALLER_USER_HANDLE));
         mContext.binder.callingUid = appRestrictionsManagerUid;
@@ -1385,4 +1385,95 @@
 
         dpm.reboot(admin1);
     }
+
+    public void testSetGetSupportText() {
+        mContext.callerPermissions.add(permission.MANAGE_DEVICE_ADMINS);
+        dpm.setActiveAdmin(admin1, true);
+        dpm.setActiveAdmin(admin2, true);
+        mContext.callerPermissions.remove(permission.MANAGE_DEVICE_ADMINS);
+
+        // Null default support messages.
+        {
+            assertNull(dpm.getLongSupportMessage(admin1));
+            assertNull(dpm.getShortSupportMessage(admin1));
+            mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
+            assertNull(dpm.getShortSupportMessageForUser(admin1,
+                    DpmMockContext.CALLER_USER_HANDLE));
+            assertNull(dpm.getLongSupportMessageForUser(admin1,
+                    DpmMockContext.CALLER_USER_HANDLE));
+            mMockContext.binder.callingUid = DpmMockContext.CALLER_UID;
+        }
+
+        // Only system can call the per user versions.
+        {
+            try {
+                dpm.getShortSupportMessageForUser(admin1,
+                        DpmMockContext.CALLER_USER_HANDLE);
+                fail("Only system should be able to call getXXXForUser versions");
+            } catch (SecurityException expected) {
+                MoreAsserts.assertContainsRegex("message for user", expected.getMessage());
+            }
+            try {
+                dpm.getLongSupportMessageForUser(admin1,
+                        DpmMockContext.CALLER_USER_HANDLE);
+                fail("Only system should be able to call getXXXForUser versions");
+            } catch (SecurityException expected) {
+                MoreAsserts.assertContainsRegex("message for user", expected.getMessage());
+            }
+        }
+
+        // Can't set message for admin in another uid.
+        {
+            mContext.binder.callingUid = DpmMockContext.CALLER_UID + 1;
+            try {
+                dpm.setShortSupportMessage(admin1, "Some text");
+                fail("Admins should only be able to change their own support text.");
+            } catch (SecurityException expected) {
+                MoreAsserts.assertContainsRegex("is not owned by uid", expected.getMessage());
+            }
+            mContext.binder.callingUid = DpmMockContext.CALLER_UID;
+        }
+
+        // Set/Get short returns what it sets and other admins text isn't changed.
+        {
+            final String supportText = "Some text to test with.";
+            dpm.setShortSupportMessage(admin1, supportText);
+            assertEquals(supportText, dpm.getShortSupportMessage(admin1));
+            assertNull(dpm.getLongSupportMessage(admin1));
+            assertNull(dpm.getShortSupportMessage(admin2));
+
+            mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
+            assertEquals(supportText, dpm.getShortSupportMessageForUser(admin1,
+                    DpmMockContext.CALLER_USER_HANDLE));
+            assertNull(dpm.getShortSupportMessageForUser(admin2,
+                    DpmMockContext.CALLER_USER_HANDLE));
+            assertNull(dpm.getLongSupportMessageForUser(admin1,
+                    DpmMockContext.CALLER_USER_HANDLE));
+            mMockContext.binder.callingUid = DpmMockContext.CALLER_UID;
+
+            dpm.setShortSupportMessage(admin1, null);
+            assertNull(dpm.getShortSupportMessage(admin1));
+        }
+
+        // Set/Get long returns what it sets and other admins text isn't changed.
+        {
+            final String supportText = "Some text to test with.\nWith more text.";
+            dpm.setLongSupportMessage(admin1, supportText);
+            assertEquals(supportText, dpm.getLongSupportMessage(admin1));
+            assertNull(dpm.getShortSupportMessage(admin1));
+            assertNull(dpm.getLongSupportMessage(admin2));
+
+            mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
+            assertEquals(supportText, dpm.getLongSupportMessageForUser(admin1,
+                    DpmMockContext.CALLER_USER_HANDLE));
+            assertNull(dpm.getLongSupportMessageForUser(admin2,
+                    DpmMockContext.CALLER_USER_HANDLE));
+            assertNull(dpm.getShortSupportMessageForUser(admin1,
+                    DpmMockContext.CALLER_USER_HANDLE));
+            mMockContext.binder.callingUid = DpmMockContext.CALLER_UID;
+
+            dpm.setLongSupportMessage(admin1, null);
+            assertNull(dpm.getLongSupportMessage(admin1));
+        }
+    }
 }
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DpmTestBase.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DpmTestBase.java
index 5b33e4d..c557ab7 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DpmTestBase.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DpmTestBase.java
@@ -117,7 +117,7 @@
         // We need to rewrite the UID in the activity info.
         realResolveInfo.get(0).activityInfo.applicationInfo = ai;
 
-        doReturn(realResolveInfo).when(mMockContext.packageManager).queryBroadcastReceivers(
+        doReturn(realResolveInfo).when(mMockContext.packageManager).queryBroadcastReceiversAsUser(
                 MockUtils.checkIntentComponent(admin),
                 eq(PackageManager.GET_META_DATA
                         | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS),
diff --git a/services/tests/servicestests/src/com/android/server/notification/RankingHelperTest.java b/services/tests/servicestests/src/com/android/server/notification/RankingHelperTest.java
index df7b412..2640889 100644
--- a/services/tests/servicestests/src/com/android/server/notification/RankingHelperTest.java
+++ b/services/tests/servicestests/src/com/android/server/notification/RankingHelperTest.java
@@ -35,7 +35,7 @@
 
 public class RankingHelperTest extends AndroidTestCase {
     @Mock NotificationUsageStats mUsageStats;
-    @Mock Handler handler;
+    @Mock RankingHandler handler;
 
     private Notification mNotiGroupGSortA;
     private Notification mNotiGroupGSortB;
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java
index 2b0919b..23e8894 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsService.java
@@ -374,7 +374,7 @@
         for (int i = 0; i < userIds.length; i++) {
             final int userId = userIds[i];
             List<PackageInfo> packages =
-                    getContext().getPackageManager().getInstalledPackages(
+                    getContext().getPackageManager().getInstalledPackagesAsUser(
                             PackageManager.GET_DISABLED_COMPONENTS
                                 | PackageManager.GET_UNINSTALLED_PACKAGES,
                             userId);
diff --git a/services/usage/java/com/android/server/usage/UserUsageStatsService.java b/services/usage/java/com/android/server/usage/UserUsageStatsService.java
index 5188e5f..72621a4 100644
--- a/services/usage/java/com/android/server/usage/UserUsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UserUsageStatsService.java
@@ -148,7 +148,7 @@
     private void initializeDefaultsForApps(long currentTimeMillis, long deviceUsageTime,
             boolean firstUpdate) {
         PackageManager pm = mContext.getPackageManager();
-        List<PackageInfo> packages = pm.getInstalledPackages(0, mUserId);
+        List<PackageInfo> packages = pm.getInstalledPackagesAsUser(0, mUserId);
         final int packageCount = packages.size();
         for (int i = 0; i < packageCount; i++) {
             final PackageInfo pi = packages.get(i);
diff --git a/telecomm/java/android/telecom/Call.java b/telecomm/java/android/telecom/Call.java
index 5d5df95..aa95e1d 100644
--- a/telecomm/java/android/telecom/Call.java
+++ b/telecomm/java/android/telecom/Call.java
@@ -242,8 +242,13 @@
          */
         public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
 
+        /**
+         * Whether the call is associated with the work profile.
+         */
+        public static final int PROPERTY_WORK_CALL = 0x00000020;
+
         //******************************************************************************************
-        // Next PROPERTY value: 0x00000020
+        // Next PROPERTY value: 0x00000040
         //******************************************************************************************
 
         private final Uri mHandle;
diff --git a/telecomm/java/android/telecom/DefaultDialerManager.java b/telecomm/java/android/telecom/DefaultDialerManager.java
index 27ee804..a915d37 100644
--- a/telecomm/java/android/telecom/DefaultDialerManager.java
+++ b/telecomm/java/android/telecom/DefaultDialerManager.java
@@ -155,8 +155,7 @@
 
         // Get the list of apps registered for the DIAL intent with empty scheme
         Intent intent = new Intent(Intent.ACTION_DIAL);
-        List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent,
-                PackageManager.MATCH_ENCRYPTION_DEFAULT);
+        List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0);
 
         List<String> packageNames = new ArrayList<>();
 
@@ -209,7 +208,7 @@
 
         final List<String> result = new ArrayList<>();
         final List<ResolveInfo> resolveInfoList = context.getPackageManager()
-                .queryIntentActivities(intent, PackageManager.MATCH_ENCRYPTION_DEFAULT);
+                .queryIntentActivities(intent, 0);
         final int length = resolveInfoList.size();
         for (int i = 0; i < length; i++) {
             final ActivityInfo info = resolveInfoList.get(i).activityInfo;
diff --git a/telecomm/java/android/telecom/InCallService.java b/telecomm/java/android/telecom/InCallService.java
index 5087080..426b240 100644
--- a/telecomm/java/android/telecom/InCallService.java
+++ b/telecomm/java/android/telecom/InCallService.java
@@ -49,7 +49,7 @@
  * <pre>
  * {@code
  * <service android:name="your.package.YourInCallServiceImplementation"
- *          android:permission="android.permission.BIND_IN_CALL_SERVICE">
+ *          android:permission="android.permission.BIND_INCALL_SERVICE">
  *      <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
  *      <intent-filter>
  *          <action android:name="android.telecom.InCallService"/>
diff --git a/telephony/java/android/telephony/ServiceState.java b/telephony/java/android/telephony/ServiceState.java
index 8537f9c..c680999 100644
--- a/telephony/java/android/telephony/ServiceState.java
+++ b/telephony/java/android/telephony/ServiceState.java
@@ -153,6 +153,17 @@
      * @hide
      */
     public static final int RIL_RADIO_TECHNOLOGY_IWLAN = 18;
+
+    /** @hide */
+    public static final int RIL_RADIO_CDMA_TECHNOLOGY_BITMASK =
+            (1 << (RIL_RADIO_TECHNOLOGY_IS95A - 1))
+                    | (1 << (RIL_RADIO_TECHNOLOGY_IS95B - 1))
+                    | (1 << (RIL_RADIO_TECHNOLOGY_1xRTT - 1))
+                    | (1 << (RIL_RADIO_TECHNOLOGY_EVDO_0 - 1))
+                    | (1 << (RIL_RADIO_TECHNOLOGY_EVDO_A - 1))
+                    | (1 << (RIL_RADIO_TECHNOLOGY_EVDO_B - 1))
+                    | (1 << (RIL_RADIO_TECHNOLOGY_EHRPD - 1));
+
     /**
      * Available registration states for GSM, UMTS and CDMA.
      */
@@ -1141,16 +1152,8 @@
     }
 
     /** @hide */
-    public static boolean hasCdma(int radioTechnologyBitmask) {
-        int cdmaBitmask = (RIL_RADIO_TECHNOLOGY_IS95A
-                | RIL_RADIO_TECHNOLOGY_IS95B
-                | RIL_RADIO_TECHNOLOGY_1xRTT
-                | RIL_RADIO_TECHNOLOGY_EVDO_0
-                | RIL_RADIO_TECHNOLOGY_EVDO_A
-                | RIL_RADIO_TECHNOLOGY_EVDO_B
-                | RIL_RADIO_TECHNOLOGY_EHRPD);
-
-        return ((radioTechnologyBitmask & cdmaBitmask) != 0);
+    public static boolean bearerBitmapHasCdma(int radioTechnologyBitmap) {
+        return (RIL_RADIO_CDMA_TECHNOLOGY_BITMASK & radioTechnologyBitmap) != 0;
     }
 
     /** @hide */
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 0b5aaa3..913cb18 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -24,6 +24,7 @@
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
+import android.net.Uri;
 import android.provider.Settings;
 import android.provider.Settings.SettingNotFoundException;
 import android.os.Bundle;
@@ -31,6 +32,7 @@
 import android.os.ServiceManager;
 import android.os.SystemProperties;
 import android.telecom.PhoneAccount;
+import android.telecom.PhoneAccountHandle;
 import android.util.Log;
 
 import com.android.internal.telecom.ITelecomService;
@@ -4865,4 +4867,43 @@
         }
         return null;
     }
+
+    /**
+     * Returns the URI for the per-account voicemail ringtone set in Phone settings.
+     *
+     * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
+     * voicemail ringtone.
+     * @return The URI for the ringtone to play when receiving a voicemail from a specific
+     * PhoneAccount.
+     */
+    public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
+        try {
+            ITelephony service = getITelephony();
+            if (service != null) {
+                return service.getVoicemailRingtoneUri(accountHandle);
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling ITelephony#getVoicemailRingtoneUri", e);
+        }
+        return null;
+    }
+
+    /**
+     * Returns whether vibration is set for voicemail notification in Phone settings.
+     *
+     * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
+     * voicemail vibration setting.
+     * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
+     */
+    public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
+        try {
+            ITelephony service = getITelephony();
+            if (service != null) {
+                return service.isVoicemailVibrationEnabled(accountHandle);
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e);
+        }
+        return false;
+    }
 }
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index 8172e94..d1badc9 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -18,7 +18,9 @@
 
 import android.content.Intent;
 import android.os.Bundle;
+import android.net.Uri;
 import android.telecom.PhoneAccount;
+import android.telecom.PhoneAccountHandle;
 import android.telephony.CellInfo;
 import android.telephony.IccOpenLogicalChannelResponse;
 import android.telephony.ModemActivityInfo;
@@ -966,7 +968,7 @@
      * Returns the Status of Wi-Fi Calling
      */
     boolean isWifiCallingAvailable();
-    
+
     /**
      * Returns the Status of Volte
      */
@@ -1014,4 +1016,23 @@
      * @return Service state on specified subscription.
      */
     ServiceState getServiceStateForSubscriber(int subId, String callingPackage);
+
+    /**
+     * Returns the URI for the per-account voicemail ringtone set in Phone settings.
+     *
+     * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
+     * voicemail ringtone.
+     * @return The URI for the ringtone to play when receiving a voicemail from a specific
+     * PhoneAccount.
+     */
+    Uri getVoicemailRingtoneUri(in PhoneAccountHandle accountHandle);
+
+    /**
+     * Returns whether vibration is set for voicemail notification in Phone settings.
+     *
+     * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
+     * voicemail vibration setting.
+     * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
+     */
+    boolean isVoicemailVibrationEnabled(in PhoneAccountHandle accountHandle);
 }
diff --git a/test-runner/src/android/test/mock/MockPackageManager.java b/test-runner/src/android/test/mock/MockPackageManager.java
index 2813df5..5381e4ef6 100644
--- a/test-runner/src/android/test/mock/MockPackageManager.java
+++ b/test-runner/src/android/test/mock/MockPackageManager.java
@@ -34,7 +34,6 @@
 import android.content.pm.InstrumentationInfo;
 import android.content.pm.IntentFilterVerificationInfo;
 import android.content.pm.KeySet;
-import android.content.pm.ManifestDigest;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageInstaller;
 import android.content.pm.PackageItemInfo;
@@ -97,14 +96,30 @@
     }
 
     @Override
-
     public int[] getPackageGids(String packageName) throws NameNotFoundException {
         throw new UnsupportedOperationException();
     }
 
+    @Override
+    public int[] getPackageGids(String packageName, int flags) throws NameNotFoundException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
+        throw new UnsupportedOperationException();
+    }
+
     /** @hide */
     @Override
-    public int getPackageUid(String packageName, int userHandle)
+    public int getPackageUidAsUser(String packageName, int flags, int userHandle)
+            throws NameNotFoundException {
+        throw new UnsupportedOperationException();
+    }
+
+    /** @hide */
+    @Override
+    public int getPackageUidAsUser(String packageName, int userHandle)
             throws NameNotFoundException {
         throw new UnsupportedOperationException();
     }
@@ -175,7 +190,7 @@
 
     /** @hide */
     @Override
-    public List<PackageInfo> getInstalledPackages(int flags, int userId) {
+    public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
         throw new UnsupportedOperationException();
     }
 
@@ -356,7 +371,7 @@
 
     /** @hide */
     @Override
-    public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags, int userId) {
+    public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
         throw new UnsupportedOperationException();
     }
 
@@ -747,7 +762,7 @@
      * @hide - to match hiding in superclass
      */
     @Override
-    public void getPackageSizeInfo(String packageName, int userHandle,
+    public void getPackageSizeInfoAsUser(String packageName, int userHandle,
             IPackageStatsObserver observer) {
         throw new UnsupportedOperationException();
     }
@@ -820,7 +835,7 @@
     @Override
     public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer,
             int flags, String installerPackageName, Uri verificationURI,
-            ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {
+            ContainerEncryptionParams encryptionParams) {
         throw new UnsupportedOperationException();
     }
 
@@ -891,7 +906,7 @@
      * @hide
      */
     @Override
-    public int getIntentVerificationStatus(String packageName, int userId) {
+    public int getIntentVerificationStatusAsUser(String packageName, int userId) {
         throw new UnsupportedOperationException();
     }
 
@@ -899,7 +914,7 @@
      * @hide
      */
     @Override
-    public boolean updateIntentVerificationStatus(String packageName, int status, int userId) {
+    public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
         throw new UnsupportedOperationException();
     }
 
@@ -916,16 +931,30 @@
         throw new UnsupportedOperationException();
     }
 
-    @Override
+    /** {@removed} */
+    @Deprecated
     public String getDefaultBrowserPackageName(int userId) {
         throw new UnsupportedOperationException();
     }
 
+    /** {@hide} */
     @Override
+    public String getDefaultBrowserPackageNameAsUser(int userId) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@removed} */
+    @Deprecated
     public boolean setDefaultBrowserPackageName(String packageName, int userId) {
         throw new UnsupportedOperationException();
     }
 
+    /** {@hide} */
+    @Override
+    public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
+        throw new UnsupportedOperationException();
+    }
+
     /**
      * @hide
      */
@@ -957,7 +986,7 @@
     @Override
     public void installPackageWithVerification(Uri packageURI,
             PackageInstallObserver observer, int flags, String installerPackageName,
-            Uri verificationURI, ManifestDigest manifestDigest,
+            Uri verificationURI,
             ContainerEncryptionParams encryptionParams) {
         throw new UnsupportedOperationException();
     }
diff --git a/tests/RenderScriptTests/Android.mk b/tests/RenderScriptTests/Android.mk
deleted file mode 100644
index 5053e7d..0000000
--- a/tests/RenderScriptTests/Android.mk
+++ /dev/null
@@ -1 +0,0 @@
-include $(call all-subdir-makefiles)
diff --git a/tests/RenderScriptTests/FBOTest/Android.mk b/tests/RenderScriptTests/FBOTest/Android.mk
deleted file mode 100644
index 7a578d9..0000000
--- a/tests/RenderScriptTests/FBOTest/Android.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Copyright (C) 2008 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
-
-LOCAL_PACKAGE_NAME := FBOTest
-
-LOCAL_SDK_VERSION := 17
-
-include $(BUILD_PACKAGE)
diff --git a/tests/RenderScriptTests/FBOTest/AndroidManifest.xml b/tests/RenderScriptTests/FBOTest/AndroidManifest.xml
deleted file mode 100644
index 788e856..0000000
--- a/tests/RenderScriptTests/FBOTest/AndroidManifest.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.android.fbotest">
-    <application android:label="_FBOTest">
-        <activity android:name="FBOTest"
-                  android:label="FBO Base Test"
-                  android:theme="@android:style/Theme.Black.NoTitleBar">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-        <activity android:name="FBOSync"
-                  android:label="FBO Sync Test"
-                  android:theme="@android:style/Theme.Black.NoTitleBar">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-    </application>
-</manifest>
diff --git a/tests/RenderScriptTests/FBOTest/res/drawable-nodpi/robot.png b/tests/RenderScriptTests/FBOTest/res/drawable-nodpi/robot.png
deleted file mode 100644
index f7353fd..0000000
--- a/tests/RenderScriptTests/FBOTest/res/drawable-nodpi/robot.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/FBOTest/res/raw/robot.a3d b/tests/RenderScriptTests/FBOTest/res/raw/robot.a3d
deleted file mode 100644
index f48895c..0000000
--- a/tests/RenderScriptTests/FBOTest/res/raw/robot.a3d
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSync.java b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSync.java
deleted file mode 100644
index d30ad7e..0000000
--- a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSync.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.fbotest;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
-import android.app.Activity;
-import android.content.res.Configuration;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.provider.Settings.System;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.MenuInflater;
-import android.view.Window;
-import android.widget.Button;
-import android.widget.ListView;
-import android.net.Uri;
-
-import java.lang.Runtime;
-
-public class FBOSync extends Activity {
-
-    private FBOSyncView mView;
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        // Create our Preview view and set it as the content of our
-        // Activity
-        mView = new FBOSyncView(this);
-        setContentView(mView);
-    }
-
-    @Override
-    protected void onResume() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
-        super.onResume();
-        mView.resume();
-    }
-
-    @Override
-    protected void onPause() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
-        super.onPause();
-        mView.pause();
-    }
-}
-
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSyncRS.java b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSyncRS.java
deleted file mode 100644
index 57a117c..0000000
--- a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSyncRS.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.fbotest;
-
-import java.io.Writer;
-
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.renderscript.Element.DataType;
-import android.renderscript.Element.DataKind;
-import android.renderscript.ProgramStore.DepthFunc;
-import android.renderscript.Type.Builder;
-import android.util.Log;
-
-
-public class FBOSyncRS {
-
-    public FBOSyncRS() {
-    }
-
-    public void init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-        initRS();
-    }
-
-    public void surfaceChanged() {
-        mRS.getWidth();
-        mRS.getHeight();
-    }
-
-    private Resources mRes;
-    private RenderScriptGL mRS;
-    private Sampler mSampler;
-    private ProgramStore mPSBackground;
-    private ProgramFragment mPFBackground;
-    private ProgramVertex mPVBackground;
-    private ProgramVertexFixedFunction.Constants mPVA;
-
-    private Allocation mGridImage;
-    private Allocation mOffscreen;
-    private Allocation mOffscreenDepth;
-    private Allocation mAllocPV;
-    private Allocation mReadBackTest;
-
-    private Font mItalic;
-    private Allocation mTextAlloc;
-
-    private ScriptField_MeshInfo mMeshes;
-    private ScriptC_fbosync mScript;
-
-
-    public void onActionDown(float x, float y) {
-        mScript.invoke_onActionDown(x, y);
-    }
-
-    public void onActionScale(float scale) {
-        mScript.invoke_onActionScale(scale);
-    }
-
-    public void onActionMove(float x, float y) {
-        mScript.invoke_onActionMove(x, y);
-    }
-
-    private void initPFS() {
-        ProgramStore.Builder b = new ProgramStore.Builder(mRS);
-
-        b.setDepthFunc(ProgramStore.DepthFunc.LESS);
-        b.setDitherEnabled(false);
-        b.setDepthMaskEnabled(true);
-        mPSBackground = b.create();
-
-        mScript.set_gPFSBackground(mPSBackground);
-    }
-
-    private void initPF() {
-        Sampler.Builder bs = new Sampler.Builder(mRS);
-        bs.setMinification(Sampler.Value.LINEAR);
-        bs.setMagnification(Sampler.Value.LINEAR);
-        bs.setWrapS(Sampler.Value.CLAMP);
-        bs.setWrapT(Sampler.Value.CLAMP);
-        mSampler = bs.create();
-
-        ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
-        b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
-                     ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
-        mPFBackground = b.create();
-        mPFBackground.bindSampler(mSampler, 0);
-
-        mScript.set_gPFBackground(mPFBackground);
-    }
-
-    private void initPV() {
-        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
-        mPVBackground = pvb.create();
-
-        mPVA = new ProgramVertexFixedFunction.Constants(mRS);
-        ((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA);
-
-        mScript.set_gPVBackground(mPVBackground);
-    }
-
-    private void loadImage() {
-        mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
-                                                         Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                                                         Allocation.USAGE_GRAPHICS_TEXTURE);
-        mScript.set_gTGrid(mGridImage);
-    }
-
-    private void initTextAllocation(String fileName) {
-        String allocString = "Displaying file: " + fileName;
-        mTextAlloc = Allocation.createFromString(mRS, allocString, Allocation.USAGE_SCRIPT);
-        mScript.set_gTextAlloc(mTextAlloc);
-    }
-
-    private void initMeshes(FileA3D model) {
-        int numEntries = model.getIndexEntryCount();
-        int numMeshes = 0;
-        for (int i = 0; i < numEntries; i ++) {
-            FileA3D.IndexEntry entry = model.getIndexEntry(i);
-            if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
-                numMeshes ++;
-            }
-        }
-
-        if (numMeshes > 0) {
-            mMeshes = new ScriptField_MeshInfo(mRS, numMeshes);
-
-            for (int i = 0; i < numEntries; i ++) {
-                FileA3D.IndexEntry entry = model.getIndexEntry(i);
-                if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
-                    Mesh mesh = entry.getMesh();
-                    mMeshes.set_mMesh(i, mesh, false);
-                    mMeshes.set_mNumIndexSets(i, mesh.getPrimitiveCount(), false);
-                }
-            }
-            mMeshes.copyAll();
-        } else {
-            throw new RSRuntimeException("No valid meshes in file");
-        }
-
-        mScript.bind_gMeshes(mMeshes);
-        mScript.invoke_updateMeshInfo();
-    }
-
-    public void loadA3DFile(String path) {
-        FileA3D model = FileA3D.createFromFile(mRS, path);
-        initMeshes(model);
-        initTextAllocation(path);
-    }
-
-    private void initRS() {
-
-        mScript = new ScriptC_fbosync(mRS, mRes, R.raw.fbosync);
-
-        initPFS();
-        initPF();
-        initPV();
-
-        loadImage();
-
-        Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS));
-        b.setX(512).setY(512);
-        mOffscreen = Allocation.createTyped(mRS,
-                                            b.create(),
-                                            Allocation.USAGE_SCRIPT |
-                                            Allocation.USAGE_GRAPHICS_TEXTURE |
-                                            Allocation.USAGE_GRAPHICS_RENDER_TARGET);
-        mScript.set_gOffscreen(mOffscreen);
-
-        mReadBackTest = Allocation.createTyped(mRS,
-                                               b.create(),
-                                               Allocation.USAGE_SCRIPT |
-                                               Allocation.USAGE_GRAPHICS_TEXTURE);
-        mScript.set_gReadBackTest(mReadBackTest);
-
-        b = new Type.Builder(mRS,
-                             Element.createPixel(mRS, DataType.UNSIGNED_16,
-                             DataKind.PIXEL_DEPTH));
-        b.setX(512).setY(512);
-        mOffscreenDepth = Allocation.createTyped(mRS,
-                                                 b.create(),
-                                                 Allocation.USAGE_GRAPHICS_RENDER_TARGET);
-        mScript.set_gOffscreenDepth(mOffscreenDepth);
-
-        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
-        initMeshes(model);
-
-        mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
-        mScript.set_gItalic(mItalic);
-
-        initTextAllocation("R.raw.robot");
-
-        mRS.bindRootScript(mScript);
-    }
-}
-
-
-
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSyncView.java b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSyncView.java
deleted file mode 100644
index 6a85628..0000000
--- a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOSyncView.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.fbotest;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScriptGL;
-
-import android.content.Context;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.ScaleGestureDetector;
-import android.util.Log;
-
-public class FBOSyncView extends RSSurfaceView {
-
-    private RenderScriptGL mRS;
-    private FBOSyncRS mRender;
-
-    private ScaleGestureDetector mScaleDetector;
-
-    private static final int INVALID_POINTER_ID = -1;
-    private int mActivePointerId = INVALID_POINTER_ID;
-
-    public FBOSyncView(Context context) {
-        super(context);
-        ensureRenderScript();
-        mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
-    }
-
-    private void ensureRenderScript() {
-        if (mRS == null) {
-            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            sc.setDepth(16, 24);
-            mRS = createRenderScriptGL(sc);
-            mRender = new FBOSyncRS();
-            mRender.init(mRS, getResources());
-        }
-    }
-
-    @Override
-    protected void onAttachedToWindow() {
-        super.onAttachedToWindow();
-        ensureRenderScript();
-    }
-
-    @Override
-    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
-        super.surfaceChanged(holder, format, w, h);
-        mRender.surfaceChanged();
-    }
-
-    @Override
-    protected void onDetachedFromWindow() {
-        mRender = null;
-        if (mRS != null) {
-            mRS = null;
-            destroyRenderScriptGL();
-        }
-    }
-
-    public void loadA3DFile(String path) {
-        mRender.loadA3DFile(path);
-    }
-
-    @Override
-    public boolean onTouchEvent(MotionEvent ev) {
-        mScaleDetector.onTouchEvent(ev);
-
-        boolean ret = false;
-        float x = ev.getX();
-        float y = ev.getY();
-
-        final int action = ev.getAction();
-
-        switch (action & MotionEvent.ACTION_MASK) {
-        case MotionEvent.ACTION_DOWN: {
-            mRender.onActionDown(x, y);
-            mActivePointerId = ev.getPointerId(0);
-            ret = true;
-            break;
-        }
-        case MotionEvent.ACTION_MOVE: {
-            if (!mScaleDetector.isInProgress()) {
-                mRender.onActionMove(x, y);
-            }
-            mRender.onActionDown(x, y);
-            ret = true;
-            break;
-        }
-
-        case MotionEvent.ACTION_UP: {
-            mActivePointerId = INVALID_POINTER_ID;
-            break;
-        }
-
-        case MotionEvent.ACTION_CANCEL: {
-            mActivePointerId = INVALID_POINTER_ID;
-            break;
-        }
-
-        case MotionEvent.ACTION_POINTER_UP: {
-            final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
-                    >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
-            final int pointerId = ev.getPointerId(pointerIndex);
-            if (pointerId == mActivePointerId) {
-                // This was our active pointer going up. Choose a new
-                // active pointer and adjust accordingly.
-                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
-                x = ev.getX(newPointerIndex);
-                y = ev.getY(newPointerIndex);
-                mRender.onActionDown(x, y);
-                mActivePointerId = ev.getPointerId(newPointerIndex);
-            }
-            break;
-        }
-        }
-
-        return ret;
-    }
-
-    private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
-        @Override
-        public boolean onScale(ScaleGestureDetector detector) {
-            mRender.onActionScale(detector.getScaleFactor());
-            return true;
-        }
-    }
-}
-
-
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTest.java b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTest.java
deleted file mode 100644
index 72aa3ea..0000000
--- a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.fbotest;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
-import android.app.Activity;
-import android.content.res.Configuration;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.provider.Settings.System;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.MenuInflater;
-import android.view.Window;
-import android.widget.Button;
-import android.widget.ListView;
-import android.net.Uri;
-
-import java.lang.Runtime;
-
-public class FBOTest extends Activity {
-
-    private FBOTestView mView;
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        // Create our Preview view and set it as the content of our
-        // Activity
-        mView = new FBOTestView(this);
-        setContentView(mView);
-    }
-
-    @Override
-    protected void onResume() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
-        super.onResume();
-        mView.resume();
-    }
-
-    @Override
-    protected void onPause() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
-        super.onPause();
-        mView.pause();
-    }
-}
-
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTestRS.java b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTestRS.java
deleted file mode 100644
index 9e30c4b5..0000000
--- a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTestRS.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.fbotest;
-
-import java.io.Writer;
-
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.renderscript.Element.DataType;
-import android.renderscript.Element.DataKind;
-import android.renderscript.ProgramStore.DepthFunc;
-import android.renderscript.Type.Builder;
-import android.util.Log;
-
-
-public class FBOTestRS {
-
-    public FBOTestRS() {
-    }
-
-    public void init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-        initRS();
-    }
-
-    public void surfaceChanged() {
-        mRS.getWidth();
-        mRS.getHeight();
-    }
-
-    private Resources mRes;
-    private RenderScriptGL mRS;
-    private Sampler mSampler;
-    private ProgramStore mPSBackground;
-    private ProgramFragment mPFBackground;
-    private ProgramVertex mPVBackground;
-    private ProgramVertexFixedFunction.Constants mPVA;
-
-    private Allocation mGridImage;
-    private Allocation mOffscreen;
-    private Allocation mOffscreenDepth;
-    private Allocation mAllocPV;
-
-    private Font mItalic;
-    private Allocation mTextAlloc;
-
-    private ScriptField_MeshInfo mMeshes;
-    private ScriptC_fbotest mScript;
-
-
-    public void onActionDown(float x, float y) {
-        mScript.invoke_onActionDown(x, y);
-    }
-
-    public void onActionScale(float scale) {
-        mScript.invoke_onActionScale(scale);
-    }
-
-    public void onActionMove(float x, float y) {
-        mScript.invoke_onActionMove(x, y);
-    }
-
-    private void initPFS() {
-        ProgramStore.Builder b = new ProgramStore.Builder(mRS);
-
-        b.setDepthFunc(ProgramStore.DepthFunc.LESS);
-        b.setDitherEnabled(false);
-        b.setDepthMaskEnabled(true);
-        mPSBackground = b.create();
-
-        mScript.set_gPFSBackground(mPSBackground);
-    }
-
-    private void initPF() {
-        Sampler.Builder bs = new Sampler.Builder(mRS);
-        bs.setMinification(Sampler.Value.LINEAR);
-        bs.setMagnification(Sampler.Value.LINEAR);
-        bs.setWrapS(Sampler.Value.CLAMP);
-        bs.setWrapT(Sampler.Value.CLAMP);
-        mSampler = bs.create();
-
-        ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
-        b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
-                     ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
-        mPFBackground = b.create();
-        mPFBackground.bindSampler(mSampler, 0);
-
-        mScript.set_gPFBackground(mPFBackground);
-    }
-
-    private void initPV() {
-        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
-        mPVBackground = pvb.create();
-
-        mPVA = new ProgramVertexFixedFunction.Constants(mRS);
-        ((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA);
-
-        mScript.set_gPVBackground(mPVBackground);
-    }
-
-    private void loadImage() {
-        mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
-                                                         Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                                                         Allocation.USAGE_GRAPHICS_TEXTURE);
-        mScript.set_gTGrid(mGridImage);
-    }
-
-    private void initTextAllocation(String fileName) {
-        String allocString = "Displaying file: " + fileName;
-        mTextAlloc = Allocation.createFromString(mRS, allocString, Allocation.USAGE_SCRIPT);
-        mScript.set_gTextAlloc(mTextAlloc);
-    }
-
-    private void initMeshes(FileA3D model) {
-        int numEntries = model.getIndexEntryCount();
-        int numMeshes = 0;
-        for (int i = 0; i < numEntries; i ++) {
-            FileA3D.IndexEntry entry = model.getIndexEntry(i);
-            if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
-                numMeshes ++;
-            }
-        }
-
-        if (numMeshes > 0) {
-            mMeshes = new ScriptField_MeshInfo(mRS, numMeshes);
-
-            for (int i = 0; i < numEntries; i ++) {
-                FileA3D.IndexEntry entry = model.getIndexEntry(i);
-                if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
-                    Mesh mesh = entry.getMesh();
-                    mMeshes.set_mMesh(i, mesh, false);
-                    mMeshes.set_mNumIndexSets(i, mesh.getPrimitiveCount(), false);
-                }
-            }
-            mMeshes.copyAll();
-        } else {
-            throw new RSRuntimeException("No valid meshes in file");
-        }
-
-        mScript.bind_gMeshes(mMeshes);
-        mScript.invoke_updateMeshInfo();
-    }
-
-    public void loadA3DFile(String path) {
-        FileA3D model = FileA3D.createFromFile(mRS, path);
-        initMeshes(model);
-        initTextAllocation(path);
-    }
-
-    private void initRS() {
-
-        mScript = new ScriptC_fbotest(mRS, mRes, R.raw.fbotest);
-
-        initPFS();
-        initPF();
-        initPV();
-
-        loadImage();
-
-        Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS));
-        b.setX(512).setY(512);
-        mOffscreen = Allocation.createTyped(mRS,
-                                            b.create(),
-                                            Allocation.USAGE_GRAPHICS_TEXTURE |
-                                            Allocation.USAGE_GRAPHICS_RENDER_TARGET);
-        mScript.set_gOffscreen(mOffscreen);
-
-        b = new Type.Builder(mRS,
-                             Element.createPixel(mRS, DataType.UNSIGNED_16,
-                             DataKind.PIXEL_DEPTH));
-        b.setX(512).setY(512);
-        mOffscreenDepth = Allocation.createTyped(mRS,
-                                                 b.create(),
-                                                 Allocation.USAGE_GRAPHICS_RENDER_TARGET);
-        mScript.set_gOffscreenDepth(mOffscreenDepth);
-
-        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
-        initMeshes(model);
-
-        mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
-        mScript.set_gItalic(mItalic);
-
-        initTextAllocation("R.raw.robot");
-
-        mRS.bindRootScript(mScript);
-    }
-}
-
-
-
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTestView.java b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTestView.java
deleted file mode 100644
index c9598ee..0000000
--- a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTestView.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.fbotest;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScriptGL;
-
-import android.content.Context;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.ScaleGestureDetector;
-import android.util.Log;
-
-public class FBOTestView extends RSSurfaceView {
-
-    private RenderScriptGL mRS;
-    private FBOTestRS mRender;
-
-    private ScaleGestureDetector mScaleDetector;
-
-    private static final int INVALID_POINTER_ID = -1;
-    private int mActivePointerId = INVALID_POINTER_ID;
-
-    public FBOTestView(Context context) {
-        super(context);
-        ensureRenderScript();
-        mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
-    }
-
-    private void ensureRenderScript() {
-        if (mRS == null) {
-            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            sc.setDepth(16, 24);
-            mRS = createRenderScriptGL(sc);
-            mRender = new FBOTestRS();
-            mRender.init(mRS, getResources());
-        }
-    }
-
-    @Override
-    protected void onAttachedToWindow() {
-        super.onAttachedToWindow();
-        ensureRenderScript();
-    }
-
-    @Override
-    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
-        super.surfaceChanged(holder, format, w, h);
-        mRender.surfaceChanged();
-    }
-
-    @Override
-    protected void onDetachedFromWindow() {
-        mRender = null;
-        if (mRS != null) {
-            mRS = null;
-            destroyRenderScriptGL();
-        }
-    }
-
-    public void loadA3DFile(String path) {
-        mRender.loadA3DFile(path);
-    }
-
-    @Override
-    public boolean onTouchEvent(MotionEvent ev) {
-        mScaleDetector.onTouchEvent(ev);
-
-        boolean ret = false;
-        float x = ev.getX();
-        float y = ev.getY();
-
-        final int action = ev.getAction();
-
-        switch (action & MotionEvent.ACTION_MASK) {
-        case MotionEvent.ACTION_DOWN: {
-            mRender.onActionDown(x, y);
-            mActivePointerId = ev.getPointerId(0);
-            ret = true;
-            break;
-        }
-        case MotionEvent.ACTION_MOVE: {
-            if (!mScaleDetector.isInProgress()) {
-                mRender.onActionMove(x, y);
-            }
-            mRender.onActionDown(x, y);
-            ret = true;
-            break;
-        }
-
-        case MotionEvent.ACTION_UP: {
-            mActivePointerId = INVALID_POINTER_ID;
-            break;
-        }
-
-        case MotionEvent.ACTION_CANCEL: {
-            mActivePointerId = INVALID_POINTER_ID;
-            break;
-        }
-
-        case MotionEvent.ACTION_POINTER_UP: {
-            final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
-                    >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
-            final int pointerId = ev.getPointerId(pointerIndex);
-            if (pointerId == mActivePointerId) {
-                // This was our active pointer going up. Choose a new
-                // active pointer and adjust accordingly.
-                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
-                x = ev.getX(newPointerIndex);
-                y = ev.getY(newPointerIndex);
-                mRender.onActionDown(x, y);
-                mActivePointerId = ev.getPointerId(newPointerIndex);
-            }
-            break;
-        }
-        }
-
-        return ret;
-    }
-
-    private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
-        @Override
-        public boolean onScale(ScaleGestureDetector detector) {
-            mRender.onActionScale(detector.getScaleFactor());
-            return true;
-        }
-    }
-}
-
-
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/fbosync.rs b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/fbosync.rs
deleted file mode 100644
index 0c177ef..0000000
--- a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/fbosync.rs
+++ /dev/null
@@ -1,230 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.fbotest)
-
-#include "rs_graphics.rsh"
-
-rs_program_vertex gPVBackground;
-rs_program_fragment gPFBackground;
-
-rs_allocation gTGrid;
-
-rs_program_store gPFSBackground;
-
-rs_font gItalic;
-rs_allocation gTextAlloc;
-
-rs_allocation gOffscreen;
-rs_allocation gOffscreenDepth;
-rs_allocation gReadBackTest;
-
-typedef struct MeshInfo {
-    rs_mesh mMesh;
-    int mNumIndexSets;
-    float3 bBoxMin;
-    float3 bBoxMax;
-} MeshInfo_t;
-
-MeshInfo_t *gMeshes;
-
-static float3 gLookAt;
-
-static float gRotateX;
-static float gRotateY;
-static float gZoom;
-
-static float gLastX;
-static float gLastY;
-
-void onActionDown(float x, float y) {
-    gLastX = x;
-    gLastY = y;
-}
-
-void onActionScale(float scale) {
-
-    gZoom *= 1.0f / scale;
-    gZoom = max(0.1f, min(gZoom, 500.0f));
-}
-
-void onActionMove(float x, float y) {
-    float dx = gLastX - x;
-    float dy = gLastY - y;
-
-    if (fabs(dy) <= 2.0f) {
-        dy = 0.0f;
-    }
-    if (fabs(dx) <= 2.0f) {
-        dx = 0.0f;
-    }
-
-    gRotateY -= dx;
-    if (gRotateY > 360) {
-        gRotateY -= 360;
-    }
-    if (gRotateY < 0) {
-        gRotateY += 360;
-    }
-
-    gRotateX -= dy;
-    gRotateX = min(gRotateX, 80.0f);
-    gRotateX = max(gRotateX, -80.0f);
-
-    gLastX = x;
-    gLastY = y;
-}
-
-void init() {
-    gRotateX = 0.0f;
-    gRotateY = 0.0f;
-    gZoom = 50.0f;
-    gLookAt = 0.0f;
-}
-
-void updateMeshInfo() {
-    rs_allocation allMeshes = rsGetAllocation(gMeshes);
-    int size = rsAllocationGetDimX(allMeshes);
-    gLookAt = 0.0f;
-    float minX, minY, minZ, maxX, maxY, maxZ;
-    for (int i = 0; i < size; i++) {
-        MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
-        rsgMeshComputeBoundingBox(info->mMesh,
-                                  &minX, &minY, &minZ,
-                                  &maxX, &maxY, &maxZ);
-        info->bBoxMin = (float3){minX, minY, minZ};
-        info->bBoxMax = (float3){maxX, maxY, maxZ};
-        gLookAt += (info->bBoxMin + info->bBoxMax)*0.5f;
-    }
-    gLookAt = gLookAt / (float)size;
-}
-
-static void renderAllMeshes() {
-    rs_allocation allMeshes = rsGetAllocation(gMeshes);
-    int size = rsAllocationGetDimX(allMeshes);
-    gLookAt = 0.0f;
-    for (int i = 0; i < size; i++) {
-        MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
-        rsgDrawMesh(info->mMesh);
-    }
-}
-
-static void drawDescription() {
-    uint height = rsgGetHeight();
-    int left = 0, right = 0, top = 0, bottom = 0;
-
-    rsgBindFont(gItalic);
-
-    rsgMeasureText(gTextAlloc, &left, &right, &top, &bottom);
-    rsgDrawText(gTextAlloc, 2 -left, height - 2 + bottom);
-}
-
-static void renderOffscreen(bool useDepth) {
-
-    rsgBindColorTarget(gOffscreen, 0);
-    if (useDepth) {
-        rsgBindDepthTarget(gOffscreenDepth);
-        rsgClearDepth(1.0f);
-    } else {
-        rsgClearDepthTarget();
-    }
-    rsgClearColor(0.8f, 0.0f, 0.0f, 1.0f);
-
-    rsgBindProgramVertex(gPVBackground);
-    rs_matrix4x4 proj;
-    float aspect = (float)rsAllocationGetDimX(gOffscreen) / (float)rsAllocationGetDimY(gOffscreen);
-    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-
-    rsgBindProgramFragment(gPFBackground);
-    rsgBindProgramStore(gPFSBackground);
-    rsgBindTexture(gPFBackground, 0, gTGrid);
-
-    rs_matrix4x4 matrix;
-    rsMatrixLoadIdentity(&matrix);
-    // Position our models on the screen
-    rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
-    rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
-    rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    renderAllMeshes();
-
-    // Render into the frambuffer
-    rsgClearAllRenderTargets();
-}
-
-static void drawOffscreenResult(int posX, int posY, rs_allocation texture) {
-    // display the result
-    rs_matrix4x4 proj, matrix;
-    rsMatrixLoadOrtho(&proj, 0, rsgGetWidth(), rsgGetHeight(), 0, -500, 500);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-    rsMatrixLoadIdentity(&matrix);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-    rsgBindTexture(gPFBackground, 0, texture);
-    float startX = posX, startY = posY;
-    float width = 256, height = 256;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 1,
-                         startX, startY + height, 0, 0, 0,
-                         startX + width, startY + height, 0, 1, 0,
-                         startX + width, startY, 0, 1, 1);
-}
-
-int root(void) {
-
-    rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgClearDepth(1.0f);
-
-    renderOffscreen(true);
-    drawOffscreenResult(0, 0, gOffscreen);
-
-
-    uint32_t w = rsAllocationGetDimX(gOffscreen);
-    uint32_t h = rsAllocationGetDimY(gOffscreen);
-
-    rsgAllocationSyncAll(gOffscreen, RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET);
-
-    rsAllocationCopy2DRange(gReadBackTest, 0, 0, 0,
-                            RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, w, h,
-                            gOffscreen, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
-
-    rsgAllocationSyncAll(gReadBackTest);
-    drawOffscreenResult(0, 300, gReadBackTest);
-
-    rsgBindProgramVertex(gPVBackground);
-    rs_matrix4x4 proj;
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
-    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-
-    rsgBindProgramFragment(gPFBackground);
-    rsgBindProgramStore(gPFSBackground);
-    rsgBindTexture(gPFBackground, 0, gTGrid);
-
-    rs_matrix4x4 matrix;
-    rsMatrixLoadIdentity(&matrix);
-    // Position our models on the screen
-    rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
-    rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
-    rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    renderAllMeshes();
-
-    drawDescription();
-
-    return 0;
-}
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/fbotest.rs b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/fbotest.rs
deleted file mode 100644
index 13a3c85..0000000
--- a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/fbotest.rs
+++ /dev/null
@@ -1,219 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.fbotest)
-
-#include "rs_graphics.rsh"
-
-rs_program_vertex gPVBackground;
-rs_program_fragment gPFBackground;
-
-rs_allocation gTGrid;
-
-rs_program_store gPFSBackground;
-
-rs_font gItalic;
-rs_allocation gTextAlloc;
-
-rs_allocation gOffscreen;
-rs_allocation gOffscreenDepth;
-
-typedef struct MeshInfo {
-    rs_mesh mMesh;
-    int mNumIndexSets;
-    float3 bBoxMin;
-    float3 bBoxMax;
-} MeshInfo_t;
-
-MeshInfo_t *gMeshes;
-
-static float3 gLookAt;
-
-static float gRotateX;
-static float gRotateY;
-static float gZoom;
-
-static float gLastX;
-static float gLastY;
-
-void onActionDown(float x, float y) {
-    gLastX = x;
-    gLastY = y;
-}
-
-void onActionScale(float scale) {
-
-    gZoom *= 1.0f / scale;
-    gZoom = max(0.1f, min(gZoom, 500.0f));
-}
-
-void onActionMove(float x, float y) {
-    float dx = gLastX - x;
-    float dy = gLastY - y;
-
-    if (fabs(dy) <= 2.0f) {
-        dy = 0.0f;
-    }
-    if (fabs(dx) <= 2.0f) {
-        dx = 0.0f;
-    }
-
-    gRotateY -= dx;
-    if (gRotateY > 360) {
-        gRotateY -= 360;
-    }
-    if (gRotateY < 0) {
-        gRotateY += 360;
-    }
-
-    gRotateX -= dy;
-    gRotateX = min(gRotateX, 80.0f);
-    gRotateX = max(gRotateX, -80.0f);
-
-    gLastX = x;
-    gLastY = y;
-}
-
-void init() {
-    gRotateX = 0.0f;
-    gRotateY = 0.0f;
-    gZoom = 50.0f;
-    gLookAt = 0.0f;
-}
-
-void updateMeshInfo() {
-    rs_allocation allMeshes = rsGetAllocation(gMeshes);
-    int size = rsAllocationGetDimX(allMeshes);
-    gLookAt = 0.0f;
-    float minX, minY, minZ, maxX, maxY, maxZ;
-    for (int i = 0; i < size; i++) {
-        MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
-        rsgMeshComputeBoundingBox(info->mMesh,
-                                  &minX, &minY, &minZ,
-                                  &maxX, &maxY, &maxZ);
-        info->bBoxMin = (float3){minX, minY, minZ};
-        info->bBoxMax = (float3){maxX, maxY, maxZ};
-        gLookAt += (info->bBoxMin + info->bBoxMax)*0.5f;
-    }
-    gLookAt = gLookAt / (float)size;
-}
-
-static void renderAllMeshes() {
-    rs_allocation allMeshes = rsGetAllocation(gMeshes);
-    int size = rsAllocationGetDimX(allMeshes);
-    gLookAt = 0.0f;
-    for (int i = 0; i < size; i++) {
-        MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
-        rsgDrawMesh(info->mMesh);
-    }
-}
-
-static void drawDescription() {
-    uint height = rsgGetHeight();
-    int left = 0, right = 0, top = 0, bottom = 0;
-
-    rsgBindFont(gItalic);
-
-    rsgMeasureText(gTextAlloc, &left, &right, &top, &bottom);
-    rsgDrawText(gTextAlloc, 2 -left, height - 2 + bottom);
-}
-
-static void renderOffscreen(bool useDepth) {
-
-    rsgBindColorTarget(gOffscreen, 0);
-    if (useDepth) {
-        rsgBindDepthTarget(gOffscreenDepth);
-        rsgClearDepth(1.0f);
-    } else {
-        rsgClearDepthTarget();
-    }
-    rsgClearColor(0.8f, 0.8f, 0.8f, 1.0f);
-
-    rsgBindProgramVertex(gPVBackground);
-    rs_matrix4x4 proj;
-    float aspect = (float)rsAllocationGetDimX(gOffscreen) / (float)rsAllocationGetDimY(gOffscreen);
-    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-
-    rsgBindProgramFragment(gPFBackground);
-    rsgBindProgramStore(gPFSBackground);
-    rsgBindTexture(gPFBackground, 0, gTGrid);
-
-    rs_matrix4x4 matrix;
-    rsMatrixLoadIdentity(&matrix);
-    // Position our models on the screen
-    rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
-    rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
-    rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    renderAllMeshes();
-
-    // Render into the frambuffer
-    rsgClearAllRenderTargets();
-}
-
-static void drawOffscreenResult(int posX, int posY) {
-    // display the result
-    rs_matrix4x4 proj, matrix;
-    rsMatrixLoadOrtho(&proj, 0, rsgGetWidth(), rsgGetHeight(), 0, -500, 500);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-    rsMatrixLoadIdentity(&matrix);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-    rsgBindTexture(gPFBackground, 0, gOffscreen);
-    float startX = posX, startY = posY;
-    float width = 256, height = 256;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 1,
-                         startX, startY + height, 0, 0, 0,
-                         startX + width, startY + height, 0, 1, 0,
-                         startX + width, startY, 0, 1, 1);
-}
-
-int root(void) {
-
-    rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgClearDepth(1.0f);
-
-    renderOffscreen(true);
-    drawOffscreenResult(0, 0);
-
-    renderOffscreen(false);
-    drawOffscreenResult(0, 256);
-
-    rsgBindProgramVertex(gPVBackground);
-    rs_matrix4x4 proj;
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
-    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-
-    rsgBindProgramFragment(gPFBackground);
-    rsgBindProgramStore(gPFSBackground);
-    rsgBindTexture(gPFBackground, 0, gTGrid);
-
-    rs_matrix4x4 matrix;
-    rsMatrixLoadIdentity(&matrix);
-    // Position our models on the screen
-    rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
-    rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
-    rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    renderAllMeshes();
-
-    drawDescription();
-
-    return 0;
-}
diff --git a/tests/RenderScriptTests/HelloWorld/Android.mk b/tests/RenderScriptTests/HelloWorld/Android.mk
deleted file mode 100644
index c1c08ec..0000000
--- a/tests/RenderScriptTests/HelloWorld/Android.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Copyright (C) 2011 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
-
-LOCAL_PACKAGE_NAME := RsHelloWorld
-
-LOCAL_SDK_VERSION := 17
-
-include $(BUILD_PACKAGE)
diff --git a/tests/RenderScriptTests/HelloWorld/AndroidManifest.xml b/tests/RenderScriptTests/HelloWorld/AndroidManifest.xml
deleted file mode 100644
index 1d37dc9..0000000
--- a/tests/RenderScriptTests/HelloWorld/AndroidManifest.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
- 
-          http://www.apache.org/licenses/LICENSE-2.0
- 
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.example.android.rs.helloworld">
-    <uses-sdk android:minSdkVersion="11" />
-    <application android:label="RsHelloWorld"
-    android:icon="@drawable/test_pattern">
-        <activity android:name="HelloWorld"
-                  android:label="RsHelloWorld"
-                  android:theme="@android:style/Theme.Black.NoTitleBar">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-    </application>
-</manifest>
diff --git a/tests/RenderScriptTests/HelloWorld/_index.html b/tests/RenderScriptTests/HelloWorld/_index.html
deleted file mode 100644
index 4cab738..0000000
--- a/tests/RenderScriptTests/HelloWorld/_index.html
+++ /dev/null
@@ -1 +0,0 @@
-<p>A Renderscript graphics application that draws the text "Hello, World!" where the user touches.</p>
\ No newline at end of file
diff --git a/tests/RenderScriptTests/HelloWorld/res/drawable/test_pattern.png b/tests/RenderScriptTests/HelloWorld/res/drawable/test_pattern.png
deleted file mode 100644
index e7d1455..0000000
--- a/tests/RenderScriptTests/HelloWorld/res/drawable/test_pattern.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/HelloWorld/src/com/example/android/rs/helloworld/HelloWorld.java b/tests/RenderScriptTests/HelloWorld/src/com/example/android/rs/helloworld/HelloWorld.java
deleted file mode 100644
index 9b1697b..0000000
--- a/tests/RenderScriptTests/HelloWorld/src/com/example/android/rs/helloworld/HelloWorld.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.rs.helloworld;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-// Renderscript activity
-public class HelloWorld extends Activity {
-
-    // Custom view to use with RenderScript
-    private HelloWorldView mView;
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        // Create our view and set it as the content of our Activity
-        mView = new HelloWorldView(this);
-        setContentView(mView);
-    }
-
-    @Override
-    protected void onResume() {
-        // Ideally an app should implement onResume() and onPause()
-        // to take appropriate action when the activity loses focus
-        super.onResume();
-        mView.resume();
-    }
-
-    @Override
-    protected void onPause() {
-        // Ideally an app should implement onResume() and onPause()
-        // to take appropriate action when the activity loses focus
-        super.onPause();
-        mView.pause();
-    }
-
-}
-
diff --git a/tests/RenderScriptTests/HelloWorld/src/com/example/android/rs/helloworld/HelloWorldRS.java b/tests/RenderScriptTests/HelloWorld/src/com/example/android/rs/helloworld/HelloWorldRS.java
deleted file mode 100644
index 4316411..0000000
--- a/tests/RenderScriptTests/HelloWorld/src/com/example/android/rs/helloworld/HelloWorldRS.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.rs.helloworld;
-
-import android.content.res.Resources;
-import android.renderscript.*;
-
-// This is the renderer for the HelloWorldView
-public class HelloWorldRS {
-    private Resources mRes;
-    private RenderScriptGL mRS;
-
-    private ScriptC_helloworld mScript;
-
-    public HelloWorldRS() {
-    }
-
-    // This provides us with the renderscript context and resources that
-    // allow us to create the script that does rendering
-    public void init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-        initRS();
-    }
-
-    public void onActionDown(int x, int y) {
-        mScript.set_gTouchX(x);
-        mScript.set_gTouchY(y);
-    }
-
-    private void initRS() {
-        mScript = new ScriptC_helloworld(mRS, mRes, R.raw.helloworld);
-        mRS.bindRootScript(mScript);
-    }
-}
-
-
-
diff --git a/tests/RenderScriptTests/HelloWorld/src/com/example/android/rs/helloworld/HelloWorldView.java b/tests/RenderScriptTests/HelloWorld/src/com/example/android/rs/helloworld/HelloWorldView.java
deleted file mode 100644
index 557ebc5..0000000
--- a/tests/RenderScriptTests/HelloWorld/src/com/example/android/rs/helloworld/HelloWorldView.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.rs.helloworld;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScriptGL;
-
-import android.content.Context;
-import android.view.MotionEvent;
-
-public class HelloWorldView extends RSSurfaceView {
-    // Renderscipt context
-    private RenderScriptGL mRS;
-    // Script that does the rendering
-    private HelloWorldRS mRender;
-
-    public HelloWorldView(Context context) {
-        super(context);
-        ensureRenderScript();
-    }
-
-    private void ensureRenderScript() {
-        if (mRS == null) {
-            // Initialize renderscript with desired surface characteristics.
-            // In this case, just use the defaults
-            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            mRS = createRenderScriptGL(sc);
-            // Create an instance of the script that does the rendering
-            mRender = new HelloWorldRS();
-            mRender.init(mRS, getResources());
-        }
-    }
-
-    @Override
-    protected void onAttachedToWindow() {
-        super.onAttachedToWindow();
-        ensureRenderScript();
-    }
-
-    @Override
-    protected void onDetachedFromWindow() {
-        // Handle the system event and clean up
-        mRender = null;
-        if (mRS != null) {
-            mRS = null;
-            destroyRenderScriptGL();
-        }
-    }
-
-    @Override
-    public boolean onTouchEvent(MotionEvent ev) {
-        // Pass touch events from the system to the rendering script
-        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
-            mRender.onActionDown((int)ev.getX(), (int)ev.getY());
-            return true;
-        }
-
-        return false;
-    }
-}
-
-
diff --git a/tests/RenderScriptTests/HelloWorld/src/com/example/android/rs/helloworld/helloworld.rs b/tests/RenderScriptTests/HelloWorld/src/com/example/android/rs/helloworld/helloworld.rs
deleted file mode 100644
index bcf624e..0000000
--- a/tests/RenderScriptTests/HelloWorld/src/com/example/android/rs/helloworld/helloworld.rs
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-// Tell which java package name the reflected files should belong to
-#pragma rs java_package_name(com.example.android.rs.helloworld)
-
-// Built-in header with graphics API's
-#include "rs_graphics.rsh"
-
-// gTouchX and gTouchY are variables that will be reflected for use
-// by the java API. We can use them to notify the script of touch events.
-int gTouchX;
-int gTouchY;
-
-// This is invoked automatically when the script is created
-void init() {
-    gTouchX = 50.0f;
-    gTouchY = 50.0f;
-}
-
-int root(void) {
-
-    // Clear the background color
-    rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
-    // Tell the runtime what the font color should be
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    // Introuduce ourselves to the world by drawing a greeting
-    // at the position user touched on the screen
-    rsgDrawText("Hello World!", gTouchX, gTouchY);
-
-    // Return value tells RS roughly how often to redraw
-    // in this case 20 ms
-    return 20;
-}
diff --git a/tests/RenderScriptTests/MiscSamples/Android.mk b/tests/RenderScriptTests/MiscSamples/Android.mk
deleted file mode 100644
index ee3567b..0000000
--- a/tests/RenderScriptTests/MiscSamples/Android.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Copyright (C) 2008 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
-
-LOCAL_PACKAGE_NAME := RsMiscSamples
-
-LOCAL_SDK_VERSION := 17
-
-include $(BUILD_PACKAGE)
diff --git a/tests/RenderScriptTests/MiscSamples/AndroidManifest.xml b/tests/RenderScriptTests/MiscSamples/AndroidManifest.xml
deleted file mode 100644
index 08a3976..0000000
--- a/tests/RenderScriptTests/MiscSamples/AndroidManifest.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.example.android.rs.miscsamples">
-    <uses-sdk android:minSdkVersion="11" />
-    <application android:label="RsMiscSamples"
-    android:icon="@drawable/test_pattern">
-        <activity android:name="RsList"
-                  android:label="RsList"
-                  android:theme="@android:style/Theme.Black.NoTitleBar">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-        
-        <activity android:name="RsRenderStates"
-                  android:label="RsStates"
-                  android:theme="@android:style/Theme.Black.NoTitleBar">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-    </application>
-</manifest>
diff --git a/tests/RenderScriptTests/MiscSamples/_index.html b/tests/RenderScriptTests/MiscSamples/_index.html
deleted file mode 100644
index 5872431..0000000
--- a/tests/RenderScriptTests/MiscSamples/_index.html
+++ /dev/null
@@ -1 +0,0 @@
-<p>A set of samples that demonstrate how to use various features of the Renderscript APIs.</p>
\ No newline at end of file
diff --git a/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/checker.png b/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/checker.png
deleted file mode 100644
index b631e1e..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/checker.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/cubemap_test.png b/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/cubemap_test.png
deleted file mode 100644
index baf35d0..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/cubemap_test.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/data.png b/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/data.png
deleted file mode 100644
index 8e34714..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/data.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/leaf.png b/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/leaf.png
deleted file mode 100644
index 3cd3775..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/leaf.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/test_pattern.png b/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/test_pattern.png
deleted file mode 100644
index e7d1455..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/test_pattern.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/torusmap.png b/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/torusmap.png
deleted file mode 100644
index 1e08f3b..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/drawable-nodpi/torusmap.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/MiscSamples/res/raw/multitexf.glsl b/tests/RenderScriptTests/MiscSamples/res/raw/multitexf.glsl
deleted file mode 100644
index e492a47..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/raw/multitexf.glsl
+++ /dev/null
@@ -1,13 +0,0 @@
-varying vec2 varTex0;
-
-void main() {
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col0 = texture2D(UNI_Tex0, t0).rgba;
-   lowp vec4 col1 = texture2D(UNI_Tex1, t0*4.0).rgba;
-   lowp vec4 col2 = texture2D(UNI_Tex2, t0).rgba;
-   col0.xyz = col0.xyz*col1.xyz*1.5;
-   col0.xyz = mix(col0.xyz, col2.xyz, col2.w);
-   col0.w = 0.5;
-   gl_FragColor = col0;
-}
-
diff --git a/tests/RenderScriptTests/MiscSamples/res/raw/shader2f.glsl b/tests/RenderScriptTests/MiscSamples/res/raw/shader2f.glsl
deleted file mode 100644
index 5fc05f1..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/raw/shader2f.glsl
+++ /dev/null
@@ -1,29 +0,0 @@
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-void main() {
-
-   vec3 V = normalize(-varWorldPos.xyz);
-   vec3 worldNorm = normalize(varWorldNormal);
-
-   vec3 light0Vec = normalize(UNI_light0_Posision.xyz - varWorldPos);
-   vec3 light0R = -reflect(light0Vec, worldNorm);
-   float light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0) * UNI_light0_Diffuse;
-   float light0Spec = clamp(dot(light0R, V), 0.001, 1.0);
-   float light0_Specular = pow(light0Spec, UNI_light0_CosinePower) * UNI_light0_Specular;
-
-   vec3 light1Vec = normalize(UNI_light1_Posision.xyz - varWorldPos);
-   vec3 light1R = reflect(light1Vec, worldNorm);
-   float light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0) * UNI_light1_Diffuse;
-   float light1Spec = clamp(dot(light1R, V), 0.001, 1.0);
-   float light1_Specular = pow(light1Spec, UNI_light1_CosinePower) * UNI_light1_Specular;
-
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col = texture2D(UNI_Tex0, t0).rgba;
-   col.xyz = col.xyz * (light0_Diffuse * UNI_light0_DiffuseColor.xyz + light1_Diffuse * UNI_light1_DiffuseColor.xyz);
-   col.xyz += light0_Specular * UNI_light0_SpecularColor.xyz;
-   col.xyz += light1_Specular * UNI_light1_SpecularColor.xyz;
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/MiscSamples/res/raw/shader2movev.glsl b/tests/RenderScriptTests/MiscSamples/res/raw/shader2movev.glsl
deleted file mode 100644
index a2c807e..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/raw/shader2movev.glsl
+++ /dev/null
@@ -1,21 +0,0 @@
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-// This is where actual shader code begins
-void main() {
-   vec4 objPos = ATTRIB_position;
-   vec3 oldPos = objPos.xyz;
-   objPos.xyz += 0.1*sin(objPos.xyz*2.0 + UNI_time);
-   objPos.xyz += 0.05*sin(objPos.xyz*4.0 + UNI_time*0.5);
-   objPos.xyz += 0.02*sin(objPos.xyz*7.0 + UNI_time*0.75);
-   vec4 worldPos = UNI_model * objPos;
-   gl_Position = UNI_proj * worldPos;
-
-   mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
-   vec3 worldNorm = model3 * (ATTRIB_normal + oldPos - objPos.xyz);
-
-   varWorldPos = worldPos.xyz;
-   varWorldNormal = worldNorm;
-   varTex0 = ATTRIB_texture0;
-}
diff --git a/tests/RenderScriptTests/MiscSamples/res/raw/shader2v.glsl b/tests/RenderScriptTests/MiscSamples/res/raw/shader2v.glsl
deleted file mode 100644
index e6885a3..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/raw/shader2v.glsl
+++ /dev/null
@@ -1,17 +0,0 @@
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-// This is where actual shader code begins
-void main() {
-   vec4 objPos = ATTRIB_position;
-   vec4 worldPos = UNI_model * objPos;
-   gl_Position = UNI_proj * worldPos;
-
-   mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
-   vec3 worldNorm = model3 * ATTRIB_normal;
-
-   varWorldPos = worldPos.xyz;
-   varWorldNormal = worldNorm;
-   varTex0 = ATTRIB_texture0;
-}
diff --git a/tests/RenderScriptTests/MiscSamples/res/raw/shaderarrayf.glsl b/tests/RenderScriptTests/MiscSamples/res/raw/shaderarrayf.glsl
deleted file mode 100644
index 238ecad..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/raw/shaderarrayf.glsl
+++ /dev/null
@@ -1,16 +0,0 @@
-
-varying lowp float light0_Diffuse;
-varying lowp float light0_Specular;
-varying lowp float light1_Diffuse;
-varying lowp float light1_Specular;
-varying vec2 varTex0;
-
-void main() {
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col = texture2D(UNI_Tex0, t0).rgba;
-   col.xyz = col.xyz * (light0_Diffuse * UNI_light_DiffuseColor[0].xyz + light1_Diffuse * UNI_light_DiffuseColor[1].xyz);
-   col.xyz += light0_Specular * UNI_light_SpecularColor[0].xyz;
-   col.xyz += light1_Specular * UNI_light_SpecularColor[1].xyz;
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/MiscSamples/res/raw/shaderarrayv.glsl b/tests/RenderScriptTests/MiscSamples/res/raw/shaderarrayv.glsl
deleted file mode 100644
index 7a1310a..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/raw/shaderarrayv.glsl
+++ /dev/null
@@ -1,32 +0,0 @@
-varying float light0_Diffuse;
-varying float light0_Specular;
-varying float light1_Diffuse;
-varying float light1_Specular;
-varying vec2 varTex0;
-
-// This is where actual shader code begins
-void main() {
-   vec4 worldPos = UNI_model[0] * ATTRIB_position;
-   worldPos = UNI_model[1] * worldPos;
-   gl_Position = UNI_proj * worldPos;
-
-   mat4 model0 = UNI_model[0];
-   mat3 model3 = mat3(model0[0].xyz, model0[1].xyz, model0[2].xyz);
-   vec3 worldNorm = model3 * ATTRIB_normal;
-   vec3 V = normalize(-worldPos.xyz);
-
-   vec3 light0Vec = normalize(UNI_light_Posision[0].xyz - worldPos.xyz);
-   vec3 light0R = -reflect(light0Vec, worldNorm);
-   light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0) * UNI_light_Diffuse[0];
-   float light0Spec = clamp(dot(light0R, V), 0.001, 1.0);
-   light0_Specular = pow(light0Spec, UNI_light_CosinePower[0]) * UNI_light_Specular[0];
-
-   vec3 light1Vec = normalize(UNI_light_Posision[1].xyz - worldPos.xyz);
-   vec3 light1R = reflect(light1Vec, worldNorm);
-   light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0) * UNI_light_Diffuse[1];
-   float light1Spec = clamp(dot(light1R, V), 0.001, 1.0);
-   light1_Specular = pow(light1Spec, UNI_light_CosinePower[1]) * UNI_light_Specular[1];
-
-   gl_PointSize = 1.0;
-   varTex0 = ATTRIB_texture0;
-}
diff --git a/tests/RenderScriptTests/MiscSamples/res/raw/shadercubef.glsl b/tests/RenderScriptTests/MiscSamples/res/raw/shadercubef.glsl
deleted file mode 100644
index 15696a4..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/raw/shadercubef.glsl
+++ /dev/null
@@ -1,8 +0,0 @@
-
-varying vec3 worldNormal;
-
-void main() {
-   lowp vec4 col = textureCube(UNI_Tex0, worldNormal);
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/MiscSamples/res/raw/shadercubev.glsl b/tests/RenderScriptTests/MiscSamples/res/raw/shadercubev.glsl
deleted file mode 100644
index 70f5cd6..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/raw/shadercubev.glsl
+++ /dev/null
@@ -1,10 +0,0 @@
-varying vec3 worldNormal;
-
-// This is where actual shader code begins
-void main() {
-   vec4 worldPos = UNI_model * ATTRIB_position;
-   gl_Position = UNI_proj * worldPos;
-
-   mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
-   worldNormal = model3 * ATTRIB_normal;
-}
diff --git a/tests/RenderScriptTests/MiscSamples/res/raw/shaderf.glsl b/tests/RenderScriptTests/MiscSamples/res/raw/shaderf.glsl
deleted file mode 100644
index d56e203..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/raw/shaderf.glsl
+++ /dev/null
@@ -1,16 +0,0 @@
-
-varying lowp float light0_Diffuse;
-varying lowp float light0_Specular;
-varying lowp float light1_Diffuse;
-varying lowp float light1_Specular;
-varying vec2 varTex0;
-
-void main() {
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col = texture2D(UNI_Tex0, t0).rgba;
-   col.xyz = col.xyz * (light0_Diffuse * UNI_light0_DiffuseColor.xyz + light1_Diffuse * UNI_light1_DiffuseColor.xyz);
-   col.xyz += light0_Specular * UNI_light0_SpecularColor.xyz;
-   col.xyz += light1_Specular * UNI_light1_SpecularColor.xyz;
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/MiscSamples/res/raw/shaderv.glsl b/tests/RenderScriptTests/MiscSamples/res/raw/shaderv.glsl
deleted file mode 100644
index f7d01de..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/raw/shaderv.glsl
+++ /dev/null
@@ -1,30 +0,0 @@
-varying float light0_Diffuse;
-varying float light0_Specular;
-varying float light1_Diffuse;
-varying float light1_Specular;
-varying vec2 varTex0;
-
-// This is where actual shader code begins
-void main() {
-   vec4 worldPos = UNI_model * ATTRIB_position;
-   gl_Position = UNI_proj * worldPos;
-
-   mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
-   vec3 worldNorm = model3 * ATTRIB_normal;
-   vec3 V = normalize(-worldPos.xyz);
-
-   vec3 light0Vec = normalize(UNI_light0_Posision.xyz - worldPos.xyz);
-   vec3 light0R = -reflect(light0Vec, worldNorm);
-   light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0) * UNI_light0_Diffuse;
-   float light0Spec = clamp(dot(light0R, V), 0.001, 1.0);
-   light0_Specular = pow(light0Spec, UNI_light0_CosinePower) * UNI_light0_Specular;
-
-   vec3 light1Vec = normalize(UNI_light1_Posision.xyz - worldPos.xyz);
-   vec3 light1R = reflect(light1Vec, worldNorm);
-   light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0) * UNI_light1_Diffuse;
-   float light1Spec = clamp(dot(light1R, V), 0.001, 1.0);
-   light1_Specular = pow(light1Spec, UNI_light1_CosinePower) * UNI_light1_Specular;
-
-   gl_PointSize = 1.0;
-   varTex0 = ATTRIB_texture0;
-}
diff --git a/tests/RenderScriptTests/MiscSamples/res/raw/torus.a3d b/tests/RenderScriptTests/MiscSamples/res/raw/torus.a3d
deleted file mode 100644
index 0322b01..0000000
--- a/tests/RenderScriptTests/MiscSamples/res/raw/torus.a3d
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsList.java b/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsList.java
deleted file mode 100644
index dade3b3..0000000
--- a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsList.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.rs.miscsamples;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-public class RsList extends Activity {
-
-    private RsListView mView;
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        // Create our Preview view and set it as the content of our
-        // Activity
-        mView = new RsListView(this);
-        setContentView(mView);
-    }
-
-    @Override
-    protected void onResume() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity loses focus
-        super.onResume();
-        mView.resume();
-    }
-
-    @Override
-    protected void onPause() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity loses focus
-        super.onPause();
-        mView.pause();
-    }
-
-}
-
diff --git a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsListRS.java b/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsListRS.java
deleted file mode 100644
index eeb2480..0000000
--- a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsListRS.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.rs.miscsamples;
-
-import java.io.Writer;
-import java.util.Vector;
-
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.renderscript.ProgramStore.DepthFunc;
-import android.util.Log;
-
-
-public class RsListRS {
-
-    private final int STATE_LAST_FOCUS = 1;
-
-    private static final String[] DATA_LIST = {
-    "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
-    "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
-    "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
-    "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",
-    "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia",
-    "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil",
-    "British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria",
-    "Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
-    "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
-    "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
-    "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
-    "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
-    "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
-    "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
-    "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia",
-    "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar",
-    "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau",
-    "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary",
-    "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica",
-    "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos",
-    "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
-    "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands",
-    "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
-    "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia",
-    "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand",
-    "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas",
-    "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru",
-    "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar",
-    "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena",
-    "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon",
-    "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal",
-    "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
-    "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea",
-    "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden",
-    "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas",
-    "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey",
-    "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda",
-    "Ukraine", "United Arab Emirates", "United Kingdom",
-    "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan",
-    "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara",
-    "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
-    };
-
-    public RsListRS() {
-    }
-
-    public void init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-        initRS();
-    }
-
-    private Resources mRes;
-    private RenderScriptGL mRS;
-    private Font mItalic;
-
-    ScriptField_ListAllocs_s mListAllocs;
-
-    private ScriptC_rslist mScript;
-
-    int mLastX;
-    int mLastY;
-
-    public void onActionDown(int x, int y) {
-        mScript.set_gDY(0.0f);
-
-        mLastX = x;
-        mLastY = y;
-    }
-
-    public void onActionMove(int x, int y) {
-        int dx = mLastX - x;
-        int dy = mLastY - y;
-
-        if (Math.abs(dy) <= 2) {
-            dy = 0;
-        }
-
-        mScript.set_gDY(dy);
-
-        mLastX = x;
-        mLastY = y;
-    }
-
-    private void initRS() {
-
-        mScript = new ScriptC_rslist(mRS, mRes, R.raw.rslist);
-
-        mListAllocs = new ScriptField_ListAllocs_s(mRS, DATA_LIST.length);
-        for (int i = 0; i < DATA_LIST.length; i ++) {
-            ScriptField_ListAllocs_s.Item listElem = new ScriptField_ListAllocs_s.Item();
-            listElem.text = Allocation.createFromString(mRS, DATA_LIST[i], Allocation.USAGE_SCRIPT);
-            mListAllocs.set(listElem, i, false);
-        }
-
-        mListAllocs.copyAll();
-
-        mScript.bind_gList(mListAllocs);
-
-        mItalic = Font.create(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8);
-        mScript.set_gItalic(mItalic);
-
-        mRS.bindRootScript(mScript);
-    }
-}
-
-
-
diff --git a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsListView.java b/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsListView.java
deleted file mode 100644
index db6e6c5..0000000
--- a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsListView.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.rs.miscsamples;
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScriptGL;
-
-import android.content.Context;
-import android.view.MotionEvent;
-
-public class RsListView extends RSSurfaceView {
-
-    public RsListView(Context context) {
-        super(context);
-        ensureRenderScript();
-    }
-
-    private RenderScriptGL mRS;
-    private RsListRS mRender;
-
-    private void ensureRenderScript() {
-        if (mRS == null) {
-            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            mRS = createRenderScriptGL(sc);
-            mRender = new RsListRS();
-            mRender.init(mRS, getResources());
-        }
-    }
-
-    @Override
-    protected void onAttachedToWindow() {
-        super.onAttachedToWindow();
-        ensureRenderScript();
-    }
-
-    @Override
-    protected void onDetachedFromWindow() {
-        mRender = null;
-        if (mRS != null) {
-            mRS = null;
-            destroyRenderScriptGL();
-        }
-    }
-
-    @Override
-    public boolean onTouchEvent(MotionEvent ev)
-    {
-        boolean ret = false;
-        int act = ev.getAction();
-        if (act == MotionEvent.ACTION_DOWN) {
-            mRender.onActionDown((int)ev.getX(), (int)ev.getY());
-            ret = true;
-        } else if (act == MotionEvent.ACTION_MOVE) {
-            mRender.onActionMove((int)ev.getX(), (int)ev.getY());
-            ret = true;
-        }
-
-        return ret;
-    }
-}
-
-
diff --git a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStates.java b/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStates.java
deleted file mode 100644
index f4ea76e..0000000
--- a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStates.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.rs.miscsamples;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-public class RsRenderStates extends Activity {
-
-    private RsRenderStatesView mView;
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        // Create our Preview view and set it as the content of our
-        // Activity
-        mView = new RsRenderStatesView(this);
-        setContentView(mView);
-    }
-
-    @Override
-    protected void onResume() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
-        super.onResume();
-        mView.resume();
-    }
-
-    @Override
-    protected void onPause() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
-        super.onPause();
-        mView.pause();
-    }
-
-}
-
diff --git a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStatesRS.java b/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStatesRS.java
deleted file mode 100644
index 0e319fe..0000000
--- a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStatesRS.java
+++ /dev/null
@@ -1,422 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.rs.miscsamples;
-
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.renderscript.*;
-import android.renderscript.Font.Style;
-import android.renderscript.Program.TextureType;
-import android.renderscript.ProgramStore.DepthFunc;
-import android.renderscript.ProgramStore.BlendSrcFunc;
-import android.renderscript.ProgramStore.BlendDstFunc;
-import android.renderscript.Sampler.Value;
-import android.util.Log;
-
-
-public class RsRenderStatesRS {
-
-    int mWidth;
-    int mHeight;
-
-    public RsRenderStatesRS() {
-    }
-
-    public void init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mWidth = mRS.getWidth();
-        mHeight = mRS.getHeight();
-        mRes = res;
-        mOptionsARGB.inScaled = false;
-        mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
-        mMode = 0;
-        mMaxModes = 0;
-        initRS();
-    }
-
-    public void surfaceChanged() {
-        mWidth = mRS.getWidth();
-        mHeight = mRS.getHeight();
-
-        Matrix4f proj = new Matrix4f();
-        proj.loadOrthoWindow(mWidth, mHeight);
-        mPVA.setProjection(proj);
-    }
-
-    private Resources mRes;
-    private RenderScriptGL mRS;
-
-    private Sampler mLinearClamp;
-    private Sampler mLinearWrap;
-    private Sampler mMipLinearWrap;
-    private Sampler mNearestClamp;
-    private Sampler mMipLinearAniso8;
-    private Sampler mMipLinearAniso15;
-
-    private ProgramStore mProgStoreBlendNoneDepth;
-    private ProgramStore mProgStoreBlendNone;
-    private ProgramStore mProgStoreBlendAlpha;
-    private ProgramStore mProgStoreBlendAdd;
-
-    private ProgramFragment mProgFragmentTexture;
-    private ProgramFragment mProgFragmentColor;
-
-    private ProgramVertex mProgVertex;
-    private ProgramVertexFixedFunction.Constants mPVA;
-
-    // Custom shaders
-    private ProgramVertex mProgVertexCustom;
-    private ProgramFragment mProgFragmentCustom;
-    private ProgramFragment mProgFragmentMultitex;
-    private ScriptField_VertexShaderConstants_s mVSConst;
-    private ScriptField_VertexShaderConstants2_s mVSConst2;
-    private ScriptField_FragentShaderConstants_s mFSConst;
-    private ScriptField_FragentShaderConstants2_s mFSConst2;
-
-    private ProgramVertex mProgVertexCustom2;
-    private ProgramFragment mProgFragmentCustom2;
-
-    private ProgramVertex mProgVertexCube;
-    private ProgramFragment mProgFragmentCube;
-
-    private ProgramRaster mCullBack;
-    private ProgramRaster mCullFront;
-    private ProgramRaster mCullNone;
-
-    private Allocation mTexTorus;
-    private Allocation mTexOpaque;
-    private Allocation mTexTransparent;
-    private Allocation mTexChecker;
-    private Allocation mTexCube;
-
-    private Mesh mMbyNMesh;
-    private Mesh mTorus;
-
-    Font mFontSans;
-    Font mFontSerif;
-    Font mFontSerifBold;
-    Font mFontSerifItalic;
-    Font mFontSerifBoldItalic;
-    Font mFontMono;
-    private Allocation mTextAlloc;
-
-    private ScriptC_rsrenderstates mScript;
-
-    private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
-
-    int mMode;
-    int mMaxModes;
-
-    public void onActionDown(int x, int y) {
-        mMode ++;
-        mMode = mMode % mMaxModes;
-        mScript.set_gDisplayMode(mMode);
-    }
-
-    ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) {
-        ProgramStore.Builder builder = new ProgramStore.Builder(rs);
-        builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
-        builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
-        builder.setDitherEnabled(false);
-        builder.setDepthMaskEnabled(false);
-        return builder.create();
-    }
-
-    private Mesh getMbyNMesh(float width, float height, int wResolution, int hResolution) {
-
-        Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS,
-                                           2, Mesh.TriangleMeshBuilder.TEXTURE_0);
-
-        for (int y = 0; y <= hResolution; y++) {
-            final float normalizedY = (float)y / hResolution;
-            final float yOffset = (normalizedY - 0.5f) * height;
-            for (int x = 0; x <= wResolution; x++) {
-                float normalizedX = (float)x / wResolution;
-                float xOffset = (normalizedX - 0.5f) * width;
-                tmb.setTexture(normalizedX, normalizedY);
-                tmb.addVertex(xOffset, yOffset);
-             }
-        }
-
-        for (int y = 0; y < hResolution; y++) {
-            final int curY = y * (wResolution + 1);
-            final int belowY = (y + 1) * (wResolution + 1);
-            for (int x = 0; x < wResolution; x++) {
-                int curV = curY + x;
-                int belowV = belowY + x;
-                tmb.addTriangle(curV, belowV, curV + 1);
-                tmb.addTriangle(belowV, belowV + 1, curV + 1);
-            }
-        }
-
-        return tmb.create(true);
-    }
-
-    private void initProgramStore() {
-        // Use stock the stock program store object
-        mProgStoreBlendNoneDepth = ProgramStore.BLEND_NONE_DEPTH_TEST(mRS);
-        mProgStoreBlendNone = ProgramStore.BLEND_NONE_DEPTH_NONE(mRS);
-
-        // Create a custom program store
-        ProgramStore.Builder builder = new ProgramStore.Builder(mRS);
-        builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
-        builder.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
-                             ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
-        builder.setDitherEnabled(false);
-        builder.setDepthMaskEnabled(false);
-        mProgStoreBlendAlpha = builder.create();
-
-        mProgStoreBlendAdd = BLEND_ADD_DEPTH_NONE(mRS);
-
-        mScript.set_gProgStoreBlendNoneDepth(mProgStoreBlendNoneDepth);
-        mScript.set_gProgStoreBlendNone(mProgStoreBlendNone);
-        mScript.set_gProgStoreBlendAlpha(mProgStoreBlendAlpha);
-        mScript.set_gProgStoreBlendAdd(mProgStoreBlendAdd);
-    }
-
-    private void initProgramFragment() {
-
-        ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
-        texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
-                              ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
-        mProgFragmentTexture = texBuilder.create();
-        mProgFragmentTexture.bindSampler(mLinearClamp, 0);
-
-        ProgramFragmentFixedFunction.Builder colBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
-        colBuilder.setVaryingColor(false);
-        mProgFragmentColor = colBuilder.create();
-
-        mScript.set_gProgFragmentColor(mProgFragmentColor);
-        mScript.set_gProgFragmentTexture(mProgFragmentTexture);
-    }
-
-    private void initProgramVertex() {
-        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
-        mProgVertex = pvb.create();
-
-        mPVA = new ProgramVertexFixedFunction.Constants(mRS);
-        ((ProgramVertexFixedFunction)mProgVertex).bindConstants(mPVA);
-        Matrix4f proj = new Matrix4f();
-        proj.loadOrthoWindow(mWidth, mHeight);
-        mPVA.setProjection(proj);
-
-        mScript.set_gProgVertex(mProgVertex);
-    }
-
-    private void initCustomShaders() {
-        mVSConst = new ScriptField_VertexShaderConstants_s(mRS, 1);
-        mVSConst2 = new ScriptField_VertexShaderConstants2_s(mRS, 1);
-        mFSConst = new ScriptField_FragentShaderConstants_s(mRS, 1);
-        mFSConst2 = new ScriptField_FragentShaderConstants2_s(mRS, 1);
-
-        mScript.bind_gVSConstants(mVSConst);
-        mScript.bind_gVSConstants2(mVSConst2);
-        mScript.bind_gFSConstants(mFSConst);
-        mScript.bind_gFSConstants2(mFSConst2);
-
-        // Initialize the shader builder
-        ProgramVertex.Builder pvbCustom = new ProgramVertex.Builder(mRS);
-        // Specify the resource that contains the shader string
-        pvbCustom.setShader(mRes, R.raw.shaderv);
-        // Use a script field to spcify the input layout
-        pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
-        // Define the constant input layout
-        pvbCustom.addConstant(mVSConst.getAllocation().getType());
-        mProgVertexCustom = pvbCustom.create();
-        // Bind the source of constant data
-        mProgVertexCustom.bindConstants(mVSConst.getAllocation(), 0);
-
-        ProgramFragment.Builder pfbCustom = new ProgramFragment.Builder(mRS);
-        // Specify the resource that contains the shader string
-        pfbCustom.setShader(mRes, R.raw.shaderf);
-        //Tell the builder how many textures we have
-        pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
-        // Define the constant input layout
-        pfbCustom.addConstant(mFSConst.getAllocation().getType());
-        mProgFragmentCustom = pfbCustom.create();
-        // Bind the source of constant data
-        mProgFragmentCustom.bindConstants(mFSConst.getAllocation(), 0);
-
-        pvbCustom = new ProgramVertex.Builder(mRS);
-        pvbCustom.setShader(mRes, R.raw.shaderarrayv);
-        pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
-        pvbCustom.addConstant(mVSConst2.getAllocation().getType());
-        mProgVertexCustom2 = pvbCustom.create();
-        mProgVertexCustom2.bindConstants(mVSConst2.getAllocation(), 0);
-
-        pfbCustom = new ProgramFragment.Builder(mRS);
-        pfbCustom.setShader(mRes, R.raw.shaderarrayf);
-        pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
-        pfbCustom.addConstant(mFSConst2.getAllocation().getType());
-        mProgFragmentCustom2 = pfbCustom.create();
-        mProgFragmentCustom2.bindConstants(mFSConst2.getAllocation(), 0);
-
-        // Cubemap test shaders
-        pvbCustom = new ProgramVertex.Builder(mRS);
-        pvbCustom.setShader(mRes, R.raw.shadercubev);
-        pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
-        pvbCustom.addConstant(mVSConst.getAllocation().getType());
-        mProgVertexCube = pvbCustom.create();
-        mProgVertexCube.bindConstants(mVSConst.getAllocation(), 0);
-
-        pfbCustom = new ProgramFragment.Builder(mRS);
-        pfbCustom.setShader(mRes, R.raw.shadercubef);
-        pfbCustom.addTexture(Program.TextureType.TEXTURE_CUBE);
-        mProgFragmentCube = pfbCustom.create();
-
-        pfbCustom = new ProgramFragment.Builder(mRS);
-        pfbCustom.setShader(mRes, R.raw.multitexf);
-        for (int texCount = 0; texCount < 3; texCount ++) {
-            pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
-        }
-        mProgFragmentMultitex = pfbCustom.create();
-
-        mScript.set_gProgVertexCustom(mProgVertexCustom);
-        mScript.set_gProgFragmentCustom(mProgFragmentCustom);
-        mScript.set_gProgVertexCustom2(mProgVertexCustom2);
-        mScript.set_gProgFragmentCustom2(mProgFragmentCustom2);
-        mScript.set_gProgVertexCube(mProgVertexCube);
-        mScript.set_gProgFragmentCube(mProgFragmentCube);
-        mScript.set_gProgFragmentMultitex(mProgFragmentMultitex);
-    }
-
-    private Allocation loadTextureRGB(int id) {
-        return Allocation.createFromBitmapResource(mRS, mRes, id,
-                                                   Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                                                   Allocation.USAGE_GRAPHICS_TEXTURE);
-    }
-
-    private Allocation loadTextureARGB(int id) {
-        Bitmap b = BitmapFactory.decodeResource(mRes, id, mOptionsARGB);
-        return Allocation.createFromBitmap(mRS, b,
-                                           Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                                           Allocation.USAGE_GRAPHICS_TEXTURE);
-    }
-
-    private void loadImages() {
-        mTexTorus = loadTextureRGB(R.drawable.torusmap);
-        mTexOpaque = loadTextureRGB(R.drawable.data);
-        mTexTransparent = loadTextureARGB(R.drawable.leaf);
-        mTexChecker = loadTextureRGB(R.drawable.checker);
-        Bitmap b = BitmapFactory.decodeResource(mRes, R.drawable.cubemap_test);
-        mTexCube = Allocation.createCubemapFromBitmap(mRS, b);
-
-        mScript.set_gTexTorus(mTexTorus);
-        mScript.set_gTexOpaque(mTexOpaque);
-        mScript.set_gTexTransparent(mTexTransparent);
-        mScript.set_gTexChecker(mTexChecker);
-        mScript.set_gTexCube(mTexCube);
-    }
-
-    private void initFonts() {
-        // Sans font by family name
-        mFontSans = Font.create(mRS, mRes, "sans-serif", Font.Style.NORMAL, 8);
-        mFontSerif = Font.create(mRS, mRes, "serif", Font.Style.NORMAL, 8);
-        // Create fonts by family and style
-        mFontSerifBold = Font.create(mRS, mRes, "serif", Font.Style.BOLD, 8);
-        mFontSerifItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
-        mFontSerifBoldItalic = Font.create(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8);
-        mFontMono = Font.create(mRS, mRes, "mono", Font.Style.NORMAL, 8);
-
-        mTextAlloc = Allocation.createFromString(mRS, "String from allocation", Allocation.USAGE_SCRIPT);
-
-        mScript.set_gFontSans(mFontSans);
-        mScript.set_gFontSerif(mFontSerif);
-        mScript.set_gFontSerifBold(mFontSerifBold);
-        mScript.set_gFontSerifItalic(mFontSerifItalic);
-        mScript.set_gFontSerifBoldItalic(mFontSerifBoldItalic);
-        mScript.set_gFontMono(mFontMono);
-        mScript.set_gTextAlloc(mTextAlloc);
-    }
-
-    private void initMesh() {
-        mMbyNMesh = getMbyNMesh(256, 256, 10, 10);
-        mScript.set_gMbyNMesh(mMbyNMesh);
-
-        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.torus);
-        FileA3D.IndexEntry entry = model.getIndexEntry(0);
-        if (entry == null || entry.getEntryType() != FileA3D.EntryType.MESH) {
-            Log.e("rs", "could not load model");
-        } else {
-            mTorus = (Mesh)entry.getObject();
-            mScript.set_gTorusMesh(mTorus);
-        }
-    }
-
-    private void initSamplers() {
-        Sampler.Builder bs = new Sampler.Builder(mRS);
-        bs.setMinification(Sampler.Value.LINEAR);
-        bs.setMagnification(Sampler.Value.LINEAR);
-        bs.setWrapS(Sampler.Value.WRAP);
-        bs.setWrapT(Sampler.Value.WRAP);
-        mLinearWrap = bs.create();
-
-        mLinearClamp = Sampler.CLAMP_LINEAR(mRS);
-        mNearestClamp = Sampler.CLAMP_NEAREST(mRS);
-        mMipLinearWrap = Sampler.WRAP_LINEAR_MIP_LINEAR(mRS);
-
-        bs = new Sampler.Builder(mRS);
-        bs.setMinification(Sampler.Value.LINEAR_MIP_LINEAR);
-        bs.setMagnification(Sampler.Value.LINEAR);
-        bs.setWrapS(Sampler.Value.WRAP);
-        bs.setWrapT(Sampler.Value.WRAP);
-        bs.setAnisotropy(8.0f);
-        mMipLinearAniso8 = bs.create();
-        bs.setAnisotropy(15.0f);
-        mMipLinearAniso15 = bs.create();
-
-        mScript.set_gLinearClamp(mLinearClamp);
-        mScript.set_gLinearWrap(mLinearWrap);
-        mScript.set_gMipLinearWrap(mMipLinearWrap);
-        mScript.set_gMipLinearAniso8(mMipLinearAniso8);
-        mScript.set_gMipLinearAniso15(mMipLinearAniso15);
-        mScript.set_gNearestClamp(mNearestClamp);
-    }
-
-    private void initProgramRaster() {
-        mCullBack = ProgramRaster.CULL_BACK(mRS);
-        mCullFront = ProgramRaster.CULL_FRONT(mRS);
-        mCullNone = ProgramRaster.CULL_NONE(mRS);
-
-        mScript.set_gCullBack(mCullBack);
-        mScript.set_gCullFront(mCullFront);
-        mScript.set_gCullNone(mCullNone);
-    }
-
-    private void initRS() {
-
-        mScript = new ScriptC_rsrenderstates(mRS, mRes, R.raw.rsrenderstates);
-
-        mMaxModes = mScript.get_gMaxModes();
-
-        initSamplers();
-        initProgramStore();
-        initProgramFragment();
-        initProgramVertex();
-        initFonts();
-        loadImages();
-        initMesh();
-        initProgramRaster();
-        initCustomShaders();
-
-        mRS.bindRootScript(mScript);
-    }
-}
-
-
-
diff --git a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStatesView.java b/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStatesView.java
deleted file mode 100644
index a15e38f..0000000
--- a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/RsRenderStatesView.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.rs.miscsamples;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScriptGL;
-
-import android.content.Context;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-
-public class RsRenderStatesView extends RSSurfaceView {
-
-    public RsRenderStatesView(Context context) {
-        super(context);
-        ensureRenderScript();
-    }
-
-    private RenderScriptGL mRS;
-    private RsRenderStatesRS mRender;
-
-    private void ensureRenderScript() {
-        if (mRS == null) {
-            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            sc.setDepth(16, 24);
-            mRS = createRenderScriptGL(sc);
-            mRender = new RsRenderStatesRS();
-            mRender.init(mRS, getResources());
-        }
-    }
-
-    @Override
-    protected void onAttachedToWindow() {
-        super.onAttachedToWindow();
-        ensureRenderScript();
-    }
-
-    @Override
-    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
-        super.surfaceChanged(holder, format, w, h);
-        mRender.surfaceChanged();
-    }
-
-    @Override
-    protected void onDetachedFromWindow() {
-        mRender = null;
-        if (mRS != null) {
-            mRS = null;
-            destroyRenderScriptGL();
-        }
-    }
-
-    @Override
-    public boolean onTouchEvent(MotionEvent ev) {
-        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
-            mRender.onActionDown((int)ev.getX(), (int)ev.getY());
-            return true;
-        }
-
-        return false;
-    }
-}
-
-
diff --git a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/rslist.rs b/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/rslist.rs
deleted file mode 100644
index d9d450d..0000000
--- a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/rslist.rs
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright (C) 2009 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.example.android.rs.miscsamples)
-
-#include "rs_graphics.rsh"
-
-float gDY;
-
-rs_font gItalic;
-
-typedef struct ListAllocs_s {
-    rs_allocation text;
-} ListAllocs;
-
-ListAllocs *gList;
-
-void init() {
-    gDY = 0.0f;
-}
-
-int textPos = 0;
-
-int root(void) {
-
-    rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
-
-    textPos -= (int)gDY*2;
-    gDY *= 0.95;
-
-    rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f);
-    rsgBindFont(gItalic);
-
-    rs_allocation listAlloc;
-    listAlloc = rsGetAllocation(gList);
-    int allocSize = rsAllocationGetDimX(listAlloc);
-
-    int width = rsgGetWidth();
-    int height = rsgGetHeight();
-
-    int itemHeight = 80;
-    int currentYPos = itemHeight + textPos;
-
-    for (int i = 0; i < allocSize; i ++) {
-        if (currentYPos - itemHeight > height) {
-            break;
-        }
-
-        if (currentYPos > 0) {
-            rsgDrawRect(0, currentYPos - 1, width, currentYPos, 0);
-            rsgDrawText(gList[i].text, 30, currentYPos - 32);
-        }
-        currentYPos += itemHeight;
-    }
-
-    return 10;
-}
diff --git a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/rsrenderstates.rs b/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/rsrenderstates.rs
deleted file mode 100644
index 5dabd00..0000000
--- a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/rsrenderstates.rs
+++ /dev/null
@@ -1,680 +0,0 @@
-// Copyright (C) 2009 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.example.android.rs.miscsamples)
-
-#include "rs_graphics.rsh"
-#include "shader_def.rsh"
-
-const int gMaxModes = 11;
-
-rs_program_vertex gProgVertex;
-rs_program_fragment gProgFragmentColor;
-rs_program_fragment gProgFragmentTexture;
-
-rs_program_store gProgStoreBlendNoneDepth;
-rs_program_store gProgStoreBlendNone;
-rs_program_store gProgStoreBlendAlpha;
-rs_program_store gProgStoreBlendAdd;
-
-rs_allocation gTexOpaque;
-rs_allocation gTexTorus;
-rs_allocation gTexTransparent;
-rs_allocation gTexChecker;
-rs_allocation gTexCube;
-
-rs_mesh gMbyNMesh;
-rs_mesh gTorusMesh;
-
-rs_font gFontSans;
-rs_font gFontSerif;
-rs_font gFontSerifBold;
-rs_font gFontSerifItalic;
-rs_font gFontSerifBoldItalic;
-rs_font gFontMono;
-rs_allocation gTextAlloc;
-
-int gDisplayMode;
-
-rs_sampler gLinearClamp;
-rs_sampler gLinearWrap;
-rs_sampler gMipLinearWrap;
-rs_sampler gMipLinearAniso8;
-rs_sampler gMipLinearAniso15;
-rs_sampler gNearestClamp;
-
-rs_program_raster gCullBack;
-rs_program_raster gCullFront;
-rs_program_raster gCullNone;
-
-// Custom vertex shader compunents
-VertexShaderConstants *gVSConstants;
-VertexShaderConstants2 *gVSConstants2;
-FragentShaderConstants *gFSConstants;
-FragentShaderConstants2 *gFSConstants2;
-// Export these out to easily set the inputs to shader
-VertexShaderInputs *gVSInputs;
-// Custom shaders we use for lighting
-rs_program_vertex gProgVertexCustom;
-rs_program_fragment gProgFragmentCustom;
-rs_program_vertex gProgVertexCustom2;
-rs_program_fragment gProgFragmentCustom2;
-rs_program_vertex gProgVertexCube;
-rs_program_fragment gProgFragmentCube;
-rs_program_fragment gProgFragmentMultitex;
-
-float gDt = 0;
-
-void init() {
-}
-
-static void displayFontSamples() {
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    int yPos = 100;
-    rsgBindFont(gFontSans);
-    rsgDrawText("Sans font sample", 30, yPos);
-    yPos += 30;
-    rsgFontColor(0.5f, 0.9f, 0.5f, 1.0f);
-    rsgBindFont(gFontSerif);
-    rsgDrawText("Serif font sample", 30, yPos);
-    yPos += 30;
-    rsgFontColor(0.7f, 0.7f, 0.7f, 1.0f);
-    rsgBindFont(gFontSerifBold);
-    rsgDrawText("Serif Bold font sample", 30, yPos);
-    yPos += 30;
-    rsgFontColor(0.5f, 0.5f, 0.9f, 1.0f);
-    rsgBindFont(gFontSerifItalic);
-    rsgDrawText("Serif Italic font sample", 30, yPos);
-    yPos += 30;
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgBindFont(gFontSerifBoldItalic);
-    rsgDrawText("Serif Bold Italic font sample", 30, yPos);
-    yPos += 30;
-    rsgBindFont(gFontMono);
-    rsgDrawText("Monospace font sample", 30, yPos);
-    yPos += 50;
-
-    // Now use text metrics to center the text
-    uint width = rsgGetWidth();
-    uint height = rsgGetHeight();
-    int left = 0, right = 0, top = 0, bottom = 0;
-
-    rsgFontColor(0.9f, 0.9f, 0.95f, 1.0f);
-    rsgBindFont(gFontSerifBoldItalic);
-
-    rsgMeasureText(gTextAlloc, &left, &right, &top, &bottom);
-    int centeredPos = width / 2 - (right - left) / 2;
-    rsgDrawText(gTextAlloc, centeredPos, yPos);
-    yPos += 30;
-
-    const char* text = "Centered Text Sample";
-    rsgMeasureText(text, &left, &right, &top, &bottom);
-    centeredPos = width / 2 - (right - left) / 2;
-    rsgDrawText(text, centeredPos, yPos);
-    yPos += 30;
-
-    rsgBindFont(gFontSans);
-    text = "More Centered Text Samples";
-    rsgMeasureText(text, &left, &right, &top, &bottom);
-    centeredPos = width / 2 - (right - left) / 2;
-    rsgDrawText(text, centeredPos, yPos);
-    yPos += 30;
-
-    // Now draw bottom and top right aligned text
-    text = "Top-right aligned text";
-    rsgMeasureText(text, &left, &right, &top, &bottom);
-    rsgDrawText(text, width - right, top);
-
-    text = "Top-left";
-    rsgMeasureText(text, &left, &right, &top, &bottom);
-    rsgDrawText(text, -left, top);
-
-    text = "Bottom-right aligned text";
-    rsgMeasureText(text, &left, &right, &top, &bottom);
-    rsgDrawText(text, width - right, height + bottom);
-
-}
-
-static void bindProgramVertexOrtho() {
-    // Default vertex sahder
-    rsgBindProgramVertex(gProgVertex);
-    // Setup the projectioni matrix
-    rs_matrix4x4 proj;
-    rsMatrixLoadOrtho(&proj, 0, rsgGetWidth(), rsgGetHeight(), 0, -500, 500);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-}
-
-static void displayShaderSamples() {
-    bindProgramVertexOrtho();
-    rs_matrix4x4 matrix;
-    rsMatrixLoadIdentity(&matrix);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNone);
-    rsgBindProgramFragment(gProgFragmentTexture);
-    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
-    rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);
-
-    float startX = 0, startY = 0;
-    float width = 256, height = 256;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
-                         startX, startY + height, 0, 0, 1,
-                         startX + width, startY + height, 0, 1, 1,
-                         startX + width, startY, 0, 1, 0);
-
-    startX = 200; startY = 0;
-    width = 128; height = 128;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
-                         startX, startY + height, 0, 0, 1,
-                         startX + width, startY + height, 0, 1, 1,
-                         startX + width, startY, 0, 1, 0);
-
-    rsgBindProgramStore(gProgStoreBlendAlpha);
-    rsgBindTexture(gProgFragmentTexture, 0, gTexTransparent);
-    startX = 0; startY = 200;
-    width = 128; height = 128;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
-                         startX, startY + height, 0, 0, 1,
-                         startX + width, startY + height, 0, 1, 1,
-                         startX + width, startY, 0, 1, 0);
-
-    // Fragment program with simple color
-    rsgBindProgramFragment(gProgFragmentColor);
-    rsgProgramFragmentConstantColor(gProgFragmentColor, 0.9, 0.3, 0.3, 1);
-    rsgDrawRect(200, 300, 350, 450, 0);
-    rsgProgramFragmentConstantColor(gProgFragmentColor, 0.3, 0.9, 0.3, 1);
-    rsgDrawRect(50, 400, 400, 600, 0);
-
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgBindFont(gFontMono);
-    rsgDrawText("Texture shader", 10, 50);
-    rsgDrawText("Alpha-blended texture shader", 10, 280);
-    rsgDrawText("Flat color shader", 100, 450);
-}
-
-static void displayBlendingSamples() {
-    int i;
-
-    bindProgramVertexOrtho();
-    rs_matrix4x4 matrix;
-    rsMatrixLoadIdentity(&matrix);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    rsgBindProgramFragment(gProgFragmentColor);
-
-    rsgBindProgramStore(gProgStoreBlendNone);
-    for (i = 0; i < 3; i ++) {
-        float iPlusOne = (float)(i + 1);
-        rsgProgramFragmentConstantColor(gProgFragmentColor,
-                                        0.1f*iPlusOne, 0.2f*iPlusOne, 0.3f*iPlusOne, 1);
-        float yPos = 150 * (float)i;
-        rsgDrawRect(0, yPos, 200, yPos + 200, 0);
-    }
-
-    rsgBindProgramStore(gProgStoreBlendAlpha);
-    for (i = 0; i < 3; i ++) {
-        float iPlusOne = (float)(i + 1);
-        rsgProgramFragmentConstantColor(gProgFragmentColor,
-                                        0.2f*iPlusOne, 0.3f*iPlusOne, 0.1f*iPlusOne, 0.5);
-        float yPos = 150 * (float)i;
-        rsgDrawRect(150, yPos, 350, yPos + 200, 0);
-    }
-
-    rsgBindProgramStore(gProgStoreBlendAdd);
-    for (i = 0; i < 3; i ++) {
-        float iPlusOne = (float)(i + 1);
-        rsgProgramFragmentConstantColor(gProgFragmentColor,
-                                        0.3f*iPlusOne, 0.1f*iPlusOne, 0.2f*iPlusOne, 0.5);
-        float yPos = 150 * (float)i;
-        rsgDrawRect(300, yPos, 500, yPos + 200, 0);
-    }
-
-
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgBindFont(gFontMono);
-    rsgDrawText("No Blending", 10, 50);
-    rsgDrawText("Alpha Blending", 160, 150);
-    rsgDrawText("Additive Blending", 320, 250);
-
-}
-
-static void displayMeshSamples() {
-
-    bindProgramVertexOrtho();
-    rs_matrix4x4 matrix;
-    rsMatrixLoadTranslate(&matrix, 128, 128, 0);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNone);
-    rsgBindProgramFragment(gProgFragmentTexture);
-    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
-    rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);
-
-    rsgDrawMesh(gMbyNMesh);
-
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgBindFont(gFontMono);
-    rsgDrawText("User gen 10 by 10 grid mesh", 10, 250);
-}
-
-static void displayTextureSamplers() {
-
-    bindProgramVertexOrtho();
-    rs_matrix4x4 matrix;
-    rsMatrixLoadIdentity(&matrix);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNone);
-    rsgBindProgramFragment(gProgFragmentTexture);
-    rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);
-
-    // Linear clamp
-    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
-    float startX = 0, startY = 0;
-    float width = 300, height = 300;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
-                         startX, startY + height, 0, 0, 1.1,
-                         startX + width, startY + height, 0, 1.1, 1.1,
-                         startX + width, startY, 0, 1.1, 0);
-
-    // Linear Wrap
-    rsgBindSampler(gProgFragmentTexture, 0, gLinearWrap);
-    startX = 0; startY = 300;
-    width = 300; height = 300;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
-                         startX, startY + height, 0, 0, 1.1,
-                         startX + width, startY + height, 0, 1.1, 1.1,
-                         startX + width, startY, 0, 1.1, 0);
-
-    // Nearest
-    rsgBindSampler(gProgFragmentTexture, 0, gNearestClamp);
-    startX = 300; startY = 0;
-    width = 300; height = 300;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
-                         startX, startY + height, 0, 0, 1.1,
-                         startX + width, startY + height, 0, 1.1, 1.1,
-                         startX + width, startY, 0, 1.1, 0);
-
-    rsgBindSampler(gProgFragmentTexture, 0, gMipLinearWrap);
-    startX = 300; startY = 300;
-    width = 300; height = 300;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
-                         startX, startY + height, 0, 0, 1.5,
-                         startX + width, startY + height, 0, 1.5, 1.5,
-                         startX + width, startY, 0, 1.5, 0);
-
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgBindFont(gFontMono);
-    rsgDrawText("Filtering: linear clamp", 10, 290);
-    rsgDrawText("Filtering: linear wrap", 10, 590);
-    rsgDrawText("Filtering: nearest clamp", 310, 290);
-    rsgDrawText("Filtering: miplinear wrap", 310, 590);
-}
-
-static float gTorusRotation = 0;
-
-static void displayCullingSamples() {
-    rsgBindProgramVertex(gProgVertex);
-    // Setup the projectioni matrix with 60 degree field of view
-    rs_matrix4x4 proj;
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
-    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNoneDepth);
-    rsgBindProgramFragment(gProgFragmentTexture);
-    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
-    rsgBindTexture(gProgFragmentTexture, 0, gTexTorus);
-
-    // Aplly a rotation to our mesh
-    gTorusRotation += 50.0f * gDt;
-    if (gTorusRotation > 360.0f) {
-        gTorusRotation -= 360.0f;
-    }
-
-    rs_matrix4x4 matrix;
-    // Position our model on the screen
-    rsMatrixLoadTranslate(&matrix, -2.0f, 0.0f, -10.0f);
-    rsMatrixRotate(&matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-    // Use front face culling
-    rsgBindProgramRaster(gCullFront);
-    rsgDrawMesh(gTorusMesh);
-
-    rsMatrixLoadTranslate(&matrix, 2.0f, 0.0f, -10.0f);
-    rsMatrixRotate(&matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-    // Use back face culling
-    rsgBindProgramRaster(gCullBack);
-    rsgDrawMesh(gTorusMesh);
-
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgBindFont(gFontMono);
-    rsgDrawText("Displaying mesh front/back face culling", 10, rsgGetHeight() - 10);
-}
-
-static float gLight0Rotation = 0;
-static float gLight1Rotation = 0;
-
-static void setupCustomShaderLights() {
-    float4 light0Pos = {-5.0f, 5.0f, -10.0f, 1.0f};
-    float4 light1Pos = {2.0f, 5.0f, 15.0f, 1.0f};
-    float4 light0DiffCol = {0.9f, 0.7f, 0.7f, 1.0f};
-    float4 light0SpecCol = {0.9f, 0.6f, 0.6f, 1.0f};
-    float4 light1DiffCol = {0.5f, 0.5f, 0.9f, 1.0f};
-    float4 light1SpecCol = {0.5f, 0.5f, 0.9f, 1.0f};
-
-    gLight0Rotation += 50.0f * gDt;
-    if (gLight0Rotation > 360.0f) {
-        gLight0Rotation -= 360.0f;
-    }
-    gLight1Rotation -= 50.0f * gDt;
-    if (gLight1Rotation > 360.0f) {
-        gLight1Rotation -= 360.0f;
-    }
-
-    rs_matrix4x4 l0Mat;
-    rsMatrixLoadRotate(&l0Mat, gLight0Rotation, 1.0f, 0.0f, 0.0f);
-    light0Pos = rsMatrixMultiply(&l0Mat, light0Pos);
-    rs_matrix4x4 l1Mat;
-    rsMatrixLoadRotate(&l1Mat, gLight1Rotation, 0.0f, 0.0f, 1.0f);
-    light1Pos = rsMatrixMultiply(&l1Mat, light1Pos);
-
-    // Set light 0 properties
-    gVSConstants->light0_Posision = light0Pos;
-    gVSConstants->light0_Diffuse = 1.0f;
-    gVSConstants->light0_Specular = 0.5f;
-    gVSConstants->light0_CosinePower = 10.0f;
-    // Set light 1 properties
-    gVSConstants->light1_Posision = light1Pos;
-    gVSConstants->light1_Diffuse = 1.0f;
-    gVSConstants->light1_Specular = 0.7f;
-    gVSConstants->light1_CosinePower = 25.0f;
-    rsgAllocationSyncAll(rsGetAllocation(gVSConstants));
-
-    gVSConstants2->light_Posision[0] = light0Pos;
-    gVSConstants2->light_Diffuse[0] = 1.0f;
-    gVSConstants2->light_Specular[0] = 0.5f;
-    gVSConstants2->light_CosinePower[0] = 10.0f;
-    gVSConstants2->light_Posision[1] = light1Pos;
-    gVSConstants2->light_Diffuse[1] = 1.0f;
-    gVSConstants2->light_Specular[1] = 0.7f;
-    gVSConstants2->light_CosinePower[1] = 25.0f;
-    rsgAllocationSyncAll(rsGetAllocation(gVSConstants2));
-
-    // Update fragmetn shader constants
-    // Set light 0 colors
-    gFSConstants->light0_DiffuseColor = light0DiffCol;
-    gFSConstants->light0_SpecularColor = light0SpecCol;
-    // Set light 1 colors
-    gFSConstants->light1_DiffuseColor = light1DiffCol;
-    gFSConstants->light1_SpecularColor = light1SpecCol;
-    rsgAllocationSyncAll(rsGetAllocation(gFSConstants));
-
-    gFSConstants2->light_DiffuseColor[0] = light0DiffCol;
-    gFSConstants2->light_SpecularColor[0] = light0SpecCol;
-    // Set light 1 colors
-    gFSConstants2->light_DiffuseColor[1] = light1DiffCol;
-    gFSConstants2->light_SpecularColor[1] = light1SpecCol;
-    rsgAllocationSyncAll(rsGetAllocation(gFSConstants2));
-}
-
-static void displayCustomShaderSamples() {
-
-    // Update vertex shader constants
-    // Load model matrix
-    // Aplly a rotation to our mesh
-    gTorusRotation += 50.0f * gDt;
-    if (gTorusRotation > 360.0f) {
-        gTorusRotation -= 360.0f;
-    }
-
-    // Position our model on the screen
-    rsMatrixLoadTranslate(&gVSConstants->model, 0.0f, 0.0f, -10.0f);
-    rsMatrixRotate(&gVSConstants->model, gTorusRotation, 1.0f, 0.0f, 0.0f);
-    rsMatrixRotate(&gVSConstants->model, gTorusRotation, 0.0f, 0.0f, 1.0f);
-    // Setup the projectioni matrix
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
-    rsMatrixLoadPerspective(&gVSConstants->proj, 30.0f, aspect, 0.1f, 100.0f);
-    setupCustomShaderLights();
-
-    rsgBindProgramVertex(gProgVertexCustom);
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNoneDepth);
-    rsgBindProgramFragment(gProgFragmentCustom);
-    rsgBindSampler(gProgFragmentCustom, 0, gLinearClamp);
-    rsgBindTexture(gProgFragmentCustom, 0, gTexTorus);
-
-    // Use back face culling
-    rsgBindProgramRaster(gCullBack);
-    rsgDrawMesh(gTorusMesh);
-
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgBindFont(gFontMono);
-    rsgDrawText("Custom shader sample", 10, rsgGetHeight() - 10);
-}
-
-static void displayCustomShaderSamples2() {
-
-    // Update vertex shader constants
-    // Load model matrix
-    // Aplly a rotation to our mesh
-    gTorusRotation += 50.0f * gDt;
-    if (gTorusRotation > 360.0f) {
-        gTorusRotation -= 360.0f;
-    }
-
-    // Position our model on the screen
-    rsMatrixLoadTranslate(&gVSConstants2->model[1], 0.0f, 0.0f, -10.0f);
-    rsMatrixLoadIdentity(&gVSConstants2->model[0]);
-    rsMatrixRotate(&gVSConstants2->model[0], gTorusRotation, 1.0f, 0.0f, 0.0f);
-    rsMatrixRotate(&gVSConstants2->model[0], gTorusRotation, 0.0f, 0.0f, 1.0f);
-    // Setup the projectioni matrix
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
-    rsMatrixLoadPerspective(&gVSConstants2->proj, 30.0f, aspect, 0.1f, 100.0f);
-    setupCustomShaderLights();
-
-    rsgBindProgramVertex(gProgVertexCustom2);
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNoneDepth);
-    rsgBindProgramFragment(gProgFragmentCustom2);
-    rsgBindSampler(gProgFragmentCustom2, 0, gLinearClamp);
-    rsgBindTexture(gProgFragmentCustom2, 0, gTexTorus);
-
-    // Use back face culling
-    rsgBindProgramRaster(gCullBack);
-    rsgDrawMesh(gTorusMesh);
-
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgBindFont(gFontMono);
-    rsgDrawText("Custom shader sample with array uniforms", 10, rsgGetHeight() - 10);
-}
-
-static void displayCubemapShaderSample() {
-    // Update vertex shader constants
-    // Load model matrix
-    // Aplly a rotation to our mesh
-    gTorusRotation += 50.0f * gDt;
-    if (gTorusRotation > 360.0f) {
-        gTorusRotation -= 360.0f;
-    }
-
-    // Position our model on the screen
-    // Position our model on the screen
-    rsMatrixLoadTranslate(&gVSConstants->model, 0.0f, 0.0f, -10.0f);
-    rsMatrixRotate(&gVSConstants->model, gTorusRotation, 1.0f, 0.0f, 0.0f);
-    rsMatrixRotate(&gVSConstants->model, gTorusRotation, 0.0f, 0.0f, 1.0f);
-    // Setup the projectioni matrix
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
-    rsMatrixLoadPerspective(&gVSConstants->proj, 30.0f, aspect, 0.1f, 100.0f);
-    rsgAllocationSyncAll(rsGetAllocation(gFSConstants));
-
-    rsgBindProgramVertex(gProgVertexCube);
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNoneDepth);
-    rsgBindProgramFragment(gProgFragmentCube);
-    rsgBindSampler(gProgFragmentCube, 0, gLinearClamp);
-    rsgBindTexture(gProgFragmentCube, 0, gTexCube);
-
-    // Use back face culling
-    rsgBindProgramRaster(gCullBack);
-    rsgDrawMesh(gTorusMesh);
-
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgBindFont(gFontMono);
-    rsgDrawText("Cubemap shader sample", 10, rsgGetHeight() - 10);
-}
-
-static void displayMultitextureSample() {
-    bindProgramVertexOrtho();
-    rs_matrix4x4 matrix;
-    rsMatrixLoadIdentity(&matrix);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNone);
-    rsgBindProgramFragment(gProgFragmentMultitex);
-    rsgBindSampler(gProgFragmentMultitex, 0, gLinearClamp);
-    rsgBindSampler(gProgFragmentMultitex, 1, gLinearWrap);
-    rsgBindSampler(gProgFragmentMultitex, 2, gLinearClamp);
-    rsgBindTexture(gProgFragmentMultitex, 0, gTexChecker);
-    rsgBindTexture(gProgFragmentMultitex, 1, gTexTorus);
-    rsgBindTexture(gProgFragmentMultitex, 2, gTexTransparent);
-
-    float startX = 0, startY = 0;
-    float width = 256, height = 256;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
-                         startX, startY + height, 0, 0, 1,
-                         startX + width, startY + height, 0, 1, 1,
-                         startX + width, startY, 0, 1, 0);
-
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgBindFont(gFontMono);
-    rsgDrawText("Custom shader with multitexturing", 10, 280);
-}
-
-static float gAnisoTime = 0.0f;
-static uint anisoMode = 0;
-static void displayAnisoSample() {
-
-    gAnisoTime += gDt;
-
-    rsgBindProgramVertex(gProgVertex);
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
-    rs_matrix4x4 proj;
-    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-
-    rs_matrix4x4 matrix;
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNone);
-    rsgBindProgramFragment(gProgFragmentTexture);
-    rsMatrixLoadTranslate(&matrix, 0.0f, 0.0f, -10.0f);
-    rsMatrixRotate(&matrix, -80, 1.0f, 0.0f, 0.0f);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    rsgBindProgramRaster(gCullNone);
-
-    rsgBindTexture(gProgFragmentTexture, 0, gTexChecker);
-
-    if (gAnisoTime >= 5.0f) {
-        gAnisoTime = 0.0f;
-        anisoMode ++;
-        anisoMode = anisoMode % 3;
-    }
-
-    if (anisoMode == 0) {
-        rsgBindSampler(gProgFragmentTexture, 0, gMipLinearAniso8);
-    } else if (anisoMode == 1) {
-        rsgBindSampler(gProgFragmentTexture, 0, gMipLinearAniso15);
-    } else {
-        rsgBindSampler(gProgFragmentTexture, 0, gMipLinearWrap);
-    }
-
-    float startX = -15;
-    float startY = -15;
-    float width = 30;
-    float height = 30;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
-                         startX, startY + height, 0, 0, 10,
-                         startX + width, startY + height, 0, 10, 10,
-                         startX + width, startY, 0, 10, 0);
-
-    rsgBindProgramRaster(gCullBack);
-
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgBindFont(gFontMono);
-    if (anisoMode == 0) {
-        rsgDrawText("Anisotropic filtering 8", 10, 40);
-    } else if (anisoMode == 1) {
-        rsgDrawText("Anisotropic filtering 15", 10, 40);
-    } else {
-        rsgDrawText("Miplinear filtering", 10, 40);
-    }
-}
-
-int root(void) {
-
-    gDt = rsGetDt();
-
-    rsgClearColor(0.2f, 0.2f, 0.2f, 0.0f);
-    rsgClearDepth(1.0f);
-
-    switch (gDisplayMode) {
-    case 0:
-        displayFontSamples();
-        break;
-    case 1:
-        displayShaderSamples();
-        break;
-    case 2:
-        displayBlendingSamples();
-        break;
-    case 3:
-        displayMeshSamples();
-        break;
-    case 4:
-        displayTextureSamplers();
-        break;
-    case 5:
-        displayCullingSamples();
-        break;
-    case 6:
-        displayCustomShaderSamples();
-        break;
-    case 7:
-        displayMultitextureSample();
-        break;
-    case 8:
-        displayAnisoSample();
-        break;
-    case 9:
-        displayCustomShaderSamples2();
-        break;
-    case 10:
-        displayCubemapShaderSample();
-        break;
-    }
-
-    return 10;
-}
diff --git a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/shader_def.rsh b/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/shader_def.rsh
deleted file mode 100644
index 08cf361..0000000
--- a/tests/RenderScriptTests/MiscSamples/src/com/example/android/rs/miscsamples/shader_def.rsh
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright (C) 2009 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.example.android.rs.miscsamples)
-
-typedef struct VertexShaderConstants_s {
-    rs_matrix4x4 model;
-    rs_matrix4x4 proj;
-    float4 light0_Posision;
-    float light0_Diffuse;
-    float light0_Specular;
-    float light0_CosinePower;
-
-    float4 light1_Posision;
-    float light1_Diffuse;
-    float light1_Specular;
-    float light1_CosinePower;
-} VertexShaderConstants;
-
-typedef struct VertexShaderConstants2_s {
-    rs_matrix4x4 model[2];
-    rs_matrix4x4 proj;
-    float4 light_Posision[2];
-    float light_Diffuse[2];
-    float light_Specular[2];
-    float light_CosinePower[2];
-} VertexShaderConstants2;
-
-typedef struct VertexShaderConstants3_s {
-    rs_matrix4x4 model;
-    rs_matrix4x4 proj;
-    float time;
-} VertexShaderConstants3;
-
-
-typedef struct FragentShaderConstants_s {
-    float4 light0_DiffuseColor;
-    float4 light0_SpecularColor;
-
-    float4 light1_DiffuseColor;
-    float4 light1_SpecularColor;
-} FragentShaderConstants;
-
-typedef struct FragentShaderConstants2_s {
-    float4 light_DiffuseColor[2];
-    float4 light_SpecularColor[2];
-} FragentShaderConstants2;
-
-typedef struct FragentShaderConstants3_s {
-    float4 light0_DiffuseColor;
-    float4 light0_SpecularColor;
-    float4 light0_Posision;
-    float light0_Diffuse;
-    float light0_Specular;
-    float light0_CosinePower;
-
-    float4 light1_DiffuseColor;
-    float4 light1_SpecularColor;
-    float4 light1_Posision;
-    float light1_Diffuse;
-    float light1_Specular;
-    float light1_CosinePower;
-} FragentShaderConstants3;
-
-typedef struct VertexShaderInputs_s {
-    float4 position;
-    float3 normal;
-    float2 texture0;
-} VertexShaderInputs;
-
diff --git a/tests/RenderScriptTests/ModelViewer/Android.mk b/tests/RenderScriptTests/ModelViewer/Android.mk
deleted file mode 100644
index 86724cf..0000000
--- a/tests/RenderScriptTests/ModelViewer/Android.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# Copyright (C) 2008 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
-#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
-
-LOCAL_SDK_VERSION := 17
-
-LOCAL_PACKAGE_NAME := ModelViewer
-
-include $(BUILD_PACKAGE)
diff --git a/tests/RenderScriptTests/ModelViewer/AndroidManifest.xml b/tests/RenderScriptTests/ModelViewer/AndroidManifest.xml
deleted file mode 100644
index 57ec4fe..0000000
--- a/tests/RenderScriptTests/ModelViewer/AndroidManifest.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.android.modelviewer">
-    <application android:label="ModelViewer">
-        <activity android:name="SimpleModel"
-                  android:label="SimpleModel"
-                  android:screenOrientation="nosensor">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-        <activity android:name="A3DSelector"
-                  android:label="A3DSelector"
-                  android:hardwareAccelerated="true">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-            </intent-filter>
-        </activity>
-        <activity android:name="SceneGraph"
-                  android:label="SceneGraph"
-                  android:theme="@android:style/Theme.Black.NoTitleBar">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-    </application>
-</manifest>
diff --git a/tests/RenderScriptTests/ModelViewer/res/drawable-nodpi/robot.png b/tests/RenderScriptTests/ModelViewer/res/drawable-nodpi/robot.png
deleted file mode 100644
index f7353fd..0000000
--- a/tests/RenderScriptTests/ModelViewer/res/drawable-nodpi/robot.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/ModelViewer/res/menu/loader_menu.xml b/tests/RenderScriptTests/ModelViewer/res/menu/loader_menu.xml
deleted file mode 100644
index 2a8759c..0000000
--- a/tests/RenderScriptTests/ModelViewer/res/menu/loader_menu.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-* Copyright (C) 2011 The Android Open Source Project
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
--->
-
-<menu xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:id="@+id/load_model"
-          android:title="@string/load_model" />
-    <item android:id="@+id/display_options"
-          android:title="@string/display_options" />
-    <item android:id="@+id/sensor"
-          android:title="@string/sensor" />
-</menu>
diff --git a/tests/RenderScriptTests/ModelViewer/res/raw/robot.a3d b/tests/RenderScriptTests/ModelViewer/res/raw/robot.a3d
deleted file mode 100644
index f48895c..0000000
--- a/tests/RenderScriptTests/ModelViewer/res/raw/robot.a3d
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/ModelViewer/res/values/strings.xml b/tests/RenderScriptTests/ModelViewer/res/values/strings.xml
deleted file mode 100644
index a5c8f22..0000000
--- a/tests/RenderScriptTests/ModelViewer/res/values/strings.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-* Copyright (C) 2011 The Android Open Source Project
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
--->
-
-<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <skip />
-    <string name="load_model">Load Model</string>
-    <string name="display_options">Display Options</string>
-    <string name="sensor">Toggle Sensor</string>
-</resources>
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/A3DSelector.java b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/A3DSelector.java
deleted file mode 100644
index 0e2004f..0000000
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/A3DSelector.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.modelviewer;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.util.ArrayList;
-import java.util.List;
-
-import android.app.ListActivity;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-
-/**
- * A list view where the last item the user clicked is placed in
- * the "activated" state, causing its background to highlight.
- */
-public class A3DSelector extends ListActivity {
-
-    File[] mCurrentSubList;
-    File mCurrentFile;
-
-    class A3DFilter implements FileFilter {
-        public boolean accept(File file) {
-            if (file.isDirectory()) {
-                return true;
-            }
-            return file.getName().endsWith(".a3d");
-        }
-    }
-
-    private void populateList(File file) {
-
-        mCurrentFile = file;
-        setTitle(mCurrentFile.getAbsolutePath() + "/*.a3d");
-        List<String> names = new ArrayList<String>();
-        names.add("..");
-
-        mCurrentSubList = mCurrentFile.listFiles(new A3DFilter());
-
-        if (mCurrentSubList != null) {
-            for (int i = 0; i < mCurrentSubList.length; i ++) {
-                String fileName = mCurrentSubList[i].getName();
-                if (mCurrentSubList[i].isDirectory()) {
-                    fileName = "/" + fileName;
-                }
-                names.add(fileName);
-            }
-        }
-
-        // Use the built-in layout for showing a list item with a single
-        // line of text whose background is changes when activated.
-        setListAdapter(new ArrayAdapter<String>(this,
-                android.R.layout.simple_list_item_activated_1, names));
-        getListView().setTextFilterEnabled(true);
-
-        // Tell the list view to show one checked/activated item at a time.
-        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
-    }
-
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        populateList(new File("/sdcard/"));
-    }
-
-    @Override
-    protected void onListItemClick(ListView l, View v, int position, long id) {
-        if (position == 0) {
-            File parent = mCurrentFile.getParentFile();
-            if (parent == null) {
-                return;
-            }
-            populateList(parent);
-            return;
-        }
-
-        // the first thing in list is parent directory
-        File selectedFile = mCurrentSubList[position - 1];
-        if (selectedFile.isDirectory()) {
-            populateList(selectedFile);
-            return;
-        }
-
-        Intent resultIntent = new Intent();
-        resultIntent.setData(Uri.fromFile(selectedFile));
-        setResult(RESULT_OK, resultIntent);
-        finish();
-    }
-
-}
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SceneGraph.java b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SceneGraph.java
deleted file mode 100644
index c9c4dc1..0000000
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SceneGraph.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.modelviewer;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
-import android.app.Activity;
-import android.content.res.Configuration;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.provider.Settings.System;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.Window;
-import android.widget.Button;
-import android.widget.ListView;
-
-import java.lang.Runtime;
-
-public class SceneGraph extends Activity {
-
-    private SceneGraphView mView;
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        // Create our Preview view and set it as the content of our
-        // Activity
-        mView = new SceneGraphView(this);
-        setContentView(mView);
-    }
-
-    @Override
-    protected void onResume() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
-        super.onResume();
-        mView.resume();
-    }
-
-    @Override
-    protected void onPause() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
-        super.onPause();
-        mView.pause();
-    }
-
-}
-
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java
deleted file mode 100644
index f91f31e..0000000
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.modelviewer;
-
-import java.io.Writer;
-import java.util.Map;
-import java.util.Vector;
-
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.renderscript.Element.Builder;
-import android.renderscript.Font.Style;
-import android.renderscript.ProgramStore.DepthFunc;
-import android.util.Log;
-
-
-public class SceneGraphRS {
-
-    private final int STATE_LAST_FOCUS = 1;
-
-    int mWidth;
-    int mHeight;
-    int mRotation;
-
-    public SceneGraphRS() {
-    }
-
-    public void init(RenderScriptGL rs, Resources res, int width, int height) {
-        mRS = rs;
-        mRes = res;
-        mWidth = width;
-        mHeight = height;
-        mRotation = 0;
-        initRS();
-    }
-
-    private Resources mRes;
-    private RenderScriptGL mRS;
-    private Sampler mSampler;
-    private ProgramStore mPSBackground;
-    private ProgramFragment mPFBackground;
-    private ProgramVertex mPVBackground;
-    private ProgramVertexFixedFunction.Constants mPVA;
-
-    private Allocation mGridImage;
-    private Allocation mAllocPV;
-
-    private Mesh mMesh;
-
-    private Font mItalic;
-    private Allocation mTextAlloc;
-
-    private ScriptC_scenegraph mScript;
-    private ScriptC_transform mTransformScript;
-
-    int mLastX;
-    int mLastY;
-
-    public void touchEvent(int x, int y) {
-        int dx = mLastX - x;
-        if (Math.abs(dx) > 50 || Math.abs(dx) < 3) {
-            dx = 0;
-        }
-
-        mRotation -= dx;
-        if (mRotation > 360) {
-            mRotation -= 360;
-        }
-        if (mRotation < 0) {
-            mRotation += 360;
-        }
-
-        mScript.set_gRotate(-(float)mRotation);
-
-        mLastX = x;
-        mLastY = y;
-    }
-
-    private void initPFS() {
-        ProgramStore.Builder b = new ProgramStore.Builder(mRS);
-
-        b.setDepthFunc(ProgramStore.DepthFunc.LESS);
-        b.setDitherEnabled(false);
-        b.setDepthMaskEnabled(true);
-        mPSBackground = b.create();
-
-        mScript.set_gPFSBackground(mPSBackground);
-    }
-
-    private void initPF() {
-        Sampler.Builder bs = new Sampler.Builder(mRS);
-        bs.setMinification(Sampler.Value.LINEAR);
-        bs.setMagnification(Sampler.Value.LINEAR);
-        bs.setWrapS(Sampler.Value.CLAMP);
-        bs.setWrapT(Sampler.Value.CLAMP);
-        mSampler = bs.create();
-
-        ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
-        b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
-                     ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
-        mPFBackground = b.create();
-        mPFBackground.bindSampler(mSampler, 0);
-
-        mScript.set_gPFBackground(mPFBackground);
-    }
-
-    private void initPV() {
-        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
-        mPVBackground = pvb.create();
-
-        mPVA = new ProgramVertexFixedFunction.Constants(mRS);
-        ((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA);
-
-        mScript.set_gPVBackground(mPVBackground);
-    }
-
-    private void loadImage() {
-        mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
-                                                         Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                                                         Allocation.USAGE_GRAPHICS_TEXTURE);
-        mScript.set_gTGrid(mGridImage);
-    }
-
-    private void initTextAllocation() {
-        String allocString = "Displaying file: R.raw.robot";
-        mTextAlloc = Allocation.createFromString(mRS, allocString, Allocation.USAGE_SCRIPT);
-        mScript.set_gTextAlloc(mTextAlloc);
-    }
-
-    SgTransform mRootTransform;
-    SgTransform mGroup1;
-
-    SgTransform mRobot1;
-    SgTransform mRobot2;
-
-    void initTransformHierarchy() {
-        mRootTransform = new SgTransform(mRS);
-
-        mGroup1 = new SgTransform(mRS);
-        mRootTransform.addChild(mGroup1);
-
-        mRobot1 = new SgTransform(mRS);
-        mRobot2 = new SgTransform(mRS);
-
-        mGroup1.addChild(mRobot1);
-        mGroup1.addChild(mRobot2);
-
-        mGroup1.setTransform(0, new Float4(0.0f, 0.0f, -15.0f, 0.0f), TransformType.TRANSLATE);
-        mGroup1.setTransform(1, new Float4(0.0f, 1.0f, 0.0f, 15.0f), TransformType.ROTATE);
-
-        mRobot1.setTransform(0, new Float4(-3.0f, -0.5f, 0.0f, 0.0f), TransformType.TRANSLATE);
-        mRobot1.setTransform(1, new Float4(0.0f, 1.0f, 0.0f, 20.0f), TransformType.ROTATE);
-        mRobot1.setTransform(2, new Float4(0.2f, 0.2f, 0.2f, 0.0f), TransformType.SCALE);
-
-        mRobot2.setTransform(0, new Float4(3.0f, 0.0f, 0.0f, 0.0f), TransformType.TRANSLATE);
-        mRobot2.setTransform(1, new Float4(0.0f, 1.0f, 0.0f, -20.0f), TransformType.ROTATE);
-        mRobot2.setTransform(2, new Float4(0.3f, 0.3f, 0.3f, 0.0f), TransformType.SCALE);
-    }
-
-    private void initRS() {
-
-        mScript = new ScriptC_scenegraph(mRS, mRes, R.raw.scenegraph);
-        mTransformScript = new ScriptC_transform(mRS, mRes, R.raw.transform);
-        mTransformScript.set_transformScript(mTransformScript);
-
-        mScript.set_gTransformRS(mTransformScript);
-
-        initPFS();
-        initPF();
-        initPV();
-
-        loadImage();
-
-        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
-        FileA3D.IndexEntry entry = model.getIndexEntry(0);
-        if (entry == null || entry.getEntryType() != FileA3D.EntryType.MESH) {
-            Log.e("rs", "could not load model");
-        } else {
-            mMesh = (Mesh)entry.getObject();
-            mScript.set_gTestMesh(mMesh);
-        }
-
-        mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
-        mScript.set_gItalic(mItalic);
-
-        initTextAllocation();
-
-        initTransformHierarchy();
-
-        mScript.bind_gRootNode(mRootTransform.getField());
-
-        mScript.bind_gGroup(mGroup1.mParent.mChildField);
-        mScript.bind_gRobot1(mRobot1.mParent.mChildField);
-        mScript.set_gRobot1Index(mRobot1.mIndexInParentGroup);
-        mScript.bind_gRobot2(mRobot2.mParent.mChildField);
-        mScript.set_gRobot2Index(mRobot2.mIndexInParentGroup);
-
-        mRS.bindRootScript(mScript);
-    }
-}
-
-
-
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SceneGraphView.java b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SceneGraphView.java
deleted file mode 100644
index 0b6a3b8..0000000
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SceneGraphView.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.modelviewer;
-
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-import android.renderscript.RenderScriptGL;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.Handler;
-import android.os.Message;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-
-public class SceneGraphView extends RSSurfaceView {
-
-    public SceneGraphView(Context context) {
-        super(context);
-        //setFocusable(true);
-    }
-
-    private RenderScriptGL mRS;
-    private SceneGraphRS mRender;
-
-
-    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
-        super.surfaceChanged(holder, format, w, h);
-        if (mRS == null) {
-            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            sc.setDepth(16, 24);
-            mRS = createRenderScriptGL(sc);
-            mRS.setSurface(holder, w, h);
-            mRender = new SceneGraphRS();
-            mRender.init(mRS, getResources(), w, h);
-        }
-    }
-
-    @Override
-    protected void onDetachedFromWindow() {
-        if (mRS != null) {
-            mRS = null;
-            destroyRenderScriptGL();
-        }
-    }
-
-    @Override
-    public boolean onKeyDown(int keyCode, KeyEvent event)
-    {
-        // break point at here
-        // this method doesn't work when 'extends View' include 'extends ScrollView'.
-        return super.onKeyDown(keyCode, event);
-    }
-
-
-    @Override
-    public boolean onTouchEvent(MotionEvent ev)
-    {
-        boolean ret = true;
-        int act = ev.getAction();
-        if (act == ev.ACTION_UP) {
-            ret = false;
-        }
-
-        mRender.touchEvent((int)ev.getX(), (int)ev.getY());
-        return ret;
-    }
-}
-
-
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SgTransform.java b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SgTransform.java
deleted file mode 100644
index f5484e2..0000000
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SgTransform.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.modelviewer;
-
-import java.io.Writer;
-import java.util.Map;
-import java.util.Vector;
-
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.renderscript.Element.Builder;
-import android.renderscript.ProgramStore.DepthFunc;
-import android.util.Log;
-
-enum TransformType {
-
-    NONE(0),
-    TRANSLATE(1),
-    ROTATE(2),
-    SCALE(3);
-
-    int mID;
-    TransformType(int id) {
-        mID = id;
-    }
-}
-
-public class SgTransform {
-
-
-    ScriptField_SgTransform mTransformField;
-    ScriptField_SgTransform mChildField;
-    public ScriptField_SgTransform.Item mTransformData;
-
-    RenderScript mRS;
-
-    Vector mChildren;
-    SgTransform mParent;
-    int mIndexInParentGroup;
-
-    public void setParent(SgTransform parent, int parentIndex) {
-        mParent = parent;
-        mIndexInParentGroup = parentIndex;
-    }
-
-    public void addChild(SgTransform child) {
-        mChildren.add(child);
-        child.setParent(this, mChildren.size() - 1);
-    }
-
-    public void setTransform(int index, Float4 value, TransformType type) {
-        mTransformData.transforms[index] = value;
-        mTransformData.transformTypes[index] = type.mID;
-    }
-
-    void initData() {
-        int numElements = mTransformData.transforms.length;
-        mTransformData.transformTypes = new int[numElements];
-        for (int i = 0; i < numElements; i ++) {
-            mTransformData.transforms[i] = new Float4(0, 0, 0, 0);
-            mTransformData.transformTypes[i] = TransformType.NONE.mID;
-        }
-
-        mTransformData.isDirty = 1;
-        mTransformData.children = null;
-    }
-
-    public SgTransform(RenderScript rs) {
-        mRS = rs;
-        mTransformData = new ScriptField_SgTransform.Item();
-        mChildren = new Vector();
-        initData();
-    }
-
-    public ScriptField_SgTransform.Item getData() {
-        if (mChildren.size() != 0) {
-            mChildField = new ScriptField_SgTransform(mRS, mChildren.size());
-            mTransformData.children = mChildField.getAllocation();
-
-            for (int i = 0; i < mChildren.size(); i ++) {
-                SgTransform child = (SgTransform)mChildren.get(i);
-                mChildField.set(child.getData(), i, false);
-            }
-            mChildField.copyAll();
-        }
-
-        return mTransformData;
-    }
-
-    public ScriptField_SgTransform getField() {
-        mTransformField = new ScriptField_SgTransform(mRS, 1);
-        mTransformField.set(getData(), 0, true);
-        return mTransformField;
-    }
-}
-
-
-
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SimpleModel.java b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SimpleModel.java
deleted file mode 100644
index 2b29ff4..0000000
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SimpleModel.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.modelviewer;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
-import android.app.Activity;
-import android.content.res.Configuration;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.provider.Settings.System;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.MenuInflater;
-import android.view.Window;
-import android.widget.Button;
-import android.widget.ListView;
-import android.net.Uri;
-
-import java.lang.Runtime;
-
-public class SimpleModel extends Activity {
-
-    private SimpleModelView mView;
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        // Create our Preview view and set it as the content of our
-        // Activity
-        mView = new SimpleModelView(this);
-        setContentView(mView);
-    }
-
-    @Override
-    protected void onResume() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
-        super.onResume();
-        mView.resume();
-    }
-
-    @Override
-    protected void onPause() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
-        super.onPause();
-        mView.pause();
-    }
-
-    @Override
-    public boolean onCreateOptionsMenu(Menu menu) {
-        MenuInflater inflater = getMenuInflater();
-        inflater.inflate(R.menu.loader_menu, menu);
-        return true;
-    }
-
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        // Handle item selection
-        switch (item.getItemId()) {
-        case R.id.load_model:
-            loadModel();
-            return true;
-        case R.id.display_options:
-            return true;
-        case R.id.sensor:
-            mView.toggleSensor();
-            return true;
-        default:
-            return super.onOptionsItemSelected(item);
-        }
-    }
-
-    private static final int FIND_A3D_MODEL = 10;
-    public void onActivityResult(int requestCode, int resultCode, Intent data) {
-        if (resultCode == RESULT_OK) {
-            if (requestCode == FIND_A3D_MODEL) {
-                Uri selectedImageUri = data.getData();
-                Log.e("Selected Path: ", selectedImageUri.getPath());
-                mView.loadA3DFile(selectedImageUri.getPath());
-            }
-        }
-    }
-
-    public void loadModel() {
-        Intent intent = new Intent();
-        intent.setAction(Intent.ACTION_PICK);
-        intent.setClassName("com.android.modelviewer",
-                            "com.android.modelviewer.A3DSelector");
-        startActivityForResult(intent, FIND_A3D_MODEL);
-    }
-
-}
-
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java
deleted file mode 100644
index 5fa3a9e..0000000
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.modelviewer;
-
-import java.io.Writer;
-
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.renderscript.ProgramStore.DepthFunc;
-import android.util.Log;
-
-
-public class SimpleModelRS {
-
-    public SimpleModelRS() {
-    }
-
-    public void init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-        initRS();
-    }
-
-    public void surfaceChanged() {
-        mRS.getWidth();
-        mRS.getHeight();
-    }
-
-    private Resources mRes;
-    private RenderScriptGL mRS;
-    private Sampler mSampler;
-    private ProgramStore mPSBackground;
-    private ProgramFragment mPFBackground;
-    private ProgramVertex mPVBackground;
-    private ProgramVertexFixedFunction.Constants mPVA;
-
-    private Allocation mGridImage;
-    private Allocation mAllocPV;
-
-    private Font mItalic;
-    private Allocation mTextAlloc;
-
-    private ScriptField_MeshInfo mMeshes;
-    private ScriptC_simplemodel mScript;
-
-
-    public void onActionDown(float x, float y) {
-        mScript.invoke_onActionDown(x, y);
-    }
-
-    public void onActionScale(float scale) {
-        mScript.invoke_onActionScale(scale);
-    }
-
-    public void onActionMove(float x, float y) {
-        mScript.invoke_onActionMove(x, y);
-    }
-
-    public void onPostureChanged(Matrix4f posture) {
-        mScript.set_gPostureMatrix(posture);
-    }
-
-    private void initPFS() {
-        ProgramStore.Builder b = new ProgramStore.Builder(mRS);
-
-        b.setDepthFunc(ProgramStore.DepthFunc.LESS);
-        b.setDitherEnabled(false);
-        b.setDepthMaskEnabled(true);
-        mPSBackground = b.create();
-
-        mScript.set_gPFSBackground(mPSBackground);
-    }
-
-    private void initPF() {
-        Sampler.Builder bs = new Sampler.Builder(mRS);
-        bs.setMinification(Sampler.Value.LINEAR);
-        bs.setMagnification(Sampler.Value.LINEAR);
-        bs.setWrapS(Sampler.Value.CLAMP);
-        bs.setWrapT(Sampler.Value.CLAMP);
-        mSampler = bs.create();
-
-        ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
-        b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
-                     ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
-        mPFBackground = b.create();
-        mPFBackground.bindSampler(mSampler, 0);
-
-        mScript.set_gPFBackground(mPFBackground);
-    }
-
-    private void initPV() {
-        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
-        mPVBackground = pvb.create();
-
-        mPVA = new ProgramVertexFixedFunction.Constants(mRS);
-        ((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA);
-
-        mScript.set_gPVBackground(mPVBackground);
-    }
-
-    private void loadImage() {
-        mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
-                                                         Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                                                         Allocation.USAGE_GRAPHICS_TEXTURE);
-        mScript.set_gTGrid(mGridImage);
-    }
-
-    private void initTextAllocation(String fileName) {
-        String allocString = "Displaying file: " + fileName;
-        mTextAlloc = Allocation.createFromString(mRS, allocString, Allocation.USAGE_SCRIPT);
-        mScript.set_gTextAlloc(mTextAlloc);
-    }
-
-    private void initMeshes(FileA3D model) {
-        int numEntries = model.getIndexEntryCount();
-        int numMeshes = 0;
-        for (int i = 0; i < numEntries; i ++) {
-            FileA3D.IndexEntry entry = model.getIndexEntry(i);
-            if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
-                numMeshes ++;
-            }
-        }
-
-        if (numMeshes > 0) {
-            mMeshes = new ScriptField_MeshInfo(mRS, numMeshes);
-
-            for (int i = 0; i < numEntries; i ++) {
-                FileA3D.IndexEntry entry = model.getIndexEntry(i);
-                if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
-                    Mesh mesh = entry.getMesh();
-                    mMeshes.set_mMesh(i, mesh, false);
-                    mMeshes.set_mNumIndexSets(i, mesh.getPrimitiveCount(), false);
-                }
-            }
-            mMeshes.copyAll();
-        } else {
-            throw new RSRuntimeException("No valid meshes in file");
-        }
-
-        mScript.bind_gMeshes(mMeshes);
-        mScript.invoke_updateMeshInfo();
-    }
-
-    public void loadA3DFile(String path) {
-        FileA3D model = FileA3D.createFromFile(mRS, path);
-        initMeshes(model);
-        initTextAllocation(path);
-    }
-
-    private void initRS() {
-
-        mScript = new ScriptC_simplemodel(mRS, mRes, R.raw.simplemodel);
-
-        initPFS();
-        initPF();
-        initPV();
-
-        loadImage();
-
-        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
-        initMeshes(model);
-
-        mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
-        mScript.set_gItalic(mItalic);
-
-        initTextAllocation("R.raw.robot");
-
-        mRS.bindRootScript(mScript);
-    }
-}
-
-
-
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SimpleModelView.java b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SimpleModelView.java
deleted file mode 100644
index 4b7836b..0000000
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/SimpleModelView.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.modelviewer;
-
-import android.renderscript.Matrix4f;
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScriptGL;
-
-import android.content.Context;
-import android.hardware.Sensor;
-import android.hardware.SensorEvent;
-import android.hardware.SensorEventListener;
-import android.hardware.SensorManager;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.ScaleGestureDetector;
-import android.util.Log;
-
-public class SimpleModelView extends RSSurfaceView implements SensorEventListener {
-
-    private RenderScriptGL mRS;
-    private SimpleModelRS mRender;
-
-    private ScaleGestureDetector mScaleDetector;
-
-    private SensorManager mSensorManager;
-    private Sensor mRotationVectorSensor;
-    private final float[] mRotationMatrix = new float[16];
-
-    private static final int INVALID_POINTER_ID = -1;
-    private int mActivePointerId = INVALID_POINTER_ID;
-    private boolean mUseSensor = false;
-    private Matrix4f mIdentityMatrix = new Matrix4f();
-
-    public SimpleModelView(Context context) {
-        super(context);
-        ensureRenderScript();
-        mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
-        // Get an instance of the SensorManager
-        mSensorManager = (SensorManager)getContext().getSystemService(Context.SENSOR_SERVICE);
-        // find the rotation-vector sensor
-        mRotationVectorSensor = mSensorManager.getDefaultSensor(
-                Sensor.TYPE_ROTATION_VECTOR);
-        mIdentityMatrix.loadIdentity();
-    }
-
-    private void ensureRenderScript() {
-        if (mRS == null) {
-            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            sc.setDepth(16, 24);
-            mRS = createRenderScriptGL(sc);
-            mRender = new SimpleModelRS();
-            mRender.init(mRS, getResources());
-        }
-    }
-
-    @Override
-    public void resume() {
-        mSensorManager.registerListener(this, mRotationVectorSensor, 10000);
-    }
-
-    @Override
-    public void pause() {
-        mSensorManager.unregisterListener(this);
-    }
-
-    @Override
-    protected void onAttachedToWindow() {
-        super.onAttachedToWindow();
-        ensureRenderScript();
-    }
-
-    @Override
-    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
-        super.surfaceChanged(holder, format, w, h);
-        mRender.surfaceChanged();
-    }
-
-    @Override
-    protected void onDetachedFromWindow() {
-        mRender = null;
-        if (mRS != null) {
-            mRS = null;
-            destroyRenderScriptGL();
-        }
-    }
-
-    public void loadA3DFile(String path) {
-        mRender.loadA3DFile(path);
-    }
-
-    @Override
-    public boolean onTouchEvent(MotionEvent ev) {
-        mScaleDetector.onTouchEvent(ev);
-
-        boolean ret = false;
-        float x = ev.getX();
-        float y = ev.getY();
-
-        final int action = ev.getAction();
-
-        switch (action & MotionEvent.ACTION_MASK) {
-        case MotionEvent.ACTION_DOWN: {
-            mRender.onActionDown(x, y);
-            mActivePointerId = ev.getPointerId(0);
-            ret = true;
-            break;
-        }
-        case MotionEvent.ACTION_MOVE: {
-            if (!mScaleDetector.isInProgress()) {
-                mRender.onActionMove(x, y);
-            }
-            mRender.onActionDown(x, y);
-            ret = true;
-            break;
-        }
-
-        case MotionEvent.ACTION_UP: {
-            mActivePointerId = INVALID_POINTER_ID;
-            break;
-        }
-
-        case MotionEvent.ACTION_CANCEL: {
-            mActivePointerId = INVALID_POINTER_ID;
-            break;
-        }
-
-        case MotionEvent.ACTION_POINTER_UP: {
-            final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
-                    >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
-            final int pointerId = ev.getPointerId(pointerIndex);
-            if (pointerId == mActivePointerId) {
-                // This was our active pointer going up. Choose a new
-                // active pointer and adjust accordingly.
-                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
-                x = ev.getX(newPointerIndex);
-                y = ev.getY(newPointerIndex);
-                mRender.onActionDown(x, y);
-                mActivePointerId = ev.getPointerId(newPointerIndex);
-            }
-            break;
-        }
-        }
-
-        return ret;
-    }
-
-    private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
-        @Override
-        public boolean onScale(ScaleGestureDetector detector) {
-            mRender.onActionScale(detector.getScaleFactor());
-            return true;
-        }
-    }
-
-    public void onSensorChanged(SensorEvent event) {
-        // we received a sensor event. it is a good practice to check
-        // that we received the proper event
-        if (mUseSensor) {
-            if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
-                // convert the rotation-vector to a 4x4 matrix. the matrix
-                // is interpreted by Open GL as the inverse of the
-                // rotation-vector, which is what we want.
-                SensorManager.getRotationMatrixFromVector(
-                        mRotationMatrix , event.values);
-
-                if (mRender != null) {
-                    mRender.onPostureChanged(new Matrix4f(mRotationMatrix));
-                }
-            }
-        }
-    }
-
-    public void onAccuracyChanged(Sensor sensor, int accuracy) {
-    }
-
-    public void toggleSensor() {
-        mUseSensor = !mUseSensor;
-        if (mUseSensor == false) {
-            mRender.onPostureChanged(mIdentityMatrix);
-        }
-    }
-}
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/scenegraph.rs b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/scenegraph.rs
deleted file mode 100644
index 5c5b1c9..0000000
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/scenegraph.rs
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright (C) 2009 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.modelviewer)
-
-#include "rs_graphics.rsh"
-#include "transform_def.rsh"
-
-rs_program_vertex gPVBackground;
-rs_program_fragment gPFBackground;
-
-rs_allocation gTGrid;
-rs_mesh gTestMesh;
-
-rs_program_store gPFSBackground;
-
-float gRotate;
-
-rs_font gItalic;
-rs_allocation gTextAlloc;
-
-rs_script gTransformRS;
-
-SgTransform *gGroup;
-SgTransform *gRobot1;
-int gRobot1Index;
-SgTransform *gRobot2;
-int gRobot2Index;
-
-SgTransform *gRootNode;
-
-void init() {
-    gRotate = 0.0f;
-}
-
-int root(void) {
-
-    gGroup->transforms[1].w += 0.5f;
-    gGroup->isDirty = 1;
-
-    SgTransform *robot1Ptr = gRobot1 + gRobot1Index;
-
-    robot1Ptr->transforms[1].w -= 1.5f;
-    robot1Ptr->isDirty = 1;
-
-    SgTransform *robot2Ptr = gRobot2 + gRobot2Index;
-    robot2Ptr->transforms[1].w += 2.5f;
-    robot2Ptr->isDirty = 1;
-
-    rsForEach(gTransformRS, gRootNode->children, gRootNode->children);
-
-    rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgClearDepth(1.0f);
-
-    rsgBindProgramVertex(gPVBackground);
-    rs_matrix4x4 proj;
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
-    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-
-    rsgBindProgramFragment(gPFBackground);
-    rsgBindProgramStore(gPFSBackground);
-    rsgBindTexture(gPFBackground, 0, gTGrid);
-
-    rsgProgramVertexLoadModelMatrix(&robot1Ptr->globalMat);
-    rsgDrawMesh(gTestMesh);
-
-    rsgProgramVertexLoadModelMatrix(&robot2Ptr->globalMat);
-    rsgDrawMesh(gTestMesh);
-
-    //color(0.3f, 0.3f, 0.3f, 1.0f);
-    rsgDrawText("Renderscript transform test", 30, 695);
-
-    rsgBindFont(gItalic);
-    rsgDrawText(gTextAlloc, 30, 730);
-
-    return 10;
-}
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/simplemodel.rs b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/simplemodel.rs
deleted file mode 100644
index d3dd5b9..0000000
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/simplemodel.rs
+++ /dev/null
@@ -1,172 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.modelviewer)
-
-#include "rs_graphics.rsh"
-
-rs_program_vertex gPVBackground;
-rs_program_fragment gPFBackground;
-
-rs_allocation gTGrid;
-
-rs_program_store gPFSBackground;
-
-rs_font gItalic;
-rs_allocation gTextAlloc;
-
-rs_matrix4x4 gPostureMatrix;
-
-typedef struct MeshInfo {
-    rs_mesh mMesh;
-    int mNumIndexSets;
-    float3 bBoxMin;
-    float3 bBoxMax;
-} MeshInfo_t;
-
-MeshInfo_t *gMeshes;
-
-static float3 gLookAt;
-
-static float gRotateX;
-static float gRotateY;
-static float gZoom;
-
-static float gLastX;
-static float gLastY;
-
-static float3 toFloat3(float x, float y, float z) {
-    float3 f;
-    f.x = x;
-    f.y = y;
-    f.z = z;
-    return f;
-}
-
-void onActionDown(float x, float y) {
-    gLastX = x;
-    gLastY = y;
-}
-
-void onActionScale(float scale) {
-
-    gZoom *= 1.0f / scale;
-    gZoom = max(0.1f, min(gZoom, 500.0f));
-}
-
-void onActionMove(float x, float y) {
-    float dx = gLastX - x;
-    float dy = gLastY - y;
-
-    if (fabs(dy) <= 2.0f) {
-        dy = 0.0f;
-    }
-    if (fabs(dx) <= 2.0f) {
-        dx = 0.0f;
-    }
-
-    gRotateY -= dx;
-    if (gRotateY > 360) {
-        gRotateY -= 360;
-    }
-    if (gRotateY < 0) {
-        gRotateY += 360;
-    }
-
-    gRotateX -= dy;
-    gRotateX = min(gRotateX, 80.0f);
-    gRotateX = max(gRotateX, -80.0f);
-
-    gLastX = x;
-    gLastY = y;
-}
-
-void init() {
-    gRotateX = 0.0f;
-    gRotateY = 0.0f;
-    gZoom = 50.0f;
-    gLookAt = 0.0f;
-    rsMatrixLoadIdentity(&gPostureMatrix);
-}
-
-void updateMeshInfo() {
-    rs_allocation allMeshes = rsGetAllocation(gMeshes);
-    int size = rsAllocationGetDimX(allMeshes);
-    gLookAt = 0.0f;
-    float minX, minY, minZ, maxX, maxY, maxZ;
-    for (int i = 0; i < size; i++) {
-        MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
-        rsgMeshComputeBoundingBox(info->mMesh,
-                                  &minX, &minY, &minZ,
-                                  &maxX, &maxY, &maxZ);
-        info->bBoxMin = toFloat3(minX, minY, minZ);
-        info->bBoxMax = toFloat3(maxX, maxY, maxZ);
-        gLookAt += (info->bBoxMin + info->bBoxMax)*0.5f;
-    }
-    gLookAt = gLookAt / (float)size;
-}
-
-static void renderAllMeshes() {
-    rs_allocation allMeshes = rsGetAllocation(gMeshes);
-    int size = rsAllocationGetDimX(allMeshes);
-    gLookAt = 0.0f;
-    for (int i = 0; i < size; i++) {
-        MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
-        rsgDrawMesh(info->mMesh);
-    }
-}
-
-void drawDescription() {
-    uint height = rsgGetHeight();
-    int left = 0, right = 0, top = 0, bottom = 0;
-
-    rsgBindFont(gItalic);
-
-    rsgMeasureText(gTextAlloc, &left, &right, &top, &bottom);
-    rsgDrawText(gTextAlloc, 2 -left, height - 2 + bottom);
-}
-
-int root(void) {
-
-    rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgClearDepth(1.0f);
-
-    rsgBindProgramVertex(gPVBackground);
-    rs_matrix4x4 proj;
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
-    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-
-    rsgBindProgramFragment(gPFBackground);
-    rsgBindProgramStore(gPFSBackground);
-    rsgBindTexture(gPFBackground, 0, gTGrid);
-
-    rs_matrix4x4 matrix;
-    rsMatrixLoadIdentity(&matrix);
-    // Position our models on the screen
-    rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
-    rsMatrixMultiply(&matrix, &gPostureMatrix);
-    rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
-    rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
-
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    renderAllMeshes();
-
-    drawDescription();
-
-    return 0;
-}
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/transform.rs b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/transform.rs
deleted file mode 100644
index 85c0630..0000000
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/transform.rs
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright (C) 2009 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.modelviewer)
-
-#include "transform_def.rsh"
-
-rs_script transformScript;
-
-typedef struct {
-    int changed;
-    rs_matrix4x4 *mat;
-} ParentData;
-
-static void appendTransformation(int type, float4 data, rs_matrix4x4 *mat) {
-    rs_matrix4x4 temp;
-
-    switch (type) {
-    case TRANSFORM_TRANSLATE:
-        rsMatrixLoadTranslate(&temp, data.x, data.y, data.z);
-        break;
-    case TRANSFORM_ROTATE:
-        rsMatrixLoadRotate(&temp, data.w, data.x, data.y, data.z);
-        break;
-    case TRANSFORM_SCALE:
-        rsMatrixLoadScale(&temp, data.x, data.y, data.z);
-        break;
-    }
-    rsMatrixMultiply(mat, &temp);
-}
-
-void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) {
-
-    SgTransform *data = (SgTransform *)v_out;
-    const ParentData *parent = (const ParentData *)usrData;
-
-    //rsDebug("Transform data", (int)data);
-    //rsDebug("Entering parent", (int)parent);
-
-    rs_matrix4x4 *localMat = &data->localMat;
-    rs_matrix4x4 *globalMat = &data->globalMat;
-
-    ParentData toChild;
-    toChild.changed = 0;
-    toChild.mat = globalMat;
-
-    //rsDebug("Transform is dirty", data->isDirty);
-
-    // Refresh matrices if dirty
-    if (data->isDirty) {
-        data->isDirty = 0;
-        toChild.changed = 1;
-
-        // Reset our local matrix
-        rsMatrixLoadIdentity(localMat);
-
-        for (int i = 0; i < 16; i ++) {
-            if (data->transformTypes[i] == TRANSFORM_NONE) {
-                break;
-            }
-            //rsDebug("Transform adding transformation", transformTypes[i]);
-            appendTransformation(data->transformTypes[i], data->transforms[i], localMat);
-        }
-    }
-
-    //rsDebug("Transform checking parent", (int)0);
-
-    if (parent) {
-        if (parent->changed) {
-            toChild.changed = 1;
-
-            rsMatrixLoad(globalMat, parent->mat);
-            rsMatrixMultiply(globalMat, localMat);
-        }
-    } else {
-        rsMatrixLoad(globalMat, localMat);
-    }
-
-    //rsDebug("Transform calling self with child ", (int)data->children.p);
-    if (data->children.p) {
-        rsForEach(transformScript, data->children, data->children, (void*)&toChild, sizeof(toChild));
-    }
-}
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/transform_def.rsh b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/transform_def.rsh
deleted file mode 100644
index 24a36c1..0000000
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/transform_def.rsh
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (C) 2009 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.modelviewer)
-
-#define TRANSFORM_NONE 0
-#define TRANSFORM_TRANSLATE 1
-#define TRANSFORM_ROTATE 2
-#define TRANSFORM_SCALE 3
-
-typedef struct __attribute__((packed, aligned(4))) SgTransform {
-    rs_matrix4x4 globalMat;
-    rs_matrix4x4 localMat;
-
-    float4 transforms[16];
-    int transformTypes[16];
-
-    int isDirty;
-
-    rs_allocation children;
-
-} SgTransform;
diff --git a/tests/RenderScriptTests/PerfTest/Android.mk b/tests/RenderScriptTests/PerfTest/Android.mk
deleted file mode 100644
index e9ee771..0000000
--- a/tests/RenderScriptTests/PerfTest/Android.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# Copyright (C) 2008 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
-#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
-
-LOCAL_SDK_VERSION := 17
-
-LOCAL_PACKAGE_NAME := PerfTest
-
-include $(BUILD_PACKAGE)
diff --git a/tests/RenderScriptTests/PerfTest/AndroidManifest.xml b/tests/RenderScriptTests/PerfTest/AndroidManifest.xml
deleted file mode 100644
index cc60396..0000000
--- a/tests/RenderScriptTests/PerfTest/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.android.perftest">
-    
-    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-    
-    <uses-sdk android:minSdkVersion="11" />
-    <application android:label="PerfTest"
-      android:icon="@drawable/test_pattern">
-        <uses-library android:name="android.test.runner" />
-        <activity android:name="RsBench"
-                  android:label="RsBenchmark">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-      </application>
-
-      <instrumentation android:name=".RsPerfTestRunner"
-        android:targetPackage="com.android.perftest"
-        android:label="Test runner for RsBench tests"
-      />
-</manifest>
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/checker.png b/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/checker.png
deleted file mode 100644
index b631e1e..0000000
--- a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/checker.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/data.png b/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/data.png
deleted file mode 100644
index 8e34714..0000000
--- a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/data.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/flares.png b/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/flares.png
deleted file mode 100644
index 3a5c970..0000000
--- a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/flares.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/globe.png b/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/globe.png
deleted file mode 100644
index f9d6172..0000000
--- a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/globe.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/leaf.png b/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/leaf.png
deleted file mode 100644
index 3cd3775..0000000
--- a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/leaf.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/light1.jpg b/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/light1.jpg
deleted file mode 100644
index 2f2f10e..0000000
--- a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/light1.jpg
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/space.jpg b/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/space.jpg
deleted file mode 100644
index b61f6a3..0000000
--- a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/space.jpg
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/test_pattern.png b/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/test_pattern.png
deleted file mode 100644
index e7d1455..0000000
--- a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/test_pattern.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/torusmap.png b/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/torusmap.png
deleted file mode 100644
index 1e08f3b..0000000
--- a/tests/RenderScriptTests/PerfTest/res/drawable-nodpi/torusmap.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/menu/loader_menu.xml b/tests/RenderScriptTests/PerfTest/res/menu/loader_menu.xml
deleted file mode 100644
index 59a251d..0000000
--- a/tests/RenderScriptTests/PerfTest/res/menu/loader_menu.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-* Copyright (C) 2011 The Android Open Source Project
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
--->
-
-<menu xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:id="@+id/benchmark_all"
-          android:title="@string/benchmark_all" />
-    <item android:id="@+id/benchmark_one"
-          android:title="@string/benchmark_one" />
-    <item android:id="@+id/debug_mode"
-          android:title="@string/debug_mode" />
-</menu>
-
diff --git a/tests/RenderScriptTests/PerfTest/res/raw/multitexf.glsl b/tests/RenderScriptTests/PerfTest/res/raw/multitexf.glsl
deleted file mode 100644
index e492a47..0000000
--- a/tests/RenderScriptTests/PerfTest/res/raw/multitexf.glsl
+++ /dev/null
@@ -1,13 +0,0 @@
-varying vec2 varTex0;
-
-void main() {
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col0 = texture2D(UNI_Tex0, t0).rgba;
-   lowp vec4 col1 = texture2D(UNI_Tex1, t0*4.0).rgba;
-   lowp vec4 col2 = texture2D(UNI_Tex2, t0).rgba;
-   col0.xyz = col0.xyz*col1.xyz*1.5;
-   col0.xyz = mix(col0.xyz, col2.xyz, col2.w);
-   col0.w = 0.5;
-   gl_FragColor = col0;
-}
-
diff --git a/tests/RenderScriptTests/PerfTest/res/raw/shader2f.glsl b/tests/RenderScriptTests/PerfTest/res/raw/shader2f.glsl
deleted file mode 100644
index 5fc05f1..0000000
--- a/tests/RenderScriptTests/PerfTest/res/raw/shader2f.glsl
+++ /dev/null
@@ -1,29 +0,0 @@
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-void main() {
-
-   vec3 V = normalize(-varWorldPos.xyz);
-   vec3 worldNorm = normalize(varWorldNormal);
-
-   vec3 light0Vec = normalize(UNI_light0_Posision.xyz - varWorldPos);
-   vec3 light0R = -reflect(light0Vec, worldNorm);
-   float light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0) * UNI_light0_Diffuse;
-   float light0Spec = clamp(dot(light0R, V), 0.001, 1.0);
-   float light0_Specular = pow(light0Spec, UNI_light0_CosinePower) * UNI_light0_Specular;
-
-   vec3 light1Vec = normalize(UNI_light1_Posision.xyz - varWorldPos);
-   vec3 light1R = reflect(light1Vec, worldNorm);
-   float light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0) * UNI_light1_Diffuse;
-   float light1Spec = clamp(dot(light1R, V), 0.001, 1.0);
-   float light1_Specular = pow(light1Spec, UNI_light1_CosinePower) * UNI_light1_Specular;
-
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col = texture2D(UNI_Tex0, t0).rgba;
-   col.xyz = col.xyz * (light0_Diffuse * UNI_light0_DiffuseColor.xyz + light1_Diffuse * UNI_light1_DiffuseColor.xyz);
-   col.xyz += light0_Specular * UNI_light0_SpecularColor.xyz;
-   col.xyz += light1_Specular * UNI_light1_SpecularColor.xyz;
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/PerfTest/res/raw/shader2movev.glsl b/tests/RenderScriptTests/PerfTest/res/raw/shader2movev.glsl
deleted file mode 100644
index a2c807e..0000000
--- a/tests/RenderScriptTests/PerfTest/res/raw/shader2movev.glsl
+++ /dev/null
@@ -1,21 +0,0 @@
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-// This is where actual shader code begins
-void main() {
-   vec4 objPos = ATTRIB_position;
-   vec3 oldPos = objPos.xyz;
-   objPos.xyz += 0.1*sin(objPos.xyz*2.0 + UNI_time);
-   objPos.xyz += 0.05*sin(objPos.xyz*4.0 + UNI_time*0.5);
-   objPos.xyz += 0.02*sin(objPos.xyz*7.0 + UNI_time*0.75);
-   vec4 worldPos = UNI_model * objPos;
-   gl_Position = UNI_proj * worldPos;
-
-   mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
-   vec3 worldNorm = model3 * (ATTRIB_normal + oldPos - objPos.xyz);
-
-   varWorldPos = worldPos.xyz;
-   varWorldNormal = worldNorm;
-   varTex0 = ATTRIB_texture0;
-}
diff --git a/tests/RenderScriptTests/PerfTest/res/raw/shader2v.glsl b/tests/RenderScriptTests/PerfTest/res/raw/shader2v.glsl
deleted file mode 100644
index e6885a3..0000000
--- a/tests/RenderScriptTests/PerfTest/res/raw/shader2v.glsl
+++ /dev/null
@@ -1,17 +0,0 @@
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-// This is where actual shader code begins
-void main() {
-   vec4 objPos = ATTRIB_position;
-   vec4 worldPos = UNI_model * objPos;
-   gl_Position = UNI_proj * worldPos;
-
-   mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
-   vec3 worldNorm = model3 * ATTRIB_normal;
-
-   varWorldPos = worldPos.xyz;
-   varWorldNormal = worldNorm;
-   varTex0 = ATTRIB_texture0;
-}
diff --git a/tests/RenderScriptTests/PerfTest/res/raw/shaderf.glsl b/tests/RenderScriptTests/PerfTest/res/raw/shaderf.glsl
deleted file mode 100644
index d56e203..0000000
--- a/tests/RenderScriptTests/PerfTest/res/raw/shaderf.glsl
+++ /dev/null
@@ -1,16 +0,0 @@
-
-varying lowp float light0_Diffuse;
-varying lowp float light0_Specular;
-varying lowp float light1_Diffuse;
-varying lowp float light1_Specular;
-varying vec2 varTex0;
-
-void main() {
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col = texture2D(UNI_Tex0, t0).rgba;
-   col.xyz = col.xyz * (light0_Diffuse * UNI_light0_DiffuseColor.xyz + light1_Diffuse * UNI_light1_DiffuseColor.xyz);
-   col.xyz += light0_Specular * UNI_light0_SpecularColor.xyz;
-   col.xyz += light1_Specular * UNI_light1_SpecularColor.xyz;
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/PerfTest/res/raw/shaderv.glsl b/tests/RenderScriptTests/PerfTest/res/raw/shaderv.glsl
deleted file mode 100644
index f7d01de..0000000
--- a/tests/RenderScriptTests/PerfTest/res/raw/shaderv.glsl
+++ /dev/null
@@ -1,30 +0,0 @@
-varying float light0_Diffuse;
-varying float light0_Specular;
-varying float light1_Diffuse;
-varying float light1_Specular;
-varying vec2 varTex0;
-
-// This is where actual shader code begins
-void main() {
-   vec4 worldPos = UNI_model * ATTRIB_position;
-   gl_Position = UNI_proj * worldPos;
-
-   mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
-   vec3 worldNorm = model3 * ATTRIB_normal;
-   vec3 V = normalize(-worldPos.xyz);
-
-   vec3 light0Vec = normalize(UNI_light0_Posision.xyz - worldPos.xyz);
-   vec3 light0R = -reflect(light0Vec, worldNorm);
-   light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0) * UNI_light0_Diffuse;
-   float light0Spec = clamp(dot(light0R, V), 0.001, 1.0);
-   light0_Specular = pow(light0Spec, UNI_light0_CosinePower) * UNI_light0_Specular;
-
-   vec3 light1Vec = normalize(UNI_light1_Posision.xyz - worldPos.xyz);
-   vec3 light1R = reflect(light1Vec, worldNorm);
-   light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0) * UNI_light1_Diffuse;
-   float light1Spec = clamp(dot(light1R, V), 0.001, 1.0);
-   light1_Specular = pow(light1Spec, UNI_light1_CosinePower) * UNI_light1_Specular;
-
-   gl_PointSize = 1.0;
-   varTex0 = ATTRIB_texture0;
-}
diff --git a/tests/RenderScriptTests/PerfTest/res/raw/singletexf.glsl b/tests/RenderScriptTests/PerfTest/res/raw/singletexf.glsl
deleted file mode 100644
index 83dfc7f..0000000
--- a/tests/RenderScriptTests/PerfTest/res/raw/singletexf.glsl
+++ /dev/null
@@ -1,8 +0,0 @@
-varying vec2 varTex0;
-
-void main() {
-   lowp vec3 col0 = texture2D(UNI_Tex0, varTex0).rgb;
-   gl_FragColor.xyz = col0;
-   gl_FragColor.w = 0.5;
-}
-
diff --git a/tests/RenderScriptTests/PerfTest/res/raw/singletexfm.glsl b/tests/RenderScriptTests/PerfTest/res/raw/singletexfm.glsl
deleted file mode 100644
index 656961c..0000000
--- a/tests/RenderScriptTests/PerfTest/res/raw/singletexfm.glsl
+++ /dev/null
@@ -1,8 +0,0 @@
-varying vec2 varTex0;
-
-void main() {
-   lowp vec3 col0 = texture2D(UNI_Tex0, varTex0).rgb;
-   gl_FragColor.xyz = col0 * UNI_modulate.rgb;
-   gl_FragColor.w = UNI_modulate.a;
-}
-
diff --git a/tests/RenderScriptTests/PerfTest/res/raw/torus.a3d b/tests/RenderScriptTests/PerfTest/res/raw/torus.a3d
deleted file mode 100644
index 0322b01..0000000
--- a/tests/RenderScriptTests/PerfTest/res/raw/torus.a3d
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/PerfTest/res/values/strings.xml b/tests/RenderScriptTests/PerfTest/res/values/strings.xml
deleted file mode 100644
index ce9819e..0000000
--- a/tests/RenderScriptTests/PerfTest/res/values/strings.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-* Copyright (C) 2011 The Android Open Source Project
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
--->
-
-<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <skip />
-    <string name="benchmark_all">Benchmark All</string>
-    <string name="benchmark_one">Benchmark One</string>
-    <string name="debug_mode">Debug Mode</string>
-</resources>
-
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/FillTest.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/FillTest.java
deleted file mode 100644
index 41f664a..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/FillTest.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.perftest;
-
-import android.os.Environment;
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-
-
-import android.util.Log;
-
-
-public class FillTest implements RsBenchBaseTest{
-
-    private static final String TAG = "FillTest";
-    private RenderScriptGL mRS;
-    private Resources mRes;
-
-    // Custom shaders
-    private ProgramFragment mProgFragmentMultitex;
-    private ProgramFragment mProgFragmentSingletex;
-    private ProgramFragment mProgFragmentSingletexModulate;
-    private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
-    int mBenchmarkDimX;
-    int mBenchmarkDimY;
-
-    private ScriptC_fill_test mFillScript;
-    ScriptField_TestScripts_s.Item[] mTests;
-    ScriptField_FillTestFragData_s mFragData;
-
-    private final String[] mNames = {
-        "Fill screen 10x singletexture",
-        "Fill screen 10x 3tex multitexture",
-        "Fill screen 10x blended singletexture",
-        "Fill screen 10x blended 3tex multitexture",
-        "Fill screen 3x modulate blended singletexture",
-        "Fill screen 1x modulate blended singletexture",
-    };
-
-    public FillTest() {
-        mOptionsARGB.inScaled = false;
-        mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
-        mBenchmarkDimX = 1280;
-        mBenchmarkDimY = 720;
-    }
-
-    void addTest(int index, int testId, int blend, int quadCount) {
-        mTests[index] = new ScriptField_TestScripts_s.Item();
-        mTests[index].testScript = mFillScript;
-        mTests[index].testName = Allocation.createFromString(mRS,
-                                                             mNames[index],
-                                                             Allocation.USAGE_SCRIPT);
-        mTests[index].debugName = RsBenchRS.createZeroTerminatedAlloc(mRS,
-                                                                      mNames[index],
-                                                                      Allocation.USAGE_SCRIPT);
-
-        ScriptField_FillTestData_s.Item dataItem = new ScriptField_FillTestData_s.Item();
-        dataItem.testId = testId;
-        dataItem.blend = blend;
-        dataItem.quadCount = quadCount;
-        ScriptField_FillTestData_s testData = new ScriptField_FillTestData_s(mRS, 1);
-        testData.set(dataItem, 0, true);
-        mTests[index].testData = testData.getAllocation();
-    }
-
-    public boolean init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-        initCustomShaders();
-        initFillScript();
-        mTests = new ScriptField_TestScripts_s.Item[mNames.length];
-
-        int index = 0;
-
-        addTest(index++, 1 /*testId*/, 0 /*blend*/, 10 /*quadCount*/);
-        addTest(index++, 0 /*testId*/, 0 /*blend*/, 10 /*quadCount*/);
-        addTest(index++, 1 /*testId*/, 1 /*blend*/, 10 /*quadCount*/);
-        addTest(index++, 0 /*testId*/, 1 /*blend*/, 10 /*quadCount*/);
-        addTest(index++, 2 /*testId*/, 1 /*blend*/, 3 /*quadCount*/);
-        addTest(index++, 2 /*testId*/, 1 /*blend*/, 1 /*quadCount*/);
-
-        return true;
-    }
-
-    public ScriptField_TestScripts_s.Item[] getTests() {
-        return mTests;
-    }
-
-    public String[] getTestNames() {
-        return mNames;
-    }
-
-    private void initCustomShaders() {
-        ProgramFragment.Builder pfbCustom = new ProgramFragment.Builder(mRS);
-        pfbCustom.setShader(mRes, R.raw.multitexf);
-        for (int texCount = 0; texCount < 3; texCount ++) {
-            pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
-        }
-        mProgFragmentMultitex = pfbCustom.create();
-
-        pfbCustom = new ProgramFragment.Builder(mRS);
-        pfbCustom.setShader(mRes, R.raw.singletexf);
-        pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
-        mProgFragmentSingletex = pfbCustom.create();
-
-        pfbCustom = new ProgramFragment.Builder(mRS);
-        pfbCustom.setShader(mRes, R.raw.singletexfm);
-        pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
-        mFragData = new ScriptField_FillTestFragData_s(mRS, 1);
-        pfbCustom.addConstant(mFragData.getType());
-        mProgFragmentSingletexModulate = pfbCustom.create();
-        mProgFragmentSingletexModulate.bindConstants(mFragData.getAllocation(), 0);
-    }
-
-    private Allocation loadTextureARGB(int id) {
-        Bitmap b = BitmapFactory.decodeResource(mRes, id, mOptionsARGB);
-        return Allocation.createFromBitmap(mRS, b,
-                Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                Allocation.USAGE_GRAPHICS_TEXTURE);
-    }
-
-    private Allocation loadTextureRGB(int id) {
-        return Allocation.createFromBitmapResource(mRS, mRes, id,
-                Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                Allocation.USAGE_GRAPHICS_TEXTURE);
-    }
-
-    void initFillScript() {
-        mFillScript = new ScriptC_fill_test(mRS, mRes, R.raw.fill_test);
-
-        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
-        ProgramVertexFixedFunction progVertex = pvb.create();
-        ProgramVertexFixedFunction.Constants PVA = new ProgramVertexFixedFunction.Constants(mRS);
-        ((ProgramVertexFixedFunction)progVertex).bindConstants(PVA);
-        Matrix4f proj = new Matrix4f();
-        proj.loadOrthoWindow(mBenchmarkDimX, mBenchmarkDimY);
-        PVA.setProjection(proj);
-        mFillScript.set_gProgVertex(progVertex);
-
-        mFillScript.set_gProgFragmentTexture(mProgFragmentSingletex);
-        mFillScript.set_gProgFragmentTextureModulate(mProgFragmentSingletexModulate);
-        mFillScript.set_gProgFragmentMultitex(mProgFragmentMultitex);
-        mFillScript.set_gProgStoreBlendNone(ProgramStore.BLEND_NONE_DEPTH_NONE(mRS));
-        mFillScript.set_gProgStoreBlendAlpha(ProgramStore.BLEND_ALPHA_DEPTH_NONE(mRS));
-
-        mFillScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS));
-        mFillScript.set_gLinearWrap(Sampler.WRAP_LINEAR(mRS));
-        mFillScript.set_gTexTorus(loadTextureRGB(R.drawable.torusmap));
-        mFillScript.set_gTexOpaque(loadTextureRGB(R.drawable.data));
-        mFillScript.set_gTexTransparent(loadTextureARGB(R.drawable.leaf));
-        mFillScript.set_gTexChecker(loadTextureRGB(R.drawable.checker));
-
-        mFillScript.bind_gFragData(mFragData);
-    }
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/MeshTest.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/MeshTest.java
deleted file mode 100644
index cdb4435..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/MeshTest.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.perftest;
-
-import android.os.Environment;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.renderscript.*;
-import android.renderscript.Element.DataKind;
-import android.renderscript.Element.DataType;
-import android.renderscript.Allocation.MipmapControl;
-import android.renderscript.Program.TextureType;
-import android.renderscript.RenderScript.RSMessageHandler;
-import android.renderscript.Mesh.Primitive;
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramVertexFixedFunction;
-
-import android.util.Log;
-
-
-public class MeshTest implements RsBenchBaseTest{
-
-    private static final String TAG = "MeshTest";
-    private RenderScriptGL mRS;
-    private Resources mRes;
-
-    int mBenchmarkDimX;
-    int mBenchmarkDimY;
-
-    private Mesh m10by10Mesh;
-    private Mesh m100by100Mesh;
-    private Mesh mWbyHMesh;
-
-    private ScriptC_mesh_test mGeoScript;
-
-    private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
-
-    ScriptField_TestScripts_s.Item[] mTests;
-
-    private final String[] mNames = {
-        "Full screen mesh 10 by 10",
-        "Full screen mesh 100 by 100",
-        "Full screen mesh W / 4 by H / 4"
-    };
-
-    public MeshTest() {
-        mBenchmarkDimX = 1280;
-        mBenchmarkDimY = 720;
-    }
-
-    void addTest(int index, int meshNum) {
-        mTests[index] = new ScriptField_TestScripts_s.Item();
-        mTests[index].testScript = mGeoScript;
-        mTests[index].testName = Allocation.createFromString(mRS,
-                                                             mNames[index],
-                                                             Allocation.USAGE_SCRIPT);
-        mTests[index].debugName = RsBenchRS.createZeroTerminatedAlloc(mRS,
-                                                                      mNames[index],
-                                                                      Allocation.USAGE_SCRIPT);
-
-        ScriptField_MeshTestData_s.Item dataItem = new ScriptField_MeshTestData_s.Item();
-        dataItem.meshNum = meshNum;
-        ScriptField_MeshTestData_s testData = new ScriptField_MeshTestData_s(mRS, 1);
-        testData.set(dataItem, 0, true);
-        mTests[index].testData = testData.getAllocation();
-    }
-
-    public boolean init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-        initGeoScript();
-        mTests = new ScriptField_TestScripts_s.Item[mNames.length];
-
-        int index = 0;
-        addTest(index++, 0 /*meshNum*/);
-        addTest(index++, 1 /*meshNum*/);
-        addTest(index++, 2 /*meshNum*/);
-
-        return true;
-    }
-
-    public ScriptField_TestScripts_s.Item[] getTests() {
-        return mTests;
-    }
-
-    public String[] getTestNames() {
-        return mNames;
-    }
-
-    private Mesh getMbyNMesh(float width, float height, int wResolution, int hResolution) {
-
-        Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS,
-                                           2, Mesh.TriangleMeshBuilder.TEXTURE_0);
-
-        for (int y = 0; y <= hResolution; y++) {
-            final float normalizedY = (float)y / hResolution;
-            final float yOffset = (normalizedY - 0.5f) * height;
-            for (int x = 0; x <= wResolution; x++) {
-                float normalizedX = (float)x / wResolution;
-                float xOffset = (normalizedX - 0.5f) * width;
-                tmb.setTexture((float)x % 2, (float)y % 2);
-                tmb.addVertex(xOffset, yOffset);
-             }
-        }
-
-        for (int y = 0; y < hResolution; y++) {
-            final int curY = y * (wResolution + 1);
-            final int belowY = (y + 1) * (wResolution + 1);
-            for (int x = 0; x < wResolution; x++) {
-                int curV = curY + x;
-                int belowV = belowY + x;
-                tmb.addTriangle(curV, belowV, curV + 1);
-                tmb.addTriangle(belowV, belowV + 1, curV + 1);
-            }
-        }
-
-        return tmb.create(true);
-    }
-
-    private Allocation loadTextureRGB(int id) {
-        return Allocation.createFromBitmapResource(mRS, mRes, id,
-                Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                Allocation.USAGE_GRAPHICS_TEXTURE);
-    }
-
-    void initGeoScript() {
-        mGeoScript = new ScriptC_mesh_test(mRS, mRes, R.raw.mesh_test);
-
-        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
-        ProgramVertexFixedFunction progVertex = pvb.create();
-        ProgramVertexFixedFunction.Constants PVA = new ProgramVertexFixedFunction.Constants(mRS);
-        ((ProgramVertexFixedFunction)progVertex).bindConstants(PVA);
-        Matrix4f proj = new Matrix4f();
-        proj.loadOrthoWindow(mBenchmarkDimX, mBenchmarkDimY);
-        PVA.setProjection(proj);
-
-        mGeoScript.set_gProgVertex(progVertex);
-        ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
-        texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
-                              ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
-        mGeoScript.set_gProgFragmentTexture(texBuilder.create());
-        mGeoScript.set_gProgStoreBlendNone(ProgramStore.BLEND_NONE_DEPTH_NONE(mRS));
-
-        mGeoScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS));
-        mGeoScript.set_gTexOpaque(loadTextureRGB(R.drawable.data));
-
-        m10by10Mesh = getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, 10, 10);
-        m100by100Mesh = getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, 100, 100);
-        mWbyHMesh= getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, mBenchmarkDimX/4, mBenchmarkDimY/4);
-
-        mGeoScript.set_g10by10Mesh(m10by10Mesh);
-        mGeoScript.set_g100by100Mesh(m100by100Mesh);
-        mGeoScript.set_gWbyHMesh(mWbyHMesh);
-    }
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBench.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBench.java
deleted file mode 100644
index 0dceafe..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBench.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.perftest;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
-import android.app.Activity;
-import android.content.res.Configuration;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.provider.Settings.System;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.MenuInflater;
-import android.view.View;
-import android.view.Window;
-import android.widget.Button;
-import android.widget.ListView;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
-import android.widget.Toast;
-
-import java.lang.Runtime;
-
-public class RsBench extends Activity {
-    private final String TAG = "RsBench";
-    public RsBenchView mView;
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-        int iterations = 0;
-        Intent intent = getIntent();
-        Uri uri = intent.getData();
-        if (uri != null) {
-            // when lauched from instrumentation
-            String scheme = uri.getScheme();
-            if ("iterations".equals(scheme)) {
-                iterations = Integer.parseInt(uri.getSchemeSpecificPart());
-            }
-        }
-        // Create our Preview view and set it as the content of our
-        // Activity
-        mView = new RsBenchView(this);
-        setContentView(mView);
-        mView.setLoops(iterations);
-    }
-
-    @Override
-    protected void onResume() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity loses focus
-        super.onResume();
-        mView.resume();
-    }
-
-    @Override
-    protected void onPause() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity loses focus
-        super.onPause();
-        mView.pause();
-    }
-
-    @Override
-    public boolean onCreateOptionsMenu(Menu menu) {
-        MenuInflater inflater = getMenuInflater();
-        inflater.inflate(R.menu.loader_menu, menu);
-        return true;
-    }
-
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        // Handle item selection
-        switch (item.getItemId()) {
-            case R.id.benchmark_all:
-                mView.setBenchmarkMode(-1);
-                mView.suspendRendering(false);
-                return true;
-            case R.id.benchmark_one:
-                mView.suspendRendering(true);
-                AlertDialog.Builder builder = new AlertDialog.Builder(this);
-                builder.setTitle("Pick a Test");
-                builder.setItems(mView.getTestNames(),
-                                 new DialogInterface.OnClickListener() {
-                    public void onClick(DialogInterface dialog, int item) {
-                        Toast.makeText(getApplicationContext(),
-                                       "Starting to benchmark: " + mView.getTestNames()[item],
-                                       Toast.LENGTH_SHORT).show();
-                        mView.setBenchmarkMode(item);
-                        mView.suspendRendering(false);
-                    }
-                });
-                builder.show();
-                return true;
-            case R.id.debug_mode:
-                mView.suspendRendering(true);
-                AlertDialog.Builder debugBuilder = new AlertDialog.Builder(this);
-                debugBuilder.setTitle("Pick a Test");
-                debugBuilder.setItems(mView.getTestNames(),
-                                 new DialogInterface.OnClickListener() {
-                    public void onClick(DialogInterface dialog, int item) {
-                        Toast.makeText(getApplicationContext(),
-                                       "Switching to: " + mView.getTestNames()[item],
-                                       Toast.LENGTH_SHORT).show();
-                        mView.setDebugMode(item);
-                        mView.suspendRendering(false);
-                    }
-                });
-                debugBuilder.show();
-                return true;
-            default:
-                return super.onOptionsItemSelected(item);
-        }
-    }
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchBaseTest.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchBaseTest.java
deleted file mode 100644
index a9e1777..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchBaseTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.perftest;
-import android.renderscript.*;
-import android.content.res.Resources;
-
-interface RsBenchBaseTest {
-    boolean init(RenderScriptGL rs, Resources res);
-
-    ScriptField_TestScripts_s.Item[] getTests();
-    String[] getTestNames();
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
deleted file mode 100644
index 4ac7dd5..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * Copyright (C) 2010-2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.perftest;
-
-import java.io.Writer;
-import java.io.BufferedWriter;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStream;
-
-import android.os.Environment;
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.renderscript.Element.DataKind;
-import android.renderscript.Element.DataType;
-import android.renderscript.Allocation.MipmapControl;
-import android.renderscript.Program.TextureType;
-import android.renderscript.RenderScript.RSMessageHandler;
-import android.renderscript.Sampler.Value;
-import android.renderscript.Mesh.Primitive;
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramVertexFixedFunction;
-
-import android.util.Log;
-
-
-public class RsBenchRS {
-
-    private static final String TAG = "RsBenchRS";
-    int mWidth;
-    int mHeight;
-    int mLoops;
-    int mCurrentLoop;
-
-    int mBenchmarkDimX;
-    int mBenchmarkDimY;
-
-    public RsBenchRS() {
-    }
-
-    public void init(RenderScriptGL rs, Resources res, int width, int height, int loops) {
-        mRS = rs;
-        mRes = res;
-        mWidth = width;
-        mHeight = height;
-        mMode = 0;
-        mLoops = loops;
-        mCurrentLoop = 0;
-        mBenchmarkDimX = 1280;
-        mBenchmarkDimY = 720;
-        initRS();
-    }
-
-    private boolean stopTest = false;
-
-    private Resources mRes;
-    private RenderScriptGL mRS;
-
-    private ProgramStore mProgStoreBlendNone;
-    private ProgramStore mProgStoreBlendAlpha;
-
-    private ProgramFragment mProgFragmentTexture;
-    private ProgramFragment mProgFragmentColor;
-
-    private ProgramVertex mProgVertex;
-    private ProgramVertexFixedFunction.Constants mPVA;
-    private ProgramVertexFixedFunction.Constants mPvProjectionAlloc;
-
-    private ScriptC_rsbench mScript;
-
-    ScriptField_TestScripts_s.Item[] mIndividualTests;
-
-    int mMode;
-
-    String[] mTestNames;
-    float[] mLocalTestResults;
-
-    static Allocation createZeroTerminatedAlloc(RenderScript rs,
-                                                String str,
-                                                int usage) {
-        byte[] allocArray = null;
-        try {
-            allocArray = str.getBytes("UTF-8");
-            byte[] allocArrayZero = new byte[allocArray.length + 1];
-            System.arraycopy(allocArray, 0, allocArrayZero, 0, allocArray.length);
-            allocArrayZero[allocArrayZero.length - 1] = '\0';
-            Allocation alloc = Allocation.createSized(rs, Element.U8(rs),
-                                                      allocArrayZero.length, usage);
-            alloc.copyFrom(allocArrayZero);
-            return alloc;
-        }
-        catch (Exception e) {
-            throw new RSRuntimeException("Could not convert string to utf-8.");
-        }
-
-    }
-
-    void appendTests(RsBenchBaseTest testSet) {
-        ScriptField_TestScripts_s.Item[] newTests = testSet.getTests();
-        if (mIndividualTests != null) {
-            ScriptField_TestScripts_s.Item[] combined;
-            combined = new ScriptField_TestScripts_s.Item[newTests.length + mIndividualTests.length];
-            System.arraycopy(mIndividualTests, 0, combined, 0, mIndividualTests.length);
-            System.arraycopy(newTests, 0, combined, mIndividualTests.length, newTests.length);
-            mIndividualTests = combined;
-        } else {
-            mIndividualTests = newTests;
-        }
-
-        String[] newNames = testSet.getTestNames();
-        if (mTestNames != null) {
-            String[] combinedNames;
-            combinedNames = new String[newNames.length + mTestNames.length];
-            System.arraycopy(mTestNames, 0, combinedNames, 0, mTestNames.length);
-            System.arraycopy(newNames, 0, combinedNames, mTestNames.length, newNames.length);
-            mTestNames = combinedNames;
-        } else {
-            mTestNames = newNames;
-        }
-    }
-
-    void createTestAllocation() {
-        int numTests = mIndividualTests.length;
-        mLocalTestResults = new float[numTests];
-        ScriptField_TestScripts_s allTests;
-        allTests = new ScriptField_TestScripts_s(mRS, numTests);
-        for (int i = 0; i < numTests; i ++) {
-            allTests.set(mIndividualTests[i], i, false);
-        }
-        allTests.copyAll();
-        mScript.bind_gTestScripts(allTests);
-    }
-
-    private void saveTestResults() {
-        String state = Environment.getExternalStorageState();
-        if (!Environment.MEDIA_MOUNTED.equals(state)) {
-            Log.v(TAG, "sdcard is read only");
-            return;
-        }
-        File sdCard = Environment.getExternalStorageDirectory();
-        if (!sdCard.canWrite()) {
-            Log.v(TAG, "ssdcard is read only");
-            return;
-        }
-
-        File resultFile = new File(sdCard, "rsbench_result" + mCurrentLoop + ".csv");
-        resultFile.setWritable(true, false);
-
-        try {
-            BufferedWriter results = new BufferedWriter(new FileWriter(resultFile));
-            for (int i = 0; i < mLocalTestResults.length; i ++) {
-                results.write(mTestNames[i] + ", " + mLocalTestResults[i] + ",\n");
-            }
-            results.close();
-            Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
-        } catch (IOException e) {
-            Log.v(TAG, "Unable to write result file " + e.getMessage());
-        }
-    }
-
-    /**
-     * Create a message handler to handle message sent from the script
-     */
-    protected RSMessageHandler mRsMessage = new RSMessageHandler() {
-        public void run() {
-            if (mID == mScript.get_RS_MSG_RESULTS_READY()) {
-                for (int i = 0; i < mLocalTestResults.length; i ++) {
-                    mLocalTestResults[i] = Float.intBitsToFloat(mData[i]);
-                }
-                saveTestResults();
-                if (mLoops > 0) {
-                    mCurrentLoop ++;
-                    mCurrentLoop = mCurrentLoop % mLoops;
-                }
-                return;
-
-            } else if (mID == mScript.get_RS_MSG_TEST_DONE()) {
-                synchronized(this) {
-                    stopTest = true;
-                    this.notifyAll();
-                }
-                return;
-            } else {
-                Log.v(TAG, "Perf test got unexpected message");
-                return;
-            }
-        }
-    };
-
-    /**
-     * Wait for message from the script
-     */
-    public boolean testIsFinished() {
-        synchronized(this) {
-            while (true) {
-                if (stopTest) {
-                    return true;
-                } else {
-                    try {
-                        this.wait(60*1000);
-                    } catch (InterruptedException e) {
-                        e.printStackTrace();
-                    }
-                }
-            }
-        }
-    }
-
-    private void initProgramFragment() {
-
-        ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
-        texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
-                              ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
-        mProgFragmentTexture = texBuilder.create();
-        mProgFragmentTexture.bindSampler(Sampler.CLAMP_LINEAR(mRS), 0);
-
-        ProgramFragmentFixedFunction.Builder colBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
-        colBuilder.setVaryingColor(false);
-        mProgFragmentColor = colBuilder.create();
-
-        mScript.set_gProgFragmentTexture(mProgFragmentTexture);
-    }
-
-    private void initProgramVertex() {
-        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
-        mProgVertex = pvb.create();
-
-        mPVA = new ProgramVertexFixedFunction.Constants(mRS);
-        ((ProgramVertexFixedFunction)mProgVertex).bindConstants(mPVA);
-        Matrix4f proj = new Matrix4f();
-        proj.loadOrthoWindow(mBenchmarkDimX, mBenchmarkDimY);
-        mPVA.setProjection(proj);
-
-        mScript.set_gProgVertex(mProgVertex);
-    }
-
-    private int strlen(byte[] array) {
-        int count = 0;
-        while(count < array.length && array[count] != 0) {
-            count ++;
-        }
-        return count;
-    }
-
-    public void setDebugMode(int num) {
-        mScript.invoke_setDebugMode(num);
-    }
-
-    public void setBenchmarkMode(int benchNum) {
-        mScript.invoke_setBenchmarkMode(benchNum);
-    }
-
-    public void pause(boolean pause) {
-        mScript.set_gPauseRendering(pause);
-    }
-
-    private void initRS() {
-
-        mScript = new ScriptC_rsbench(mRS, mRes, R.raw.rsbench);
-        mRS.bindRootScript(mScript);
-
-        mRS.setMessageHandler(mRsMessage);
-
-        mScript.set_gMaxLoops(mLoops);
-
-        initProgramVertex();
-        initProgramFragment();
-        mScript.set_gFontSerif(Font.create(mRS, mRes, "serif", Font.Style.NORMAL, 8));
-
-        Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS));
-        b.setX(mBenchmarkDimX).setY(mBenchmarkDimY);
-        Allocation offscreen = Allocation.createTyped(mRS,
-                                                      b.create(),
-                                                      Allocation.USAGE_GRAPHICS_TEXTURE |
-                                                      Allocation.USAGE_GRAPHICS_RENDER_TARGET);
-        mScript.set_gRenderBufferColor(offscreen);
-
-        b = new Type.Builder(mRS,
-                             Element.createPixel(mRS, DataType.UNSIGNED_16,
-                             DataKind.PIXEL_DEPTH));
-        b.setX(mBenchmarkDimX).setY(mBenchmarkDimY);
-        offscreen = Allocation.createTyped(mRS,
-                                           b.create(),
-                                           Allocation.USAGE_GRAPHICS_RENDER_TARGET);
-        mScript.set_gRenderBufferDepth(offscreen);
-        mScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS));
-
-        RsBenchBaseTest test = new TextTest();
-        if (test.init(mRS, mRes)) {
-            appendTests(test);
-        }
-        test = new FillTest();
-        if (test.init(mRS, mRes)) {
-            appendTests(test);
-        }
-        test = new MeshTest();
-        if (test.init(mRS, mRes)) {
-            appendTests(test);
-        }
-        test = new TorusTest();
-        if (test.init(mRS, mRes)) {
-            appendTests(test);
-        }
-        test = new UiTest();
-        if (test.init(mRS, mRes)) {
-            appendTests(test);
-        }
-        createTestAllocation();
-
-        mScript.set_gLoadComplete(true);
-    }
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchTest.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchTest.java
deleted file mode 100644
index 199200b..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.perftest;
-
-import android.app.Instrumentation;
-import android.content.Context;
-import android.content.Intent;
-import android.net.Uri;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.TouchUtils;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.util.Log;
-
-/**
- * To run the test, please use command
- *
- * adb shell am instrument -w com.android.perftest/.RsPerfTestRunner
- *
- */
-public class RsBenchTest extends ActivityInstrumentationTestCase2<RsBench> {
-    private String TAG = "RsBenchTest";
-    private int iterations = 0;
-    private RsBench mAct;
-
-    public RsBenchTest() {
-        super(RsBench.class);
-    }
-
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-        Instrumentation mInst = getInstrumentation();
-        RsPerfTestRunner mRunner = (RsPerfTestRunner) getInstrumentation();
-        iterations = mRunner.iterations;
-        Log.v(TAG, "Run benchmark for " + iterations + " iterations.");
-
-        Uri data = Uri.fromParts("iterations", Integer.toString(iterations), null);
-        Intent intent = new Intent(Intent.ACTION_MAIN);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        intent.setClassName("com.android.perftest", "com.android.perftest.RsBench");
-        intent.setData(data);
-        mAct = (RsBench) mInst.startActivitySync(intent);
-        mInst.waitForIdleSync();
-
-    }
-
-    @Override
-    public void tearDown() throws Exception {
-        mAct.finish();
-        super.tearDown();
-    }
-
-    /**
-     * Run tests and wait until the test has been run for iterations.
-     */
-    @LargeTest
-    public void testRsBench() {
-        if (mAct.mView.testIsFinished()) {
-            return;
-        } else {
-            fail("test didn't stop correctly");
-        }
-    }
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchView.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchView.java
deleted file mode 100644
index 124071e..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchView.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.perftest;
-
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-import android.renderscript.RenderScriptGL;
-import android.renderscript.RenderScript.RSMessageHandler;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.Handler;
-import android.os.Message;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-
-public class RsBenchView extends RSSurfaceView {
-
-    public RsBenchView(Context context) {
-        super(context);
-    }
-
-    private RenderScriptGL mRS;
-    private RsBenchRS mRender;
-    private int mLoops = 0;
-
-    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
-        super.surfaceChanged(holder, format, w, h);
-        if (mRS == null) {
-            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            sc.setDepth(16, 24);
-            mRS = createRenderScriptGL(sc);
-            mRS.setSurface(holder, w, h);
-            mRender = new RsBenchRS();
-            Log.v("RsBenchView", "mLoops = " + mLoops);
-            mRender.init(mRS, getResources(), w, h, mLoops);
-        }
-    }
-
-    @Override
-    protected void onDetachedFromWindow() {
-        if (mRS != null) {
-            mRS = null;
-            destroyRenderScriptGL();
-        }
-    }
-
-    /**
-     * Set the total number of loops the benchmark tests will run
-     * before the test results are collected.
-     */
-    public void setLoops(int iterations) {
-        if (iterations > 0) {
-            mLoops = iterations;
-        }
-    }
-
-    /**
-     * Wait for message from the script
-     */
-    public boolean testIsFinished() {
-        return mRender.testIsFinished();
-    }
-
-    void setBenchmarkMode(int benchNum) {
-        mRender.setBenchmarkMode(benchNum);
-    }
-
-    void suspendRendering(boolean pause) {
-        mRender.pause(pause);
-    }
-
-    void setDebugMode(int num) {
-        mRender.setDebugMode(num);
-    }
-
-    String[] getTestNames() {
-        return mRender.mTestNames;
-    }
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsPerfTestRunner.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsPerfTestRunner.java
deleted file mode 100644
index 031af6a..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsPerfTestRunner.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.perftest;
-
-//import com.android.perftest.RsBenchTest;
-
-import android.os.Bundle;
-import android.test.InstrumentationTestRunner;
-import android.test.InstrumentationTestSuite;
-
-import junit.framework.TestSuite;
-
-/**
- * Run the RenderScript Performance Test
- * adb shell am instrument -w com.android.perftest/.RsPerfTestRunner
- *
- * with specified iterations:
- * adb shell am instrument -e iterations <n> -w com.android.perftest/.RsPerfTestRunner
- *
- */
-public class RsPerfTestRunner extends InstrumentationTestRunner {
-    public int iterations = 10;
-
-    @Override
-    public TestSuite getAllTests() {
-        TestSuite suite = new InstrumentationTestSuite(this);
-        suite.addTestSuite(RsBenchTest.class);
-        return suite;
-    }
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-        String strValue = (String)icicle.get("iterations");
-        if (strValue != null) {
-            int intValue = Integer.parseInt(strValue);
-            if (iterations > 0) {
-                iterations = intValue;
-            }
-        }
-    }
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/TextTest.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/TextTest.java
deleted file mode 100644
index 3ca2792..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/TextTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.perftest;
-
-import android.os.Environment;
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.util.DisplayMetrics;
-
-import android.util.Log;
-
-
-public class TextTest implements RsBenchBaseTest{
-
-    private static final String TAG = "TextTest";
-    private RenderScriptGL mRS;
-    private Resources mRes;
-
-    private ScriptC_text_test mTextScript;
-    ScriptField_TestScripts_s.Item[] mTests;
-
-    private final String[] mNames = {
-        "Fill screen with text 1 time",
-        "Fill screen with text 3 times",
-        "Fill screen with text 5 times"
-    };
-
-    public TextTest() {
-    }
-
-    void addTest(int index, int fillNum) {
-        mTests[index] = new ScriptField_TestScripts_s.Item();
-        mTests[index].testScript = mTextScript;
-        mTests[index].testName = Allocation.createFromString(mRS,
-                                                             mNames[index],
-                                                             Allocation.USAGE_SCRIPT);
-        mTests[index].debugName = RsBenchRS.createZeroTerminatedAlloc(mRS,
-                                                                     mNames[index],
-                                                                     Allocation.USAGE_SCRIPT);
-
-        ScriptField_TextTestData_s.Item dataItem = new ScriptField_TextTestData_s.Item();
-        dataItem.fillNum = fillNum;
-        ScriptField_TextTestData_s testData = new ScriptField_TextTestData_s(mRS, 1);
-        testData.set(dataItem, 0, true);
-        mTests[index].testData = testData.getAllocation();
-    }
-
-    public boolean init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-        initTextScript();
-        mTests = new ScriptField_TestScripts_s.Item[mNames.length];
-
-        int index = 0;
-        addTest(index++, 1 /*fillNum*/);
-        addTest(index++, 3 /*fillNum*/);
-        addTest(index++, 5 /*fillNum*/);
-
-        return true;
-    }
-
-    public ScriptField_TestScripts_s.Item[] getTests() {
-        return mTests;
-    }
-
-    public String[] getTestNames() {
-        return mNames;
-    }
-
-    void initTextScript() {
-        DisplayMetrics metrics = mRes.getDisplayMetrics();
-
-        mTextScript = new ScriptC_text_test(mRS, mRes, R.raw.text_test);
-        mTextScript.set_gFontSans(Font.create(mRS, mRes, "sans-serif",
-                                              Font.Style.NORMAL, 8.0f / metrics.density));
-        mTextScript.set_gFontSerif(Font.create(mRS, mRes, "serif",
-                                               Font.Style.NORMAL, 8.0f / metrics.density));
-    }
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/TorusTest.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/TorusTest.java
deleted file mode 100644
index 5c9ecd5..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/TorusTest.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.perftest;
-
-import android.os.Environment;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.renderscript.*;
-import android.renderscript.Element.DataKind;
-import android.renderscript.Element.DataType;
-import android.renderscript.Allocation.MipmapControl;
-import android.renderscript.Program.TextureType;
-import android.renderscript.RenderScript.RSMessageHandler;
-import android.renderscript.Mesh.Primitive;
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramVertexFixedFunction;
-
-import android.util.Log;
-
-
-public class TorusTest implements RsBenchBaseTest{
-
-    private static final String TAG = "TorusTest";
-    private RenderScriptGL mRS;
-    private Resources mRes;
-
-    private ProgramStore mProgStoreBlendNoneDepth;
-    private ProgramStore mProgStoreBlendNone;
-    private ProgramStore mProgStoreBlendAlpha;
-
-    private ProgramFragment mProgFragmentTexture;
-    private ProgramFragment mProgFragmentColor;
-
-    private ProgramVertex mProgVertex;
-    private ProgramVertexFixedFunction.Constants mPVA;
-    private ProgramVertexFixedFunction.Constants mPvProjectionAlloc;
-
-    // Custom shaders
-    private ProgramVertex mProgVertexCustom;
-    private ProgramFragment mProgFragmentCustom;
-    private ProgramFragment mProgFragmentMultitex;
-    private ProgramVertex mProgVertexPixelLight;
-    private ProgramVertex mProgVertexPixelLightMove;
-    private ProgramFragment mProgFragmentPixelLight;
-    private ScriptField_VertexShaderConstants_s mVSConst;
-    private ScriptField_FragentShaderConstants_s mFSConst;
-    private ScriptField_VertexShaderConstants3_s mVSConstPixel;
-    private ScriptField_FragentShaderConstants3_s mFSConstPixel;
-
-    private Allocation mTexTorus;
-    private Mesh mTorus;
-
-    private ScriptC_torus_test mTorusScript;
-
-    private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
-
-    ScriptField_TestScripts_s.Item[] mTests;
-
-    private final String[] mNames = {
-        "Geo test 25.6k flat color",
-        "Geo test 51.2k flat color",
-        "Geo test 204.8k small tries flat color",
-        "Geo test 25.6k single texture",
-        "Geo test 51.2k single texture",
-        "Geo test 204.8k small tries single texture",
-        "Geo test 25.6k geo heavy vertex",
-        "Geo test 51.2k geo heavy vertex",
-        "Geo test 204.8k geo raster load heavy vertex",
-        "Geo test 25.6k heavy fragment",
-        "Geo test 51.2k heavy fragment",
-        "Geo test 204.8k small tries heavy fragment",
-        "Geo test 25.6k heavy fragment heavy vertex",
-        "Geo test 51.2k heavy fragment heavy vertex",
-        "Geo test 204.8k small tries heavy fragment heavy vertex"
-    };
-
-    public TorusTest() {
-    }
-
-    void addTest(int index, int testId, int user1, int user2) {
-        mTests[index] = new ScriptField_TestScripts_s.Item();
-        mTests[index].testScript = mTorusScript;
-        mTests[index].testName = Allocation.createFromString(mRS,
-                                                             mNames[index],
-                                                             Allocation.USAGE_SCRIPT);
-        mTests[index].debugName = RsBenchRS.createZeroTerminatedAlloc(mRS,
-                                                                      mNames[index],
-                                                                      Allocation.USAGE_SCRIPT);
-
-        ScriptField_TorusTestData_s.Item dataItem = new ScriptField_TorusTestData_s.Item();
-        dataItem.testId = testId;
-        dataItem.user1 = user1;
-        dataItem.user2 = user2;
-        ScriptField_TorusTestData_s testData = new ScriptField_TorusTestData_s(mRS, 1);
-        testData.set(dataItem, 0, true);
-        mTests[index].testData = testData.getAllocation();
-    }
-
-    public boolean init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-        initCustomShaders();
-        loadImages();
-        initMesh();
-        initTorusScript();
-        mTests = new ScriptField_TestScripts_s.Item[mNames.length];
-
-        int index = 0;
-        addTest(index++, 0, 0 /*useTexture*/, 1 /*numMeshes*/);
-        addTest(index++, 0, 0 /*useTexture*/, 2 /*numMeshes*/);
-        addTest(index++, 0, 0 /*useTexture*/, 8 /*numMeshes*/);
-        addTest(index++, 0, 1 /*useTexture*/, 1 /*numMeshes*/);
-        addTest(index++, 0, 1 /*useTexture*/, 2 /*numMeshes*/);
-        addTest(index++, 0, 1 /*useTexture*/, 8 /*numMeshes*/);
-
-        // Secont test
-        addTest(index++, 1, 1 /*numMeshes*/, 0 /*unused*/);
-        addTest(index++, 1, 2 /*numMeshes*/, 0 /*unused*/);
-        addTest(index++, 1, 8 /*numMeshes*/, 0 /*unused*/);
-
-        // Third test
-        addTest(index++, 2, 1 /*numMeshes*/, 0 /*heavyVertex*/);
-        addTest(index++, 2, 2 /*numMeshes*/, 0 /*heavyVertex*/);
-        addTest(index++, 2, 8 /*numMeshes*/, 0 /*heavyVertex*/);
-        addTest(index++, 2, 1 /*numMeshes*/, 1 /*heavyVertex*/);
-        addTest(index++, 2, 2 /*numMeshes*/, 1 /*heavyVertex*/);
-        addTest(index++, 2, 8 /*numMeshes*/, 1 /*heavyVertex*/);
-
-        return true;
-    }
-
-    public ScriptField_TestScripts_s.Item[] getTests() {
-        return mTests;
-    }
-
-    public String[] getTestNames() {
-        return mNames;
-    }
-
-    private void initCustomShaders() {
-        mVSConst = new ScriptField_VertexShaderConstants_s(mRS, 1);
-        mFSConst = new ScriptField_FragentShaderConstants_s(mRS, 1);
-
-        mVSConstPixel = new ScriptField_VertexShaderConstants3_s(mRS, 1);
-        mFSConstPixel = new ScriptField_FragentShaderConstants3_s(mRS, 1);
-
-        // Initialize the shader builder
-        ProgramVertex.Builder pvbCustom = new ProgramVertex.Builder(mRS);
-        // Specify the resource that contains the shader string
-        pvbCustom.setShader(mRes, R.raw.shaderv);
-        // Use a script field to specify the input layout
-        pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
-        // Define the constant input layout
-        pvbCustom.addConstant(mVSConst.getAllocation().getType());
-        mProgVertexCustom = pvbCustom.create();
-        // Bind the source of constant data
-        mProgVertexCustom.bindConstants(mVSConst.getAllocation(), 0);
-
-        ProgramFragment.Builder pfbCustom = new ProgramFragment.Builder(mRS);
-        // Specify the resource that contains the shader string
-        pfbCustom.setShader(mRes, R.raw.shaderf);
-        // Tell the builder how many textures we have
-        pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
-        // Define the constant input layout
-        pfbCustom.addConstant(mFSConst.getAllocation().getType());
-        mProgFragmentCustom = pfbCustom.create();
-        // Bind the source of constant data
-        mProgFragmentCustom.bindConstants(mFSConst.getAllocation(), 0);
-
-        pvbCustom = new ProgramVertex.Builder(mRS);
-        pvbCustom.setShader(mRes, R.raw.shader2v);
-        pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
-        pvbCustom.addConstant(mVSConstPixel.getAllocation().getType());
-        mProgVertexPixelLight = pvbCustom.create();
-        mProgVertexPixelLight.bindConstants(mVSConstPixel.getAllocation(), 0);
-
-        pvbCustom = new ProgramVertex.Builder(mRS);
-        pvbCustom.setShader(mRes, R.raw.shader2movev);
-        pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
-        pvbCustom.addConstant(mVSConstPixel.getAllocation().getType());
-        mProgVertexPixelLightMove = pvbCustom.create();
-        mProgVertexPixelLightMove.bindConstants(mVSConstPixel.getAllocation(), 0);
-
-        pfbCustom = new ProgramFragment.Builder(mRS);
-        pfbCustom.setShader(mRes, R.raw.shader2f);
-        pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
-        pfbCustom.addConstant(mFSConstPixel.getAllocation().getType());
-        mProgFragmentPixelLight = pfbCustom.create();
-        mProgFragmentPixelLight.bindConstants(mFSConstPixel.getAllocation(), 0);
-
-        pfbCustom = new ProgramFragment.Builder(mRS);
-        pfbCustom.setShader(mRes, R.raw.multitexf);
-        for (int texCount = 0; texCount < 3; texCount ++) {
-            pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
-        }
-        mProgFragmentMultitex = pfbCustom.create();
-
-        ProgramFragmentFixedFunction.Builder colBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
-        colBuilder.setVaryingColor(false);
-        mProgFragmentColor = colBuilder.create();
-
-        ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
-        texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
-                              ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
-        mProgFragmentTexture = texBuilder.create();
-
-        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
-        mProgVertex = pvb.create();
-        ProgramVertexFixedFunction.Constants PVA = new ProgramVertexFixedFunction.Constants(mRS);
-        ((ProgramVertexFixedFunction)mProgVertex).bindConstants(PVA);
-        Matrix4f proj = new Matrix4f();
-        proj.loadOrthoWindow(1280, 720);
-        PVA.setProjection(proj);
-    }
-
-    private Allocation loadTextureRGB(int id) {
-        return Allocation.createFromBitmapResource(mRS, mRes, id,
-                Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                Allocation.USAGE_GRAPHICS_TEXTURE);
-    }
-
-    private void loadImages() {
-        mTexTorus = loadTextureRGB(R.drawable.torusmap);
-    }
-
-    private void initMesh() {
-        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.torus);
-        FileA3D.IndexEntry entry = model.getIndexEntry(0);
-        if (entry == null || entry.getEntryType() != FileA3D.EntryType.MESH) {
-            Log.e("rs", "could not load model");
-        } else {
-            mTorus = (Mesh)entry.getObject();
-        }
-    }
-
-    void initTorusScript() {
-        mTorusScript = new ScriptC_torus_test(mRS, mRes, R.raw.torus_test);
-        mTorusScript.set_gCullFront(ProgramRaster.CULL_FRONT(mRS));
-        mTorusScript.set_gCullBack(ProgramRaster.CULL_BACK(mRS));
-        mTorusScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS));
-        mTorusScript.set_gTorusMesh(mTorus);
-        mTorusScript.set_gTexTorus(mTexTorus);
-        mTorusScript.set_gProgVertexCustom(mProgVertexCustom);
-        mTorusScript.set_gProgFragmentCustom(mProgFragmentCustom);
-        mTorusScript.set_gProgVertexPixelLight(mProgVertexPixelLight);
-        mTorusScript.set_gProgVertexPixelLightMove(mProgVertexPixelLightMove);
-        mTorusScript.set_gProgFragmentPixelLight(mProgFragmentPixelLight);
-        mTorusScript.bind_gVSConstPixel(mVSConstPixel);
-        mTorusScript.bind_gFSConstPixel(mFSConstPixel);
-        mTorusScript.bind_gVSConstants(mVSConst);
-        mTorusScript.bind_gFSConstants(mFSConst);
-        mTorusScript.set_gProgVertex(mProgVertex);
-        mTorusScript.set_gProgFragmentTexture(mProgFragmentTexture);
-        mTorusScript.set_gProgFragmentColor(mProgFragmentColor);
-        mTorusScript.set_gProgStoreBlendNoneDepth(mProgStoreBlendNoneDepth);
-    }
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/UiTest.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/UiTest.java
deleted file mode 100644
index c8b58b2..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/UiTest.java
+++ /dev/null
@@ -1,337 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.perftest;
-
-import android.os.Environment;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.renderscript.*;
-import android.renderscript.Element.DataKind;
-import android.renderscript.Element.DataType;
-import android.renderscript.Allocation.MipmapControl;
-import android.renderscript.Program.TextureType;
-import android.renderscript.ProgramStore.DepthFunc;
-import android.renderscript.ProgramStore.BlendSrcFunc;
-import android.renderscript.ProgramStore.BlendDstFunc;
-import android.renderscript.RenderScript.RSMessageHandler;
-import android.renderscript.Mesh.Primitive;
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramVertexFixedFunction;
-
-import android.util.Log;
-
-
-public class UiTest implements RsBenchBaseTest{
-
-    private static final String TAG = "UiTest";
-    private static final String SAMPLE_TEXT = "Bench Test";
-    private static final String LIST_TEXT =
-      "This is a sample list of text to show in the list view";
-    private static int PARTICLES_COUNT = 12000;
-
-    private RenderScriptGL mRS;
-    private Resources mRes;
-
-    Font mFontSans;
-
-    private ScriptField_ListAllocs_s mTextureAllocs;
-    private ScriptField_ListAllocs_s mSampleTextAllocs;
-    private ScriptField_ListAllocs_s mSampleListViewAllocs;
-    private ScriptField_VpConsts mPvStarAlloc;
-    private ProgramVertexFixedFunction.Constants mPvProjectionAlloc;
-
-    private Mesh mSingleMesh;
-    private Mesh mParticlesMesh;
-
-    private ScriptC_ui_test mUiScript;
-
-    private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
-
-    ScriptField_TestScripts_s.Item[] mTests;
-
-    private final String[] mNames = {
-        "UI test with icon display 10 by 10",
-        "UI test with icon display 100 by 100",
-        "UI test with image and text display 3 pages",
-        "UI test with image and text display 5 pages",
-        "UI test with list view",
-        "UI test with live wallpaper"
-    };
-
-    public UiTest() {
-    }
-
-    void addTest(int index, int testId, int user1, int user2, int user3) {
-        mTests[index] = new ScriptField_TestScripts_s.Item();
-        mTests[index].testScript = mUiScript;
-        mTests[index].testName = Allocation.createFromString(mRS,
-                                                             mNames[index],
-                                                             Allocation.USAGE_SCRIPT);
-        mTests[index].debugName = RsBenchRS.createZeroTerminatedAlloc(mRS,
-                                                                      mNames[index],
-                                                                      Allocation.USAGE_SCRIPT);
-
-        ScriptField_UiTestData_s.Item dataItem = new ScriptField_UiTestData_s.Item();
-        dataItem.testId = testId;
-        dataItem.user1 = user1;
-        dataItem.user2 = user2;
-        dataItem.user3 = user3;
-        ScriptField_UiTestData_s testData = new ScriptField_UiTestData_s(mRS, 1);
-        testData.set(dataItem, 0, true);
-        mTests[index].testData = testData.getAllocation();
-    }
-
-    public boolean init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-        mFontSans = Font.create(mRS, mRes, "sans-serif", Font.Style.NORMAL, 8);
-        mSingleMesh = getSingleMesh(1, 1);  // a unit size mesh
-
-        initUiScript();
-        mTests = new ScriptField_TestScripts_s.Item[mNames.length];
-
-        int index = 0;
-
-        addTest(index++, 0, 0 /*meshMode*/, 0 /*unused*/, 0 /*unused*/);
-        addTest(index++, 0, 1 /*meshMode*/, 0 /*unused*/, 0 /*unused*/);
-        addTest(index++, 1, 7 /*wResolution*/, 5 /*hResolution*/, 0 /*meshMode*/);
-        addTest(index++, 1, 7 /*wResolution*/, 5 /*hResolution*/, 1 /*meshMode*/);
-        addTest(index++, 2, 0 /*unused*/, 0 /*unused*/, 0 /*unused*/);
-        addTest(index++, 3, 7 /*wResolution*/, 5 /*hResolution*/, 0 /*unused*/);
-
-        return true;
-    }
-
-    public ScriptField_TestScripts_s.Item[] getTests() {
-        return mTests;
-    }
-
-    public String[] getTestNames() {
-        return mNames;
-    }
-
-    private Allocation loadTextureRGB(int id) {
-        return Allocation.createFromBitmapResource(mRS, mRes, id,
-                Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                Allocation.USAGE_GRAPHICS_TEXTURE);
-    }
-
-    private Allocation loadTextureARGB(int id) {
-        Bitmap b = BitmapFactory.decodeResource(mRes, id, mOptionsARGB);
-        return Allocation.createFromBitmap(mRS, b,
-                Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                Allocation.USAGE_GRAPHICS_TEXTURE);
-    }
-
-    private void createParticlesMesh() {
-        ScriptField_Particle p = new ScriptField_Particle(mRS, PARTICLES_COUNT);
-
-        final Mesh.AllocationBuilder meshBuilder = new Mesh.AllocationBuilder(mRS);
-        meshBuilder.addVertexAllocation(p.getAllocation());
-        final int vertexSlot = meshBuilder.getCurrentVertexTypeIndex();
-        meshBuilder.addIndexSetType(Primitive.POINT);
-        mParticlesMesh = meshBuilder.create();
-
-        mUiScript.set_gParticlesMesh(mParticlesMesh);
-        mUiScript.bind_Particles(p);
-    }
-
-    /**
-     * Create a mesh with a single quad for the given width and height.
-     */
-    private Mesh getSingleMesh(float width, float height) {
-        Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS,
-                                           2, Mesh.TriangleMeshBuilder.TEXTURE_0);
-        float xOffset = width/2;
-        float yOffset = height/2;
-        tmb.setTexture(0, 0);
-        tmb.addVertex(-1.0f * xOffset, -1.0f * yOffset);
-        tmb.setTexture(1, 0);
-        tmb.addVertex(xOffset, -1.0f * yOffset);
-        tmb.setTexture(1, 1);
-        tmb.addVertex(xOffset, yOffset);
-        tmb.setTexture(0, 1);
-        tmb.addVertex(-1.0f * xOffset, yOffset);
-        tmb.addTriangle(0, 3, 1);
-        tmb.addTriangle(1, 3, 2);
-        return tmb.create(true);
-    }
-
-    private Matrix4f getProjectionNormalized(int w, int h) {
-        // range -1,1 in the narrow axis at z = 0.
-        Matrix4f m1 = new Matrix4f();
-        Matrix4f m2 = new Matrix4f();
-
-        if(w > h) {
-            float aspect = ((float)w) / h;
-            m1.loadFrustum(-aspect,aspect,  -1,1,  1,100);
-        } else {
-            float aspect = ((float)h) / w;
-            m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
-        }
-
-        m2.loadRotate(180, 0, 1, 0);
-        m1.loadMultiply(m1, m2);
-
-        m2.loadScale(-2, 2, 1);
-        m1.loadMultiply(m1, m2);
-
-        m2.loadTranslate(0, 0, 2);
-        m1.loadMultiply(m1, m2);
-        return m1;
-    }
-
-    private void updateProjectionMatrices() {
-        Matrix4f projNorm = getProjectionNormalized(1280, 720);
-        ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
-        i.Proj = projNorm;
-        i.MVP = projNorm;
-        mPvStarAlloc.set(i, 0, true);
-        mPvProjectionAlloc.setProjection(projNorm);
-    }
-
-    void initUiScript() {
-        mUiScript = new ScriptC_ui_test(mRS, mRes, R.raw.ui_test);
-
-        ProgramFragmentFixedFunction.Builder colBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
-        colBuilder.setVaryingColor(false);
-        ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
-        texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
-                              ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
-
-        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
-        ProgramVertexFixedFunction progVertex = pvb.create();
-        ProgramVertexFixedFunction.Constants PVA = new ProgramVertexFixedFunction.Constants(mRS);
-        ((ProgramVertexFixedFunction)progVertex).bindConstants(PVA);
-        Matrix4f proj = new Matrix4f();
-        proj.loadOrthoWindow(1280, 720);
-        PVA.setProjection(proj);
-
-        mUiScript.set_gProgVertex(progVertex);
-        mUiScript.set_gProgFragmentColor(colBuilder.create());
-        mUiScript.set_gProgFragmentTexture(texBuilder.create());
-        mUiScript.set_gProgStoreBlendAlpha(ProgramStore.BLEND_ALPHA_DEPTH_NONE(mRS));
-
-        mUiScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS));
-
-        mUiScript.set_gTexTorus(loadTextureRGB(R.drawable.torusmap));
-        mUiScript.set_gTexOpaque(loadTextureRGB(R.drawable.data));
-        mUiScript.set_gTexGlobe(loadTextureRGB(R.drawable.globe));
-        mUiScript.set_gSingleMesh(mSingleMesh);
-
-        // For GALAXY
-        ProgramStore.Builder psb = new ProgramStore.Builder(mRS);
-        psb.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
-        mRS.bindProgramStore(psb.create());
-
-        psb.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE);
-        mUiScript.set_gPSLights(psb.create());
-
-        // For Galaxy live wallpaper drawing
-        ProgramFragmentFixedFunction.Builder builder = new ProgramFragmentFixedFunction.Builder(mRS);
-        builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
-                           ProgramFragmentFixedFunction.Builder.Format.RGB, 0);
-        ProgramFragment pfb = builder.create();
-        pfb.bindSampler(Sampler.WRAP_NEAREST(mRS), 0);
-        mUiScript.set_gPFBackground(pfb);
-
-        builder = new ProgramFragmentFixedFunction.Builder(mRS);
-        builder.setPointSpriteTexCoordinateReplacement(true);
-        builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
-                           ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
-        builder.setVaryingColor(true);
-        ProgramFragment pfs = builder.create();
-        pfs.bindSampler(Sampler.WRAP_LINEAR_MIP_LINEAR(mRS), 0);
-        mUiScript.set_gPFStars(pfs);
-
-        mTextureAllocs = new ScriptField_ListAllocs_s(mRS, 100);
-        for (int i = 0; i < 100; i++) {
-            ScriptField_ListAllocs_s.Item texElem = new ScriptField_ListAllocs_s.Item();
-            texElem.item = loadTextureRGB(R.drawable.globe);
-            mTextureAllocs.set(texElem, i, false);
-        }
-        mTextureAllocs.copyAll();
-        mUiScript.bind_gTexList100(mTextureAllocs);
-
-        mSampleTextAllocs = new ScriptField_ListAllocs_s(mRS, 100);
-        for (int i = 0; i < 100; i++) {
-            ScriptField_ListAllocs_s.Item textElem = new ScriptField_ListAllocs_s.Item();
-            textElem.item = Allocation.createFromString(mRS, SAMPLE_TEXT, Allocation.USAGE_SCRIPT);
-            mSampleTextAllocs.set(textElem, i, false);
-        }
-        mSampleTextAllocs.copyAll();
-        mUiScript.bind_gSampleTextList100(mSampleTextAllocs);
-
-        mSampleListViewAllocs = new ScriptField_ListAllocs_s(mRS, 1000);
-        for (int i = 0; i < 1000; i++) {
-            ScriptField_ListAllocs_s.Item textElem = new ScriptField_ListAllocs_s.Item();
-            textElem.item = Allocation.createFromString(mRS, LIST_TEXT, Allocation.USAGE_SCRIPT);
-            mSampleListViewAllocs.set(textElem, i, false);
-        }
-        mSampleListViewAllocs.copyAll();
-        mUiScript.bind_gListViewText(mSampleListViewAllocs);
-
-        // For galaxy live wallpaper
-        mPvStarAlloc = new ScriptField_VpConsts(mRS, 1);
-        mUiScript.bind_vpConstants(mPvStarAlloc);
-        mPvProjectionAlloc = new ProgramVertexFixedFunction.Constants(mRS);
-        updateProjectionMatrices();
-
-        pvb = new ProgramVertexFixedFunction.Builder(mRS);
-        ProgramVertex pvbp = pvb.create();
-        ((ProgramVertexFixedFunction)pvbp).bindConstants(mPvProjectionAlloc);
-        mUiScript.set_gPVBkProj(pvbp);
-
-        createParticlesMesh();
-
-        ProgramVertex.Builder sb = new ProgramVertex.Builder(mRS);
-        String t =  "varying vec4 varColor;\n" +
-                    "varying vec2 varTex0;\n" +
-                    "void main() {\n" +
-                    "  float dist = ATTRIB_position.y;\n" +
-                    "  float angle = ATTRIB_position.x;\n" +
-                    "  float x = dist * sin(angle);\n" +
-                    "  float y = dist * cos(angle) * 0.892;\n" +
-                    "  float p = dist * 5.5;\n" +
-                    "  float s = cos(p);\n" +
-                    "  float t = sin(p);\n" +
-                    "  vec4 pos;\n" +
-                    "  pos.x = t * x + s * y;\n" +
-                    "  pos.y = s * x - t * y;\n" +
-                    "  pos.z = ATTRIB_position.z;\n" +
-                    "  pos.w = 1.0;\n" +
-                    "  gl_Position = UNI_MVP * pos;\n" +
-                    "  gl_PointSize = ATTRIB_color.a * 10.0;\n" +
-                    "  varColor.rgb = ATTRIB_color.rgb;\n" +
-                    "  varColor.a = 1.0;\n" +
-                    "}\n";
-        sb.setShader(t);
-        sb.addInput(mParticlesMesh.getVertexAllocation(0).getType().getElement());
-        sb.addConstant(mPvStarAlloc.getType());
-        ProgramVertex pvs = sb.create();
-        pvs.bindConstants(mPvStarAlloc.getAllocation(), 0);
-        mUiScript.set_gPVStars(pvs);
-
-        // For Galaxy live wallpaper
-        mUiScript.set_gTSpace(loadTextureRGB(R.drawable.space));
-        mUiScript.set_gTLight1(loadTextureRGB(R.drawable.light1));
-        mUiScript.set_gTFlares(loadTextureARGB(R.drawable.flares));
-
-        mUiScript.set_gFontSans(mFontSans);
-    }
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/fill_test.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/fill_test.rs
deleted file mode 100644
index 281f830..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/fill_test.rs
+++ /dev/null
@@ -1,158 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.perftest)
-
-#include "rs_graphics.rsh"
-#include "subtest_def.rsh"
-
-rs_program_vertex gProgVertex;
-rs_program_fragment gProgFragmentTexture;
-rs_program_fragment gProgFragmentTextureModulate;
-rs_program_fragment gProgFragmentMultitex;
-
-rs_program_store gProgStoreBlendNone;
-rs_program_store gProgStoreBlendAlpha;
-
-rs_allocation gTexOpaque;
-rs_allocation gTexTorus;
-rs_allocation gTexTransparent;
-rs_allocation gTexChecker;
-
-rs_sampler gLinearClamp;
-rs_sampler gLinearWrap;
-
-typedef struct FillTestData_s {
-    int testId;
-    int blend;
-    int quadCount;
-} FillTestData;
-FillTestData *gData;
-
-typedef struct FillTestFragData_s {
-    float4 modulate;
-} FillTestFragData;
-FillTestFragData *gFragData;
-
-static float gDt = 0.0f;
-
-void init() {
-}
-
-static int gRenderSurfaceW = 1280;
-static int gRenderSurfaceH = 720;
-
-static void bindProgramVertexOrtho() {
-    // Default vertex shader
-    rsgBindProgramVertex(gProgVertex);
-    // Setup the projection matrix
-    rs_matrix4x4 proj;
-    rsMatrixLoadOrtho(&proj, 0, gRenderSurfaceW, gRenderSurfaceH, 0, -500, 500);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-}
-
-static void displaySingletexFill(bool blend, int quadCount, bool modulate) {
-    bindProgramVertexOrtho();
-    rs_matrix4x4 matrix;
-    rsMatrixLoadIdentity(&matrix);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    // Fragment shader with texture
-    if (!blend) {
-        rsgBindProgramStore(gProgStoreBlendNone);
-    } else {
-        rsgBindProgramStore(gProgStoreBlendAlpha);
-    }
-    if (modulate) {
-        rsgBindProgramFragment(gProgFragmentTextureModulate);
-        rsgBindSampler(gProgFragmentTextureModulate, 0, gLinearClamp);
-        rsgBindTexture(gProgFragmentTextureModulate, 0, gTexOpaque);
-
-        gFragData->modulate.r = 0.8f;
-        gFragData->modulate.g = 0.7f;
-        gFragData->modulate.b = 0.8f;
-        gFragData->modulate.a = 0.5f;
-        rsgAllocationSyncAll(rsGetAllocation(gFragData));
-    } else {
-        rsgBindProgramFragment(gProgFragmentTexture);
-        rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
-        rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);
-    }
-
-    for (int i = 0; i < quadCount; i ++) {
-        float startX = 5 * i, startY = 5 * i;
-        float width = gRenderSurfaceW - startX, height = gRenderSurfaceH - startY;
-        rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
-                             startX, startY + height, 0, 0, 1,
-                             startX + width, startY + height, 0, 1, 1,
-                             startX + width, startY, 0, 1, 0);
-    }
-}
-
-static void displayMultitextureSample(bool blend, int quadCount) {
-    bindProgramVertexOrtho();
-    rs_matrix4x4 matrix;
-    rsMatrixLoadIdentity(&matrix);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    // Fragment shader with texture
-    if (!blend) {
-        rsgBindProgramStore(gProgStoreBlendNone);
-    } else {
-        rsgBindProgramStore(gProgStoreBlendAlpha);
-    }
-    rsgBindProgramFragment(gProgFragmentMultitex);
-    rsgBindSampler(gProgFragmentMultitex, 0, gLinearClamp);
-    rsgBindSampler(gProgFragmentMultitex, 1, gLinearWrap);
-    rsgBindSampler(gProgFragmentMultitex, 2, gLinearClamp);
-    rsgBindTexture(gProgFragmentMultitex, 0, gTexChecker);
-    rsgBindTexture(gProgFragmentMultitex, 1, gTexTorus);
-    rsgBindTexture(gProgFragmentMultitex, 2, gTexTransparent);
-
-    for (int i = 0; i < quadCount; i ++) {
-        float startX = 10 * i, startY = 10 * i;
-        float width = gRenderSurfaceW - startX, height = gRenderSurfaceH - startY;
-        rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
-                             startX, startY + height, 0, 0, 1,
-                             startX + width, startY + height, 0, 1, 1,
-                             startX + width, startY, 0, 1, 0);
-    }
-}
-
-
-void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) {
-    TestData *testData = (TestData*)usrData;
-    gRenderSurfaceW = testData->renderSurfaceW;
-    gRenderSurfaceH = testData->renderSurfaceH;
-    gDt = testData->dt;
-
-    gData = (FillTestData*)v_in;
-
-    switch(gData->testId) {
-        case 0:
-            displayMultitextureSample(gData->blend == 1 ? true : false, gData->quadCount);
-            break;
-        case 1:
-            displaySingletexFill(gData->blend == 1 ? true : false, gData->quadCount, false);
-            break;
-        case 2:
-            displaySingletexFill(gData->blend == 1 ? true : false, gData->quadCount, true);
-            break;
-        default:
-            rsDebug("Wrong test number", 0);
-            break;
-    }
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/mesh_test.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/mesh_test.rs
deleted file mode 100644
index d7e4857..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/mesh_test.rs
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.perftest)
-
-#include "rs_graphics.rsh"
-#include "shader_def.rsh"
-#include "subtest_def.rsh"
-
-rs_program_vertex gProgVertex;
-rs_program_fragment gProgFragmentTexture;
-
-rs_program_store gProgStoreBlendNone;
-
-rs_allocation gTexOpaque;
-
-rs_mesh g10by10Mesh;
-rs_mesh g100by100Mesh;
-rs_mesh gWbyHMesh;
-
-rs_sampler gLinearClamp;
-static int gRenderSurfaceW;
-static int gRenderSurfaceH;
-
-static float gDt = 0;
-
-typedef struct MeshTestData_s {
-    int meshNum;
-} MeshTestData;
-MeshTestData *gData;
-
-void init() {
-}
-
-static void bindProgramVertexOrtho() {
-    // Default vertex shader
-    rsgBindProgramVertex(gProgVertex);
-    // Setup the projection matrix
-    rs_matrix4x4 proj;
-    rsMatrixLoadOrtho(&proj, 0, gRenderSurfaceW, gRenderSurfaceH, 0, -500, 500);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-}
-
-static void displayMeshSamples(int meshNum) {
-
-    bindProgramVertexOrtho();
-    rs_matrix4x4 matrix;
-    rsMatrixLoadTranslate(&matrix, gRenderSurfaceW/2, gRenderSurfaceH/2, 0);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNone);
-    rsgBindProgramFragment(gProgFragmentTexture);
-    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
-
-    rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);
-
-    if (meshNum == 0) {
-        rsgDrawMesh(g10by10Mesh);
-    } else if (meshNum == 1) {
-        rsgDrawMesh(g100by100Mesh);
-    } else if (meshNum == 2) {
-        rsgDrawMesh(gWbyHMesh);
-    }
-}
-
-void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) {
-    TestData *testData = (TestData*)usrData;
-    gRenderSurfaceW = testData->renderSurfaceW;
-    gRenderSurfaceH = testData->renderSurfaceH;
-    gDt = testData->dt;
-
-    gData = (MeshTestData*)v_in;
-
-    displayMeshSamples(gData->meshNum);
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
deleted file mode 100644
index 43cf4e0..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
+++ /dev/null
@@ -1,270 +0,0 @@
-// Copyright (C) 2010-2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.perftest)
-
-#include "rs_graphics.rsh"
-#include "shader_def.rsh"
-#include "subtest_def.rsh"
-
-/* Message sent from script to renderscript */
-const int RS_MSG_TEST_DONE = 100;
-const int RS_MSG_RESULTS_READY = 101;
-
-static const int gMaxModes = 64;
-int gMaxLoops = 1;
-int gDisplayMode = 1;
-
-// Allocation to write the results into
-static float gResultBuffer[gMaxModes];
-
-rs_font gFontSerif;
-rs_sampler gLinearClamp;
-
-rs_program_vertex gProgVertex;
-rs_program_fragment gProgFragmentTexture;
-
-rs_allocation gRenderBufferColor;
-rs_allocation gRenderBufferDepth;
-
-VertexShaderInputs *gVSInputs;
-
-typedef struct TestScripts_s {
-    rs_allocation testData;
-    rs_allocation testName;
-    rs_allocation debugName;
-    rs_script testScript;
-} TestScripts;
-TestScripts *gTestScripts;
-
-bool gLoadComplete = false;
-bool gPauseRendering = false;
-
-static float gDt = 0;
-
-void init() {
-}
-
-static int gRenderSurfaceW;
-static int gRenderSurfaceH;
-
-static void fillSurfaceParams(TestData *testData) {
-    testData->renderSurfaceW = gRenderSurfaceW;
-    testData->renderSurfaceH = gRenderSurfaceH;
-    testData->dt = gDt;
-}
-
-static void setupOffscreenTarget() {
-    rsgBindColorTarget(gRenderBufferColor, 0);
-    rsgBindDepthTarget(gRenderBufferDepth);
-}
-
-static void bindProgramVertexOrtho() {
-    // Default vertex shader
-    rsgBindProgramVertex(gProgVertex);
-    // Setup the projection matrix
-    rs_matrix4x4 proj;
-    rsMatrixLoadOrtho(&proj, 0, gRenderSurfaceW, gRenderSurfaceH, 0, -500, 500);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-}
-
-static void runSubTest(int index) {
-    TestData testData;
-    fillSurfaceParams(&testData);
-
-    rs_allocation null_alloc = {0};
-    rsForEach(gTestScripts[index].testScript,
-              gTestScripts[index].testData,
-              null_alloc,
-              &testData,
-              sizeof(testData));
-}
-
-
-static bool checkInit() {
-
-    static int countdown = 3;
-
-    // Perform all the uploads so we only measure rendered time
-    if(countdown > 1) {
-        int testCount = rsAllocationGetDimX(rsGetAllocation(gTestScripts));
-        for(int i = 0; i < testCount; i ++) {
-            rsgClearColor(0.2f, 0.2f, 0.2f, 0.0f);
-            runSubTest(i);
-            rsgFinish();
-        }
-        countdown --;
-        rsgClearColor(0.2f, 0.2f, 0.2f, 0.0f);
-
-        rsgFontColor(0.9f, 0.9f, 0.95f, 1.0f);
-        rsgBindFont(gFontSerif);
-        if (countdown == 1) {
-            rsgDrawText("Rendering", 50, 50);
-        } else {
-            rsgDrawText("Initializing", 50, 50);
-        }
-
-        return false;
-    }
-
-    return true;
-}
-
-static int benchMode = 0;
-static bool benchmarkSingleTest = false;
-static int runningLoops = 0;
-static bool sendMsgFlag = false;
-
-static bool gIsDebugMode = false;
-void setDebugMode(int testNumber) {
-    gIsDebugMode = true;
-    benchMode = testNumber;
-    rsgClearAllRenderTargets();
-}
-
-void setBenchmarkMode(int testNumber) {
-    gIsDebugMode = false;
-    if (testNumber == -1) {
-        benchmarkSingleTest = false;
-        benchMode = 0;
-    } else {
-        benchmarkSingleTest = true;
-        benchMode = testNumber;
-    }
-
-    runningLoops = 0;
-}
-
-static void drawOffscreenResult(int posX, int posY, int width, int height) {
-    bindProgramVertexOrtho();
-
-    rs_matrix4x4 matrix;
-    rsMatrixLoadIdentity(&matrix);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    rsgBindProgramFragment(gProgFragmentTexture);
-
-    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
-    rsgBindTexture(gProgFragmentTexture, 0, gRenderBufferColor);
-
-    float startX = posX, startY = posY;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 1,
-                         startX, startY + height, 0, 0, 0,
-                         startX + width, startY + height, 0, 1, 0,
-                         startX + width, startY, 0, 1, 1);
-}
-
-static void benchmark() {
-
-    gDt = 1.0f / 60.0f;
-
-    rsgFinish();
-    int64_t start = rsUptimeMillis();
-
-    int drawPos = 0;
-    int frameCount = 100;
-    for(int i = 0; i < frameCount; i ++) {
-        setupOffscreenTarget();
-        gRenderSurfaceW = rsAllocationGetDimX(gRenderBufferColor);
-        gRenderSurfaceH = rsAllocationGetDimY(gRenderBufferColor);
-        rsgClearColor(0.1f, 0.1f, 0.1f, 1.0f);
-        rsgClearDepth(1.0f);
-
-        runSubTest(benchMode);
-        rsgClearAllRenderTargets();
-        gRenderSurfaceW = rsgGetWidth();
-        gRenderSurfaceH = rsgGetHeight();
-        int size = 8;
-        // draw each frame at (8, 3/4 gRenderSurfaceH) with size
-        drawOffscreenResult((drawPos+=size)%gRenderSurfaceW, (gRenderSurfaceH * 3) / 4, size, size);
-    }
-
-    rsgFinish();
-
-    int64_t end = rsUptimeMillis();
-    float fps = (float)(frameCount) / ((float)(end - start)*0.001f);
-    const char *testName = rsGetElementAt(gTestScripts[benchMode].debugName, 0);
-    rsDebug(testName, fps);
-
-    gResultBuffer[benchMode] = fps;
-    int bufferW = rsAllocationGetDimX(gRenderBufferColor);
-    int bufferH = rsAllocationGetDimY(gRenderBufferColor);
-
-    int quadW = gRenderSurfaceW / 2;
-    int quadH = (quadW * bufferH) / bufferW;
-    drawOffscreenResult(0, 0, quadW, quadH);
-
-    int left = 0, right = 0, top = 0, bottom = 0;
-    uint height = rsgGetHeight();
-    rsgFontColor(0.9f, 0.9f, 0.95f, 1.0f);
-    rsgBindFont(gFontSerif);
-    rsgMeasureText(gTestScripts[benchMode].testName, &left, &right, &top, &bottom);
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgDrawText(gTestScripts[benchMode].testName, 2 -left, height - 2 + bottom);
-
-    if (benchmarkSingleTest) {
-        return;
-    }
-
-    benchMode ++;
-    int testCount = rsAllocationGetDimX(rsGetAllocation(gTestScripts));
-    if (benchMode == testCount) {
-        rsSendToClientBlocking(RS_MSG_RESULTS_READY, gResultBuffer, testCount*sizeof(float));
-        benchMode = 0;
-        runningLoops++;
-        if ((gMaxLoops > 0) && (runningLoops > gMaxLoops) && !sendMsgFlag) {
-            //Notifiy the test to stop and get results
-            rsDebug("gMaxLoops and runningLoops: ", gMaxLoops, runningLoops);
-            rsSendToClientBlocking(RS_MSG_TEST_DONE);
-            sendMsgFlag = true;
-        }
-    }
-}
-
-static void debug() {
-    gDt = rsGetDt();
-    runSubTest(benchMode);
-}
-
-int root(void) {
-    gRenderSurfaceW = rsgGetWidth();
-    gRenderSurfaceH = rsgGetHeight();
-    rsgClearColor(0.2f, 0.2f, 0.2f, 1.0f);
-    rsgClearDepth(1.0f);
-
-    if (!gLoadComplete) {
-        rsgFontColor(0.9f, 0.9f, 0.95f, 1.0f);
-        rsgBindFont(gFontSerif);
-        rsgDrawText("Loading", 50, 50);
-        return 0;
-    }
-
-    if(!checkInit()) {
-        return 1;
-    }
-
-    if (gPauseRendering) {
-        rsgDrawText("Paused", 50, 50);
-        return 30;
-    }
-    if (gIsDebugMode) {
-        debug();
-    } else {
-        benchmark();
-    }
-
-    return 1;
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/shader_def.rsh b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/shader_def.rsh
deleted file mode 100644
index 648359c..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/shader_def.rsh
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright (C) 2009 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.perftest)
-
-typedef struct VertexShaderConstants_s {
-    rs_matrix4x4 model;
-    rs_matrix4x4 proj;
-    float4 light0_Posision;
-    float light0_Diffuse;
-    float light0_Specular;
-    float light0_CosinePower;
-
-    float4 light1_Posision;
-    float light1_Diffuse;
-    float light1_Specular;
-    float light1_CosinePower;
-} VertexShaderConstants;
-
-typedef struct VertexShaderConstants3_s {
-    rs_matrix4x4 model;
-    rs_matrix4x4 proj;
-    float time;
-} VertexShaderConstants3;
-
-
-typedef struct FragentShaderConstants_s {
-    float4 light0_DiffuseColor;
-    float4 light0_SpecularColor;
-
-    float4 light1_DiffuseColor;
-    float4 light1_SpecularColor;
-} FragentShaderConstants;
-
-typedef struct FragentShaderConstants2_s {
-    float4 light_DiffuseColor[2];
-    float4 light_SpecularColor[2];
-} FragentShaderConstants2;
-
-typedef struct FragentShaderConstants3_s {
-    float4 light0_DiffuseColor;
-    float4 light0_SpecularColor;
-    float4 light0_Posision;
-    float light0_Diffuse;
-    float light0_Specular;
-    float light0_CosinePower;
-
-    float4 light1_DiffuseColor;
-    float4 light1_SpecularColor;
-    float4 light1_Posision;
-    float light1_Diffuse;
-    float light1_Specular;
-    float light1_CosinePower;
-} FragentShaderConstants3;
-
-typedef struct VertexShaderInputs_s {
-    float4 position;
-    float3 normal;
-    float2 texture0;
-} VertexShaderInputs;
-
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/subtest_def.rsh b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/subtest_def.rsh
deleted file mode 100644
index 43658b1..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/subtest_def.rsh
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.perftest)
-
-typedef struct TestData_s {
-    int renderSurfaceW;
-    int renderSurfaceH;
-    float dt;
-} TestData;
-
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/text_test.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/text_test.rs
deleted file mode 100644
index 0f50828..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/text_test.rs
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.perftest)
-
-#include "rs_graphics.rsh"
-#include "subtest_def.rsh"
-
-rs_font gFontSans;
-rs_font gFontSerif;
-
-typedef struct TextTestData_s {
-    int fillNum;
-} TextTestData;
-TextTestData *gData;
-
-void init() {
-}
-
-static int gRenderSurfaceW = 1280;
-static int gRenderSurfaceH = 720;
-
-static const char *sampleText = "This is a sample of small text for performace";
-// Offsets for multiple layer of text
-static int textOffsets[] = { 0,  0, -5, -5, 5,  5, -8, -8, 8,  8};
-static float textColors[] = {1.0f, 1.0f, 1.0f, 1.0f,
-                             0.5f, 0.7f, 0.5f, 1.0f,
-                             0.7f, 0.5f, 0.5f, 1.0f,
-                             0.5f, 0.5f, 0.7f, 1.0f,
-                             0.5f, 0.6f, 0.7f, 1.0f,
-};
-
-static void displayFontSamples(int fillNum) {
-
-    rs_font fonts[5];
-    fonts[0] = gFontSans;
-    fonts[1] = gFontSerif;
-    fonts[2] = gFontSans;
-    fonts[3] = gFontSerif;
-    fonts[4] = gFontSans;
-
-    uint height = gRenderSurfaceH;
-    int left = 0, right = 0, top = 0, bottom = 0;
-    rsgMeasureText(sampleText, &left, &right, &top, &bottom);
-
-    int textHeight = top - bottom;
-    int textWidth = right - left;
-    int numVerticalLines = height / textHeight;
-    int yPos = top;
-
-    int xOffset = 0, yOffset = 0;
-    for(int fillI = 0; fillI < fillNum; fillI ++) {
-        rsgBindFont(fonts[fillI]);
-        xOffset = textOffsets[fillI * 2];
-        yOffset = textOffsets[fillI * 2 + 1];
-        float *colPtr = textColors + fillI * 4;
-        rsgFontColor(colPtr[0], colPtr[1], colPtr[2], colPtr[3]);
-        for (int h = 0; h < 4; h ++) {
-            yPos = top + yOffset;
-            for (int v = 0; v < numVerticalLines; v ++) {
-                rsgDrawText(sampleText, xOffset + textWidth * h, yPos);
-                yPos += textHeight;
-            }
-        }
-    }
-}
-
-void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) {
-    TestData *testData = (TestData*)usrData;
-    gRenderSurfaceW = testData->renderSurfaceW;
-    gRenderSurfaceH = testData->renderSurfaceH;
-
-    gData = (TextTestData*)v_in;
-
-    displayFontSamples(gData->fillNum);
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/torus_test.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/torus_test.rs
deleted file mode 100644
index 853a05d..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/torus_test.rs
+++ /dev/null
@@ -1,295 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.perftest)
-
-#include "rs_graphics.rsh"
-#include "subtest_def.rsh"
-#include "shader_def.rsh"
-
-rs_program_vertex gProgVertex;
-rs_program_fragment gProgFragmentColor;
-rs_program_fragment gProgFragmentTexture;
-
-rs_program_store gProgStoreBlendNoneDepth;
-rs_mesh gTorusMesh;
-
-rs_program_raster gCullBack;
-rs_program_raster gCullFront;
-
-// Custom vertex shader compunents
-VertexShaderConstants *gVSConstants;
-FragentShaderConstants *gFSConstants;
-VertexShaderConstants3 *gVSConstPixel;
-FragentShaderConstants3 *gFSConstPixel;
-
-// Custom shaders we use for lighting
-rs_program_vertex gProgVertexCustom;
-rs_program_fragment gProgFragmentCustom;
-
-rs_sampler gLinearClamp;
-rs_allocation gTexTorus;
-
-rs_program_vertex gProgVertexPixelLight;
-rs_program_vertex gProgVertexPixelLightMove;
-rs_program_fragment gProgFragmentPixelLight;
-
-typedef struct TorusTestData_s {
-    int testId;
-    int user1;
-    int user2;
-} TorusTestData;
-TorusTestData *gData;
-
-static float gDt = 0.0f;
-
-static int gRenderSurfaceW;
-static int gRenderSurfaceH;
-
-
-static float gTorusRotation = 0;
-static void updateModelMatrix(rs_matrix4x4 *matrix, void *buffer) {
-    if (buffer == 0) {
-        rsgProgramVertexLoadModelMatrix(matrix);
-    } else {
-        rsgAllocationSyncAll(rsGetAllocation(buffer));
-    }
-}
-
-static void drawToruses(int numMeshes, rs_matrix4x4 *matrix, void *buffer) {
-
-    if (numMeshes == 1) {
-        rsMatrixLoadTranslate(matrix, 0.0f, 0.0f, -7.5f);
-        rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
-        updateModelMatrix(matrix, buffer);
-        rsgDrawMesh(gTorusMesh);
-        return;
-    }
-
-    if (numMeshes == 2) {
-        rsMatrixLoadTranslate(matrix, -1.6f, 0.0f, -7.5f);
-        rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
-        updateModelMatrix(matrix, buffer);
-        rsgDrawMesh(gTorusMesh);
-
-        rsMatrixLoadTranslate(matrix, 1.6f, 0.0f, -7.5f);
-        rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
-        updateModelMatrix(matrix, buffer);
-        rsgDrawMesh(gTorusMesh);
-        return;
-    }
-
-    float startX = -5.0f;
-    float startY = -1.5f;
-    float startZ = -15.0f;
-    float dist = 3.2f;
-
-    for (int h = 0; h < 4; h ++) {
-        for (int v = 0; v < 2; v ++) {
-            // Position our model on the screen
-            rsMatrixLoadTranslate(matrix, startX + dist * h, startY + dist * v, startZ);
-            rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
-            updateModelMatrix(matrix, buffer);
-            rsgDrawMesh(gTorusMesh);
-        }
-    }
-}
-
-
-// Quick hack to get some geometry numbers
-static void displaySimpleGeoSamples(bool useTexture, int numMeshes) {
-    rsgBindProgramVertex(gProgVertex);
-    rsgBindProgramRaster(gCullBack);
-    // Setup the projection matrix with 30 degree field of view
-    rs_matrix4x4 proj;
-    float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH;
-    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNoneDepth);
-    if (useTexture) {
-        rsgBindProgramFragment(gProgFragmentTexture);
-    } else {
-        rsgBindProgramFragment(gProgFragmentColor);
-        rsgProgramFragmentConstantColor(gProgFragmentColor, 0.1, 0.7, 0.1, 1);
-    }
-    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
-    rsgBindTexture(gProgFragmentTexture, 0, gTexTorus);
-
-    // Apply a rotation to our mesh
-    gTorusRotation += 50.0f * gDt;
-    if (gTorusRotation > 360.0f) {
-        gTorusRotation -= 360.0f;
-    }
-
-    rs_matrix4x4 matrix;
-    drawToruses(numMeshes, &matrix, 0);
-}
-
-float gLight0Rotation = 0;
-float gLight1Rotation = 0;
-
-static void setupCustomShaderLights() {
-    float4 light0Pos = {-5.0f, 5.0f, -10.0f, 1.0f};
-    float4 light1Pos = {2.0f, 5.0f, 15.0f, 1.0f};
-    float4 light0DiffCol = {0.9f, 0.7f, 0.7f, 1.0f};
-    float4 light0SpecCol = {0.9f, 0.6f, 0.6f, 1.0f};
-    float4 light1DiffCol = {0.5f, 0.5f, 0.9f, 1.0f};
-    float4 light1SpecCol = {0.5f, 0.5f, 0.9f, 1.0f};
-
-    gLight0Rotation += 50.0f * gDt;
-    if (gLight0Rotation > 360.0f) {
-        gLight0Rotation -= 360.0f;
-    }
-    gLight1Rotation -= 50.0f * gDt;
-    if (gLight1Rotation > 360.0f) {
-        gLight1Rotation -= 360.0f;
-    }
-
-    rs_matrix4x4 l0Mat;
-    rsMatrixLoadRotate(&l0Mat, gLight0Rotation, 1.0f, 0.0f, 0.0f);
-    light0Pos = rsMatrixMultiply(&l0Mat, light0Pos);
-    rs_matrix4x4 l1Mat;
-    rsMatrixLoadRotate(&l1Mat, gLight1Rotation, 0.0f, 0.0f, 1.0f);
-    light1Pos = rsMatrixMultiply(&l1Mat, light1Pos);
-
-    // Set light 0 properties
-    gVSConstants->light0_Posision = light0Pos;
-    gVSConstants->light0_Diffuse = 1.0f;
-    gVSConstants->light0_Specular = 0.5f;
-    gVSConstants->light0_CosinePower = 10.0f;
-    // Set light 1 properties
-    gVSConstants->light1_Posision = light1Pos;
-    gVSConstants->light1_Diffuse = 1.0f;
-    gVSConstants->light1_Specular = 0.7f;
-    gVSConstants->light1_CosinePower = 25.0f;
-    rsgAllocationSyncAll(rsGetAllocation(gVSConstants));
-
-    // Update fragment shader constants
-    // Set light 0 colors
-    gFSConstants->light0_DiffuseColor = light0DiffCol;
-    gFSConstants->light0_SpecularColor = light0SpecCol;
-    // Set light 1 colors
-    gFSConstants->light1_DiffuseColor = light1DiffCol;
-    gFSConstants->light1_SpecularColor = light1SpecCol;
-    rsgAllocationSyncAll(rsGetAllocation(gFSConstants));
-
-    // Set light 0 properties for per pixel lighting
-    gFSConstPixel->light0_Posision = light0Pos;
-    gFSConstPixel->light0_Diffuse = 1.0f;
-    gFSConstPixel->light0_Specular = 0.5f;
-    gFSConstPixel->light0_CosinePower = 10.0f;
-    gFSConstPixel->light0_DiffuseColor = light0DiffCol;
-    gFSConstPixel->light0_SpecularColor = light0SpecCol;
-    // Set light 1 properties
-    gFSConstPixel->light1_Posision = light1Pos;
-    gFSConstPixel->light1_Diffuse = 1.0f;
-    gFSConstPixel->light1_Specular = 0.7f;
-    gFSConstPixel->light1_CosinePower = 25.0f;
-    gFSConstPixel->light1_DiffuseColor = light1DiffCol;
-    gFSConstPixel->light1_SpecularColor = light1SpecCol;
-    rsgAllocationSyncAll(rsGetAllocation(gFSConstPixel));
-}
-
-static void displayCustomShaderSamples(int numMeshes) {
-
-    // Update vertex shader constants
-    // Load model matrix
-    // Apply a rotation to our mesh
-    gTorusRotation += 50.0f * gDt;
-    if (gTorusRotation > 360.0f) {
-        gTorusRotation -= 360.0f;
-    }
-
-    // Setup the projection matrix
-    float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH;
-    rsMatrixLoadPerspective(&gVSConstants->proj, 30.0f, aspect, 0.1f, 100.0f);
-    setupCustomShaderLights();
-
-    rsgBindProgramVertex(gProgVertexCustom);
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNoneDepth);
-    rsgBindProgramFragment(gProgFragmentCustom);
-    rsgBindSampler(gProgFragmentCustom, 0, gLinearClamp);
-    rsgBindTexture(gProgFragmentCustom, 0, gTexTorus);
-
-    // Use back face culling
-    rsgBindProgramRaster(gCullBack);
-
-    drawToruses(numMeshes, &gVSConstants->model, gVSConstants);
-}
-
-static void displayPixelLightSamples(int numMeshes, bool heavyVertex) {
-
-    // Update vertex shader constants
-    // Load model matrix
-    // Apply a rotation to our mesh
-    gTorusRotation += 30.0f * gDt;
-    if (gTorusRotation > 360.0f) {
-        gTorusRotation -= 360.0f;
-    }
-
-    gVSConstPixel->time = rsUptimeMillis()*0.005;
-
-    // Setup the projection matrix
-    float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH;
-    rsMatrixLoadPerspective(&gVSConstPixel->proj, 30.0f, aspect, 0.1f, 100.0f);
-    setupCustomShaderLights();
-
-    if (heavyVertex) {
-        rsgBindProgramVertex(gProgVertexPixelLightMove);
-    } else {
-        rsgBindProgramVertex(gProgVertexPixelLight);
-    }
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendNoneDepth);
-    rsgBindProgramFragment(gProgFragmentPixelLight);
-    rsgBindSampler(gProgFragmentPixelLight, 0, gLinearClamp);
-    rsgBindTexture(gProgFragmentPixelLight, 0, gTexTorus);
-
-    // Use back face culling
-    rsgBindProgramRaster(gCullBack);
-
-    drawToruses(numMeshes, &gVSConstPixel->model, gVSConstPixel);
-}
-
-
-void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) {
-    TestData *testData = (TestData*)usrData;
-    gRenderSurfaceW = testData->renderSurfaceW;
-    gRenderSurfaceH = testData->renderSurfaceH;
-    gDt = testData->dt;
-
-    gData = (TorusTestData*)v_in;
-
-    switch(gData->testId) {
-        case 0:
-            displaySimpleGeoSamples(gData->user1 == 1 ? true : false, gData->user2);
-            break;
-        case 1:
-            displayCustomShaderSamples(gData->user1);
-            break;
-        case 2:
-            displayPixelLightSamples(gData->user1, gData->user2 == 1 ? true : false);
-            break;
-        default:
-            rsDebug("Wrong test number", gData->testId);
-            break;
-    }
-}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/ui_test.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/ui_test.rs
deleted file mode 100644
index e87db39..0000000
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/ui_test.rs
+++ /dev/null
@@ -1,442 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.perftest)
-
-#include "rs_graphics.rsh"
-#include "shader_def.rsh"
-#include "subtest_def.rsh"
-
-// Parameters for galaxy live wallpaper
-rs_allocation gTSpace;
-rs_allocation gTLight1;
-rs_allocation gTFlares;
-rs_mesh gParticlesMesh;
-
-rs_program_fragment gPFBackground;
-rs_program_fragment gPFStars;
-rs_program_vertex gPVStars;
-rs_program_vertex gPVBkProj;
-rs_program_store gPSLights;
-
-float gXOffset = 0.5f;
-
-#define ELLIPSE_RATIO 0.892f
-#define PI 3.1415f
-#define TWO_PI 6.283f
-#define ELLIPSE_TWIST 0.023333333f
-
-static float angle = 50.f;
-static int gOldWidth;
-static int gOldHeight;
-static int gWidth;
-static int gHeight;
-static float gSpeed[12000];
-static int gGalaxyRadius = 300;
-static rs_allocation gParticlesBuffer;
-
-typedef struct __attribute__((packed, aligned(4))) Particle {
-    uchar4 color;
-    float3 position;
-} Particle_t;
-Particle_t *Particles;
-
-typedef struct VpConsts {
-    rs_matrix4x4 Proj;
-    rs_matrix4x4 MVP;
-} VpConsts_t;
-VpConsts_t *vpConstants;
-// End of parameters for galaxy live wallpaper
-
-rs_program_vertex gProgVertex;
-rs_program_fragment gProgFragmentColor;
-rs_program_fragment gProgFragmentTexture;
-
-rs_program_store gProgStoreBlendAlpha;
-
-rs_allocation gTexOpaque;
-rs_allocation gTexTorus;
-rs_allocation gTexGlobe;
-
-typedef struct ListAllocs_s {
-    rs_allocation item;
-} ListAllocs;
-
-ListAllocs *gTexList100;
-ListAllocs *gSampleTextList100;
-ListAllocs *gListViewText;
-
-rs_mesh gSingleMesh;
-
-rs_font gFontSans;
-
-rs_sampler gLinearClamp;
-
-typedef struct UiTestData_s {
-    int testId;
-    int user1;
-    int user2;
-    int user3;
-} UiTestData;
-UiTestData *gData;
-
-static float gDt = 0;
-
-
-void init() {
-}
-
-static int gRenderSurfaceW;
-static int gRenderSurfaceH;
-
-static void bindProgramVertexOrtho() {
-    // Default vertex shader
-    rsgBindProgramVertex(gProgVertex);
-    // Setup the projection matrix
-    rs_matrix4x4 proj;
-    rsMatrixLoadOrtho(&proj, 0, gRenderSurfaceW, gRenderSurfaceH, 0, -500, 500);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-}
-
-/**
-  * Methods to draw the galaxy live wall paper
-  */
-static float mapf(float minStart, float minStop, float maxStart, float maxStop, float value) {
-    return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
-}
-
-/**
- * Helper function to generate the stars.
- */
-static float randomGauss() {
-    float x1;
-    float x2;
-    float w = 2.f;
-
-    while (w >= 1.0f) {
-        x1 = rsRand(2.0f) - 1.0f;
-        x2 = rsRand(2.0f) - 1.0f;
-        w = x1 * x1 + x2 * x2;
-    }
-
-    w = sqrt(-2.0f * log(w) / w);
-    return x1 * w;
-}
-
-/**
- * Generates the properties for a given star.
- */
-static void createParticle(Particle_t *part, int idx, float scale) {
-    float d = fabs(randomGauss()) * gGalaxyRadius * 0.5f + rsRand(64.0f);
-    float id = d / gGalaxyRadius;
-    float z = randomGauss() * 0.4f * (1.0f - id);
-
-    if (d < gGalaxyRadius * 0.33f) {
-        part->color.x = (uchar) (220 + id * 35);
-        part->color.y = 220;
-        part->color.z = 220;
-    } else {
-        part->color.x = 180;
-        part->color.y = 180;
-        part->color.z = (uchar) clamp(140.f + id * 115.f, 140.f, 255.f);
-    }
-    // Stash point size * 10 in Alpha
-    part->color.w = (uchar) (rsRand(1.2f, 2.1f) * 60);
-
-    if (d > gGalaxyRadius * 0.15f) {
-        z *= 0.6f * (1.0f - id);
-    } else {
-        z *= 0.72f;
-    }
-
-    // Map to the projection coordinates (viewport.x = -1.0 -> 1.0)
-    d = mapf(-4.0f, gGalaxyRadius + 4.0f, 0.0f, scale, d);
-
-    part->position.x = rsRand(TWO_PI);
-    part->position.y = d;
-    gSpeed[idx] = rsRand(0.0015f, 0.0025f) * (0.5f + (scale / d)) * 0.8f;
-
-    part->position.z = z / 5.0f;
-}
-
-/**
- * Initialize all the starts, called from Java
- */
-void initParticles() {
-    Particle_t *part = Particles;
-    float scale = gGalaxyRadius / (gWidth * 0.5f);
-    int count = rsAllocationGetDimX(gParticlesBuffer);
-    for (int i = 0; i < count; i ++) {
-        createParticle(part, i, scale);
-        part++;
-    }
-}
-
-static void drawSpace() {
-    rsgBindProgramFragment(gPFBackground);
-    rsgBindTexture(gPFBackground, 0, gTSpace);
-    rsgDrawQuadTexCoords(
-            0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
-            gWidth, 0.0f, 0.0f, 2.0f, 1.0f,
-            gWidth, gHeight, 0.0f, 2.0f, 0.0f,
-            0.0f, gHeight, 0.0f, 0.0f, 0.0f);
-}
-
-static void drawLights() {
-    rsgBindProgramVertex(gPVBkProj);
-    rsgBindProgramFragment(gPFBackground);
-    rsgBindTexture(gPFBackground, 0, gTLight1);
-
-    float scale = 512.0f / gWidth;
-    float x = -scale - scale * 0.05f;
-    float y = -scale;
-
-    scale *= 2.0f;
-
-    rsgDrawQuad(x, y, 0.0f,
-             x + scale * 1.1f, y, 0.0f,
-             x + scale * 1.1f, y + scale, 0.0f,
-             x, y + scale, 0.0f);
-}
-
-static void drawParticles(float offset) {
-    float a = offset * angle;
-    float absoluteAngle = fabs(a);
-
-    rs_matrix4x4 matrix;
-    rsMatrixLoadTranslate(&matrix, 0.0f, 0.0f, 10.0f - 6.0f * absoluteAngle / 50.0f);
-    if (gHeight > gWidth) {
-        rsMatrixScale(&matrix, 6.6f, 6.0f, 1.0f);
-    } else {
-        rsMatrixScale(&matrix, 12.6f, 12.0f, 1.0f);
-    }
-    rsMatrixRotate(&matrix, absoluteAngle, 1.0f, 0.0f, 0.0f);
-    rsMatrixRotate(&matrix, a, 0.0f, 0.4f, 0.1f);
-    rsMatrixLoad(&vpConstants->MVP, &vpConstants->Proj);
-    rsMatrixMultiply(&vpConstants->MVP, &matrix);
-    rsgAllocationSyncAll(rsGetAllocation(vpConstants));
-
-    rsgBindProgramVertex(gPVStars);
-    rsgBindProgramFragment(gPFStars);
-    rsgBindProgramStore(gPSLights);
-    rsgBindTexture(gPFStars, 0, gTFlares);
-
-    Particle_t *vtx = Particles;
-    int count = rsAllocationGetDimX(gParticlesBuffer);
-    for (int i = 0; i < count; i++) {
-        vtx->position.x = vtx->position.x + gSpeed[i];
-        vtx++;
-    }
-
-    rsgDrawMesh(gParticlesMesh);
-}
-/* end of methods for drawing galaxy */
-
-// Display sample images in a mesh with different texture
-static void displayIcons(int meshMode) {
-    bindProgramVertexOrtho();
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendAlpha);
-    rsgBindProgramFragment(gProgFragmentTexture);
-    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
-    rsgBindTexture(gProgFragmentTexture, 0, gTexTorus);
-    rsgDrawQuadTexCoords(
-            0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
-            0.0f, gRenderSurfaceH, 0.0f, 0.0f, 1.0f,
-            gRenderSurfaceW, gRenderSurfaceH, 0.0f, 1.0f, 1.0f,
-            gRenderSurfaceW, 0.0f, 0.0f, 1.0f, 0.0f);
-
-    int meshCount = (int)pow(10.0f, (float)(meshMode + 1));
-
-    float wSize = gRenderSurfaceW/(float)meshCount;
-    float hSize = gRenderSurfaceH/(float)meshCount;
-    rs_matrix4x4 matrix;
-    rsMatrixLoadScale(&matrix, wSize, hSize, 1.0);
-
-    float yPos = 0;
-    float yPad = hSize / 2;
-    float xPad = wSize / 2;
-    for (int y = 0; y < meshCount; y++) {
-        yPos = y * hSize + yPad;
-        float xPos = 0;
-        for (int x = 0; x < meshCount; x++) {
-            xPos = x * wSize + xPad;
-            rs_matrix4x4 transMatrix;
-            rsMatrixLoadTranslate(&transMatrix, xPos, yPos, 0);
-            rsMatrixMultiply(&transMatrix, &matrix);
-            rsgProgramVertexLoadModelMatrix(&transMatrix);
-            int i = (x + y * meshCount) % 100;
-            rsgBindTexture(gProgFragmentTexture, 0, gTexList100[i].item);
-            rsgDrawMesh(gSingleMesh);
-        }
-    }
-}
-
-// Draw meshes in a single page with top left corner coordinates (xStart, yStart)
-static void drawMeshInPage(float xStart, float yStart, int wResolution, int hResolution) {
-    // Draw wResolution * hResolution meshes in one page
-    float wMargin = 100.0f;
-    float hMargin = 100.0f;
-    float xPad = 50.0f;
-    float yPad = 20.0f;
-    float size = 100.0f;  // size of images
-
-    // font info
-    rs_font font = gFontSans;
-    rsgBindFont(font);
-    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
-
-    // Measure text size
-    int left = 0, right = 0, top = 0, bottom = 0;
-    rsgMeasureText(gSampleTextList100[0].item, &left, &right, &top, &bottom);
-    float textHeight = (float)(top - bottom);
-
-    rs_matrix4x4 matrix;
-    rsMatrixLoadScale(&matrix, size, size, 1.0);
-
-    for (int y = 0; y < hResolution; y++) {
-        float yPos = yStart + hMargin + y * size + y * yPad;
-        for (int x = 0; x < wResolution; x++) {
-            float xPos = xStart + wMargin + x * size + x * xPad;
-
-            rs_matrix4x4 transMatrix;
-            rsMatrixLoadTranslate(&transMatrix, xPos + size/2, yPos + size/2, 0);
-            rsMatrixMultiply(&transMatrix, &matrix);  // scale the mesh
-            rsgProgramVertexLoadModelMatrix(&transMatrix);
-
-            int i = (y * wResolution + x) % 100;
-            rsgBindTexture(gProgFragmentTexture, 0, gTexList100[i].item);
-            rsgDrawMesh(gSingleMesh);
-            rsgDrawText(gSampleTextList100[i].item, xPos, yPos + size + yPad/2 + textHeight);
-        }
-    }
-}
-
-// Display both images and text as shown in launcher and homepage
-// meshMode will decide how many pages we draw
-// meshMode = 0: draw 3 pages of meshes
-// meshMode = 1: draw 5 pages of meshes
-static void displayImageWithText(int wResolution, int hResolution, int meshMode) {
-    bindProgramVertexOrtho();
-
-    // Fragment shader with texture
-    rsgBindProgramStore(gProgStoreBlendAlpha);
-    rsgBindProgramFragment(gProgFragmentTexture);
-    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
-
-    drawMeshInPage(0, 0, wResolution, hResolution);
-    drawMeshInPage(-1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
-    drawMeshInPage(1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
-    if (meshMode == 1) {
-        // draw another two pages of meshes
-        drawMeshInPage(-2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
-        drawMeshInPage(2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
-    }
-}
-
-// Display a list of text as the list view
-static void displayListView() {
-    // set text color
-    rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f);
-    rsgBindFont(gFontSans);
-
-    // get the size of the list
-    rs_allocation textAlloc;
-    textAlloc = rsGetAllocation(gListViewText);
-    int allocSize = rsAllocationGetDimX(textAlloc);
-
-    int listItemHeight = 80;
-    int yOffset = listItemHeight;
-
-    // set the color for the list divider
-    rsgBindProgramFragment(gProgFragmentColor);
-    rsgProgramFragmentConstantColor(gProgFragmentColor, 1.0, 1.0, 1.0, 1);
-
-    // draw the list with divider
-    for (int i = 0; i < allocSize; i++) {
-        if (yOffset - listItemHeight > gRenderSurfaceH) {
-            break;
-        }
-        rsgDrawRect(0, yOffset - 1, gRenderSurfaceW, yOffset, 0);
-        rsgDrawText(gListViewText[i].item, 20, yOffset - 10);
-        yOffset += listItemHeight;
-    }
-}
-
-static void drawGalaxy() {
-    rsgClearColor(0.f, 0.f, 0.f, 1.f);
-    gParticlesBuffer = rsGetAllocation(Particles);
-    rsgBindProgramFragment(gPFBackground);
-
-    gWidth = rsgGetWidth();
-    gHeight = rsgGetHeight();
-    if ((gWidth != gOldWidth) || (gHeight != gOldHeight)) {
-        initParticles();
-        gOldWidth = gWidth;
-        gOldHeight = gHeight;
-    }
-
-    float offset = mix(-1.0f, 1.0f, gXOffset);
-    drawSpace();
-    drawParticles(offset);
-    drawLights();
-}
-
-// Display images and text with live wallpaper in the background
-static void displayLiveWallPaper(int wResolution, int hResolution) {
-    bindProgramVertexOrtho();
-
-    drawGalaxy();
-
-    rsgBindProgramVertex(gProgVertex);
-    rsgBindProgramStore(gProgStoreBlendAlpha);
-    rsgBindProgramFragment(gProgFragmentTexture);
-    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
-
-    drawMeshInPage(0, 0, wResolution, hResolution);
-    drawMeshInPage(-1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
-    drawMeshInPage(1.0f*gRenderSurfaceW, 0, wResolution, hResolution);
-    drawMeshInPage(-2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
-    drawMeshInPage(2.0f*gRenderSurfaceW, 0, wResolution, hResolution);
-}
-
-void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) {
-    TestData *testData = (TestData*)usrData;
-    gRenderSurfaceW = testData->renderSurfaceW;
-    gRenderSurfaceH = testData->renderSurfaceH;
-    gDt = testData->dt;
-
-    gData = (UiTestData*)v_in;
-
-    switch(gData->testId) {
-        case 0:
-            displayIcons(gData->user1);
-            break;
-        case 1:
-            displayImageWithText(gData->user1, gData->user2, gData->user3);
-            break;
-        case 2:
-            displayListView();
-            break;
-        case 3:
-            displayLiveWallPaper(gData->user1, gData->user2);
-            break;
-        default:
-            rsDebug("Wrong test number", 0);
-            break;
-    }
-}
diff --git a/tests/RenderScriptTests/SceneGraph/Android.mk b/tests/RenderScriptTests/SceneGraph/Android.mk
deleted file mode 100644
index 6047305..0000000
--- a/tests/RenderScriptTests/SceneGraph/Android.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Copyright (C) 2011 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
-
-LOCAL_SDK_VERSION := 17
-
-LOCAL_PACKAGE_NAME := SceneGraphTest
-
-include $(BUILD_PACKAGE)
diff --git a/tests/RenderScriptTests/SceneGraph/AndroidManifest.xml b/tests/RenderScriptTests/SceneGraph/AndroidManifest.xml
deleted file mode 100644
index 67af0fa..0000000
--- a/tests/RenderScriptTests/SceneGraph/AndroidManifest.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.android.testapp">
-    <uses-permission
-        android:name="android.permission.INTERNET" />
-    <application android:label="SceneGraphTest">
-        <activity android:name="TestApp"
-                  android:label="SceneGraphTest">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-        <activity android:name="SimpleApp"
-                  android:label="SimpleSceneGraph">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-        <activity android:name="FileSelector"
-                  android:label="FileSelector"
-                  android:hardwareAccelerated="true">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-            </intent-filter>
-        </activity>
-    </application>
-</manifest>
diff --git a/tests/RenderScriptTests/SceneGraph/assets/blue.jpg b/tests/RenderScriptTests/SceneGraph/assets/blue.jpg
deleted file mode 100644
index 494e77a..0000000
--- a/tests/RenderScriptTests/SceneGraph/assets/blue.jpg
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/SceneGraph/assets/carbonfiber.jpg b/tests/RenderScriptTests/SceneGraph/assets/carbonfiber.jpg
deleted file mode 100644
index 2fcecb0..0000000
--- a/tests/RenderScriptTests/SceneGraph/assets/carbonfiber.jpg
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/SceneGraph/assets/green.jpg b/tests/RenderScriptTests/SceneGraph/assets/green.jpg
deleted file mode 100644
index a86a754..0000000
--- a/tests/RenderScriptTests/SceneGraph/assets/green.jpg
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/SceneGraph/assets/grey.jpg b/tests/RenderScriptTests/SceneGraph/assets/grey.jpg
deleted file mode 100644
index 5870b1a..0000000
--- a/tests/RenderScriptTests/SceneGraph/assets/grey.jpg
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/SceneGraph/assets/orange.jpg b/tests/RenderScriptTests/SceneGraph/assets/orange.jpg
deleted file mode 100644
index 7dbe942..0000000
--- a/tests/RenderScriptTests/SceneGraph/assets/orange.jpg
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/SceneGraph/assets/orientation_test.a3d b/tests/RenderScriptTests/SceneGraph/assets/orientation_test.a3d
deleted file mode 100644
index 07318ae..0000000
--- a/tests/RenderScriptTests/SceneGraph/assets/orientation_test.a3d
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/SceneGraph/assets/orientation_test.dae b/tests/RenderScriptTests/SceneGraph/assets/orientation_test.dae
deleted file mode 100644
index 7eef443..0000000
--- a/tests/RenderScriptTests/SceneGraph/assets/orientation_test.dae
+++ /dev/null
@@ -1,1102 +0,0 @@
-<?xml version="1.0" ?>
-<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
-    <asset>
-        <contributor>
-            <author>alexst</author>
-            <authoring_tool>OpenCOLLADA2010</authoring_tool>
-            <comments>ColladaMaya export options: bakeTransforms=0;relativePaths=0;copyTextures=0;exportTriangles=1;exportCgfxFileReferences=0; isSampling=0;curveConstrainSampling=0;removeStaticCurves=1;exportPolygonMeshes=1;exportLights=1; exportCameras=1;exportJointsAndSkin=1;exportAnimations=0;exportInvisibleNodes=0;exportDefaultCameras=0; exportTexCoords=1;exportNormals=1;exportNormalsPerVertex=1;exportVertexColors=0;exportVertexColorsPerVertex=0; exportTexTangents=0;exportTangents=0;exportReferencedMaterials=1;exportMaterialsOnly=0; exportXRefs=1;dereferenceXRefs=1;exportCameraAsLookat=0;cameraXFov=0;cameraYFov=1;doublePrecision=0</comments>
-            <source_data>file:///Volumes/Android/art/orientation_test.mb</source_data>
-        </contributor>
-        <created>2011-09-30T15:31:38</created>
-        <modified>2011-09-30T15:31:38</modified>
-        <unit meter="0.01" name="centimeter" />
-        <up_axis>Y_UP</up_axis>
-    </asset>
-    <library_cameras>
-        <camera id="cameraShape1" name="cameraShape1">
-            <optics>
-                <technique_common>
-                    <perspective>
-                        <yfov>37.8493</yfov>
-                        <aspect_ratio>1.5</aspect_ratio>
-                        <znear>1</znear>
-                        <zfar>400</zfar>
-                    </perspective>
-                </technique_common>
-            </optics>
-            <extra>
-                <technique profile="OpenCOLLADAMaya">
-                    <film_fit>0</film_fit>
-                    <film_fit_offset>0</film_fit_offset>
-                    <film_offsetX>0</film_offsetX>
-                    <film_offsetY>0</film_offsetY>
-                    <horizontal_aperture>3.599993</horizontal_aperture>
-                    <lens_squeeze>1</lens_squeeze>
-                    <originalMayaNodeId>cameraShape1</originalMayaNodeId>
-                    <vertical_aperture>2.399995</vertical_aperture>
-                </technique>
-            </extra>
-        </camera>
-        <camera id="CameraDistShape" name="CameraDistShape">
-            <optics>
-                <technique_common>
-                    <perspective>
-                        <yfov>37.8493</yfov>
-                        <aspect_ratio>1.5</aspect_ratio>
-                        <znear>1</znear>
-                        <zfar>1000</zfar>
-                    </perspective>
-                </technique_common>
-            </optics>
-            <extra>
-                <technique profile="OpenCOLLADAMaya">
-                    <film_fit>0</film_fit>
-                    <film_fit_offset>0</film_fit_offset>
-                    <film_offsetX>0</film_offsetX>
-                    <film_offsetY>0</film_offsetY>
-                    <horizontal_aperture>3.599993</horizontal_aperture>
-                    <lens_squeeze>1</lens_squeeze>
-                    <originalMayaNodeId>CameraDistShape</originalMayaNodeId>
-                    <vertical_aperture>2.399995</vertical_aperture>
-                </technique>
-            </extra>
-        </camera>
-    </library_cameras>
-    <library_materials>
-        <material id="Paint1" name="Paint1">
-            <instance_effect url="#Paint1-fx" />
-        </material>
-        <material id="lambert2" name="lambert2">
-            <instance_effect url="#lambert2-fx" />
-        </material>
-        <material id="Plastic" name="Plastic">
-            <instance_effect url="#Plastic-fx" />
-        </material>
-        <material id="Metal" name="Metal">
-            <instance_effect url="#Metal-fx" />
-        </material>
-        <material id="PlasticCenter" name="PlasticCenter">
-            <instance_effect url="#PlasticCenter-fx" />
-        </material>
-        <material id="PlasticRed" name="PlasticRed">
-            <instance_effect url="#PlasticRed-fx" />
-        </material>
-        <material id="lambert10" name="lambert10">
-            <instance_effect url="#lambert10-fx" />
-        </material>
-        <material id="lambert11" name="lambert11">
-            <instance_effect url="#lambert11-fx" />
-        </material>
-    </library_materials>
-    <library_effects>
-        <effect id="Metal-fx">
-            <profile_COMMON>
-                <newparam sid="file23-surface">
-                    <surface type="2D">
-                        <init_from>file23</init_from>
-                    </surface>
-                </newparam>
-                <newparam sid="file23-sampler">
-                    <sampler2D>
-                        <source>file23-surface</source>
-                    </sampler2D>
-                </newparam>
-                <technique sid="common">
-                    <lambert>
-                        <emission>
-                            <color>0 0 0 1</color>
-                        </emission>
-                        <ambient>
-                            <color>0 0 0 1</color>
-                        </ambient>
-                        <diffuse>
-                            <texture texture="file23-sampler" texcoord="TEX0">
-                                <extra>
-                                    <technique profile="OpenCOLLADAMaya">
-                                        <blend_mode>NONE</blend_mode>
-                                        <coverageU>1</coverageU>
-                                        <coverageV>1</coverageV>
-                                        <fast>0</fast>
-                                        <mirrorU>0</mirrorU>
-                                        <mirrorV>0</mirrorV>
-                                        <noiseU>0</noiseU>
-                                        <noiseV>0</noiseV>
-                                        <offsetU>0</offsetU>
-                                        <offsetV>0</offsetV>
-                                        <repeatU>1</repeatU>
-                                        <repeatV>1</repeatV>
-                                        <rotateFrame>0</rotateFrame>
-                                        <rotateUV>0</rotateUV>
-                                        <stagger>0</stagger>
-                                        <translateFrameU>0</translateFrameU>
-                                        <translateFrameV>0</translateFrameV>
-                                        <wrapU>1</wrapU>
-                                        <wrapV>1</wrapV>
-                                    </technique>
-                                </extra>
-                            </texture>
-                        </diffuse>
-                        <transparent opaque="RGB_ZERO">
-                            <color>0 0 0 1</color>
-                        </transparent>
-                        <transparency>
-                            <float>1</float>
-                        </transparency>
-                    </lambert>
-                </technique>
-            </profile_COMMON>
-        </effect>
-        <effect id="Paint1-fx">
-            <profile_COMMON>
-                <newparam sid="file25-surface">
-                    <surface type="2D">
-                        <init_from>file25</init_from>
-                    </surface>
-                </newparam>
-                <newparam sid="file25-sampler">
-                    <sampler2D>
-                        <source>file25-surface</source>
-                    </sampler2D>
-                </newparam>
-                <technique sid="common">
-                    <lambert>
-                        <emission>
-                            <color>0 0 0 1</color>
-                        </emission>
-                        <ambient>
-                            <color>0 0 0 1</color>
-                        </ambient>
-                        <diffuse>
-                            <texture texture="file25-sampler" texcoord="TEX0">
-                                <extra>
-                                    <technique profile="OpenCOLLADAMaya">
-                                        <blend_mode>NONE</blend_mode>
-                                        <coverageU>1</coverageU>
-                                        <coverageV>1</coverageV>
-                                        <fast>0</fast>
-                                        <mirrorU>0</mirrorU>
-                                        <mirrorV>0</mirrorV>
-                                        <noiseU>0</noiseU>
-                                        <noiseV>0</noiseV>
-                                        <offsetU>0</offsetU>
-                                        <offsetV>0</offsetV>
-                                        <repeatU>1</repeatU>
-                                        <repeatV>1</repeatV>
-                                        <rotateFrame>0</rotateFrame>
-                                        <rotateUV>0</rotateUV>
-                                        <stagger>0</stagger>
-                                        <translateFrameU>0</translateFrameU>
-                                        <translateFrameV>0</translateFrameV>
-                                        <wrapU>1</wrapU>
-                                        <wrapV>1</wrapV>
-                                    </technique>
-                                </extra>
-                            </texture>
-                        </diffuse>
-                        <transparent opaque="RGB_ZERO">
-                            <color>0 0 0 1</color>
-                        </transparent>
-                        <transparency>
-                            <float>1</float>
-                        </transparency>
-                    </lambert>
-                </technique>
-            </profile_COMMON>
-        </effect>
-        <effect id="Plastic-fx">
-            <profile_COMMON>
-                <newparam sid="file24-surface">
-                    <surface type="2D">
-                        <init_from>file24</init_from>
-                    </surface>
-                </newparam>
-                <newparam sid="file24-sampler">
-                    <sampler2D>
-                        <source>file24-surface</source>
-                    </sampler2D>
-                </newparam>
-                <technique sid="common">
-                    <lambert>
-                        <emission>
-                            <color>0 0 0 1</color>
-                        </emission>
-                        <ambient>
-                            <color>0 0 0 1</color>
-                        </ambient>
-                        <diffuse>
-                            <texture texture="file24-sampler" texcoord="TEX0">
-                                <extra>
-                                    <technique profile="OpenCOLLADAMaya">
-                                        <blend_mode>NONE</blend_mode>
-                                        <coverageU>1</coverageU>
-                                        <coverageV>1</coverageV>
-                                        <fast>0</fast>
-                                        <mirrorU>0</mirrorU>
-                                        <mirrorV>0</mirrorV>
-                                        <noiseU>0</noiseU>
-                                        <noiseV>0</noiseV>
-                                        <offsetU>0</offsetU>
-                                        <offsetV>0</offsetV>
-                                        <repeatU>1</repeatU>
-                                        <repeatV>1</repeatV>
-                                        <rotateFrame>0</rotateFrame>
-                                        <rotateUV>0</rotateUV>
-                                        <stagger>0</stagger>
-                                        <translateFrameU>0</translateFrameU>
-                                        <translateFrameV>0</translateFrameV>
-                                        <wrapU>1</wrapU>
-                                        <wrapV>1</wrapV>
-                                    </technique>
-                                </extra>
-                            </texture>
-                        </diffuse>
-                        <transparent opaque="RGB_ZERO">
-                            <color>0 0 0 1</color>
-                        </transparent>
-                        <transparency>
-                            <float>1</float>
-                        </transparency>
-                    </lambert>
-                </technique>
-            </profile_COMMON>
-        </effect>
-        <effect id="PlasticCenter-fx">
-            <profile_COMMON>
-                <newparam sid="file24-surface">
-                    <surface type="2D">
-                        <init_from>file24</init_from>
-                    </surface>
-                </newparam>
-                <newparam sid="file24-sampler">
-                    <sampler2D>
-                        <source>file24-surface</source>
-                    </sampler2D>
-                </newparam>
-                <technique sid="common">
-                    <lambert>
-                        <emission>
-                            <color>0 0 0 1</color>
-                        </emission>
-                        <ambient>
-                            <color>0 0 0 1</color>
-                        </ambient>
-                        <diffuse>
-                            <texture texture="file24-sampler" texcoord="TEX0">
-                                <extra>
-                                    <technique profile="OpenCOLLADAMaya">
-                                        <blend_mode>NONE</blend_mode>
-                                        <coverageU>1</coverageU>
-                                        <coverageV>1</coverageV>
-                                        <fast>0</fast>
-                                        <mirrorU>0</mirrorU>
-                                        <mirrorV>0</mirrorV>
-                                        <noiseU>0</noiseU>
-                                        <noiseV>0</noiseV>
-                                        <offsetU>0</offsetU>
-                                        <offsetV>0</offsetV>
-                                        <repeatU>1</repeatU>
-                                        <repeatV>1</repeatV>
-                                        <rotateFrame>0</rotateFrame>
-                                        <rotateUV>0</rotateUV>
-                                        <stagger>0</stagger>
-                                        <translateFrameU>0</translateFrameU>
-                                        <translateFrameV>0</translateFrameV>
-                                        <wrapU>1</wrapU>
-                                        <wrapV>1</wrapV>
-                                    </technique>
-                                </extra>
-                            </texture>
-                        </diffuse>
-                        <transparent opaque="RGB_ZERO">
-                            <color>0 0 0 1</color>
-                        </transparent>
-                        <transparency>
-                            <float>1</float>
-                        </transparency>
-                    </lambert>
-                </technique>
-            </profile_COMMON>
-        </effect>
-        <effect id="PlasticRed-fx">
-            <profile_COMMON>
-                <newparam sid="file23-surface">
-                    <surface type="2D">
-                        <init_from>file23</init_from>
-                    </surface>
-                </newparam>
-                <newparam sid="file23-sampler">
-                    <sampler2D>
-                        <source>file23-surface</source>
-                    </sampler2D>
-                </newparam>
-                <technique sid="common">
-                    <lambert>
-                        <emission>
-                            <color>0 0 0 1</color>
-                        </emission>
-                        <ambient>
-                            <color>0 0 0 1</color>
-                        </ambient>
-                        <diffuse>
-                            <texture texture="file23-sampler" texcoord="TEX0">
-                                <extra>
-                                    <technique profile="OpenCOLLADAMaya">
-                                        <blend_mode>NONE</blend_mode>
-                                        <coverageU>1</coverageU>
-                                        <coverageV>1</coverageV>
-                                        <fast>0</fast>
-                                        <mirrorU>0</mirrorU>
-                                        <mirrorV>0</mirrorV>
-                                        <noiseU>0</noiseU>
-                                        <noiseV>0</noiseV>
-                                        <offsetU>0</offsetU>
-                                        <offsetV>0</offsetV>
-                                        <repeatU>1</repeatU>
-                                        <repeatV>1</repeatV>
-                                        <rotateFrame>0</rotateFrame>
-                                        <rotateUV>0</rotateUV>
-                                        <stagger>0</stagger>
-                                        <translateFrameU>0</translateFrameU>
-                                        <translateFrameV>0</translateFrameV>
-                                        <wrapU>1</wrapU>
-                                        <wrapV>1</wrapV>
-                                    </technique>
-                                </extra>
-                            </texture>
-                        </diffuse>
-                        <transparent opaque="RGB_ZERO">
-                            <color>0 0 0 1</color>
-                        </transparent>
-                        <transparency>
-                            <float>1</float>
-                        </transparency>
-                    </lambert>
-                </technique>
-            </profile_COMMON>
-        </effect>
-        <effect id="lambert10-fx">
-            <profile_COMMON>
-                <newparam sid="file28-surface">
-                    <surface type="2D">
-                        <init_from>file28</init_from>
-                    </surface>
-                </newparam>
-                <newparam sid="file28-sampler">
-                    <sampler2D>
-                        <source>file28-surface</source>
-                    </sampler2D>
-                </newparam>
-                <technique sid="common">
-                    <lambert>
-                        <emission>
-                            <color>0 0 0 1</color>
-                        </emission>
-                        <ambient>
-                            <color>0 0 0 1</color>
-                        </ambient>
-                        <diffuse>
-                            <texture texture="file28-sampler" texcoord="TEX0">
-                                <extra>
-                                    <technique profile="OpenCOLLADAMaya">
-                                        <blend_mode>NONE</blend_mode>
-                                        <coverageU>1</coverageU>
-                                        <coverageV>1</coverageV>
-                                        <fast>0</fast>
-                                        <mirrorU>0</mirrorU>
-                                        <mirrorV>0</mirrorV>
-                                        <noiseU>0</noiseU>
-                                        <noiseV>0</noiseV>
-                                        <offsetU>0</offsetU>
-                                        <offsetV>0</offsetV>
-                                        <repeatU>1</repeatU>
-                                        <repeatV>1</repeatV>
-                                        <rotateFrame>0</rotateFrame>
-                                        <rotateUV>0</rotateUV>
-                                        <stagger>0</stagger>
-                                        <translateFrameU>0</translateFrameU>
-                                        <translateFrameV>0</translateFrameV>
-                                        <wrapU>1</wrapU>
-                                        <wrapV>1</wrapV>
-                                    </technique>
-                                </extra>
-                            </texture>
-                        </diffuse>
-                        <transparent opaque="RGB_ZERO">
-                            <color>0 0 0 1</color>
-                        </transparent>
-                        <transparency>
-                            <float>1</float>
-                        </transparency>
-                    </lambert>
-                </technique>
-            </profile_COMMON>
-        </effect>
-        <effect id="lambert11-fx">
-            <profile_COMMON>
-                <newparam sid="file29-surface">
-                    <surface type="2D">
-                        <init_from>file29</init_from>
-                    </surface>
-                </newparam>
-                <newparam sid="file29-sampler">
-                    <sampler2D>
-                        <source>file29-surface</source>
-                    </sampler2D>
-                </newparam>
-                <technique sid="common">
-                    <lambert>
-                        <emission>
-                            <color>0 0 0 1</color>
-                        </emission>
-                        <ambient>
-                            <color>0 0 0 1</color>
-                        </ambient>
-                        <diffuse>
-                            <texture texture="file29-sampler" texcoord="TEX0">
-                                <extra>
-                                    <technique profile="OpenCOLLADAMaya">
-                                        <blend_mode>NONE</blend_mode>
-                                        <coverageU>1</coverageU>
-                                        <coverageV>1</coverageV>
-                                        <fast>0</fast>
-                                        <mirrorU>0</mirrorU>
-                                        <mirrorV>0</mirrorV>
-                                        <noiseU>0</noiseU>
-                                        <noiseV>0</noiseV>
-                                        <offsetU>0</offsetU>
-                                        <offsetV>0</offsetV>
-                                        <repeatU>1</repeatU>
-                                        <repeatV>1</repeatV>
-                                        <rotateFrame>0</rotateFrame>
-                                        <rotateUV>0</rotateUV>
-                                        <stagger>0</stagger>
-                                        <translateFrameU>0</translateFrameU>
-                                        <translateFrameV>0</translateFrameV>
-                                        <wrapU>1</wrapU>
-                                        <wrapV>1</wrapV>
-                                    </technique>
-                                </extra>
-                            </texture>
-                        </diffuse>
-                        <transparent opaque="RGB_ZERO">
-                            <color>0 0 0 1</color>
-                        </transparent>
-                        <transparency>
-                            <float>1</float>
-                        </transparency>
-                    </lambert>
-                </technique>
-            </profile_COMMON>
-        </effect>
-        <effect id="lambert2-fx">
-            <profile_COMMON>
-                <newparam sid="file22-surface">
-                    <surface type="2D">
-                        <init_from>file22</init_from>
-                    </surface>
-                </newparam>
-                <newparam sid="file22-sampler">
-                    <sampler2D>
-                        <source>file22-surface</source>
-                    </sampler2D>
-                </newparam>
-                <technique sid="common">
-                    <lambert>
-                        <emission>
-                            <color>0 0 0 1</color>
-                        </emission>
-                        <ambient>
-                            <color>0 0 0 1</color>
-                        </ambient>
-                        <diffuse>
-                            <texture texture="file22-sampler" texcoord="TEX0">
-                                <extra>
-                                    <technique profile="OpenCOLLADAMaya">
-                                        <blend_mode>NONE</blend_mode>
-                                        <coverageU>1</coverageU>
-                                        <coverageV>1</coverageV>
-                                        <fast>0</fast>
-                                        <mirrorU>0</mirrorU>
-                                        <mirrorV>0</mirrorV>
-                                        <noiseU>0</noiseU>
-                                        <noiseV>0</noiseV>
-                                        <offsetU>0</offsetU>
-                                        <offsetV>0</offsetV>
-                                        <repeatU>1</repeatU>
-                                        <repeatV>1</repeatV>
-                                        <rotateFrame>0</rotateFrame>
-                                        <rotateUV>0</rotateUV>
-                                        <stagger>0</stagger>
-                                        <translateFrameU>0</translateFrameU>
-                                        <translateFrameV>0</translateFrameV>
-                                        <wrapU>1</wrapU>
-                                        <wrapV>1</wrapV>
-                                    </technique>
-                                </extra>
-                            </texture>
-                        </diffuse>
-                        <transparent opaque="RGB_ZERO">
-                            <color>0 0 0 1</color>
-                        </transparent>
-                        <transparency>
-                            <float>1</float>
-                        </transparency>
-                    </lambert>
-                </technique>
-            </profile_COMMON>
-        </effect>
-    </library_effects>
-    <library_images>
-        <image id="file29" name="file29" height="0" width="0">
-            <init_from>file:///Volumes/Android/Sanity/SceneGraph/assets/blue.jpg</init_from>
-            <extra>
-                <technique profile="OpenCOLLADAMaya">
-                    <dgnode_type>kFile</dgnode_type>
-                    <image_sequence>0</image_sequence>
-                    <originalMayaNodeId>file29</originalMayaNodeId>
-                </technique>
-            </extra>
-        </image>
-        <image id="file25" name="file25" height="0" width="0">
-            <init_from>file:///Volumes/Android/Sanity/SceneGraph/assets/carbonfiber.jpg</init_from>
-            <extra>
-                <technique profile="OpenCOLLADAMaya">
-                    <dgnode_type>kFile</dgnode_type>
-                    <image_sequence>0</image_sequence>
-                    <originalMayaNodeId>file25</originalMayaNodeId>
-                </technique>
-            </extra>
-        </image>
-        <image id="file28" name="file28" height="0" width="0">
-            <init_from>file:///Volumes/Android/Sanity/SceneGraph/assets/green.jpg</init_from>
-            <extra>
-                <technique profile="OpenCOLLADAMaya">
-                    <dgnode_type>kFile</dgnode_type>
-                    <image_sequence>0</image_sequence>
-                    <originalMayaNodeId>file28</originalMayaNodeId>
-                </technique>
-            </extra>
-        </image>
-        <image id="file22" name="file22" height="0" width="0">
-            <init_from>file:///Volumes/Android/Sanity/SceneGraph/assets/grey.jpg</init_from>
-            <extra>
-                <technique profile="OpenCOLLADAMaya">
-                    <dgnode_type>kFile</dgnode_type>
-                    <image_sequence>0</image_sequence>
-                    <originalMayaNodeId>file22</originalMayaNodeId>
-                </technique>
-            </extra>
-        </image>
-        <image id="file24" name="file24" height="0" width="0">
-            <init_from>file:///Volumes/Android/Sanity/SceneGraph/assets/orange.jpg</init_from>
-            <extra>
-                <technique profile="OpenCOLLADAMaya">
-                    <dgnode_type>kFile</dgnode_type>
-                    <image_sequence>0</image_sequence>
-                    <originalMayaNodeId>file24</originalMayaNodeId>
-                </technique>
-            </extra>
-        </image>
-        <image id="file23" name="file23" height="0" width="0">
-            <init_from>file:///Volumes/Android/Sanity/SceneGraph/assets/red.jpg</init_from>
-            <extra>
-                <technique profile="OpenCOLLADAMaya">
-                    <dgnode_type>kFile</dgnode_type>
-                    <image_sequence>0</image_sequence>
-                    <originalMayaNodeId>file23</originalMayaNodeId>
-                </technique>
-            </extra>
-        </image>
-    </library_images>
-    <library_visual_scenes>
-        <visual_scene id="VisualSceneNode" name="orientation_test">
-            <node id="camera1" name="camera1">
-                <translate sid="translate">24.5791 14.1321 31.4654</translate>
-                <rotate sid="rotateZ">0 0 1 0</rotate>
-                <rotate sid="rotateY">0 1 0 42</rotate>
-                <rotate sid="rotateX">1 0 0 -16.2</rotate>
-                <scale sid="scale">1 1 1</scale>
-                <instance_camera url="#cameraShape1" />
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>camera1</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="CameraAim" name="CameraAim">
-                <translate sid="translate">0.0209301 3.68542 2.06912</translate>
-                <rotate sid="rotateY">0 1 0 43.2561</rotate>
-                <rotate sid="rotateX">1 0 0 -20</rotate>
-                <scale sid="scale">1 1 1</scale>
-                <node id="CameraDist" name="CameraDist">
-                    <translate sid="translate">0 0 45</translate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_camera url="#CameraDistShape" />
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>CameraDist</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>CameraAim</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="pSphere4" name="pSphere4">
-                <translate sid="translate">-9.69237 0 7.70498</translate>
-                <scale sid="scale">1 1 1</scale>
-                <instance_geometry url="#pSphereShape4">
-                    <bind_material>
-                        <technique_common>
-                            <instance_material symbol="lambert7SG" target="#Paint1">
-                                <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                            </instance_material>
-                        </technique_common>
-                    </bind_material>
-                </instance_geometry>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>pSphere4</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="pSphere1" name="pSphere1">
-                <translate sid="translate">13.0966 0 5.76254</translate>
-                <scale sid="scale">1 1 1</scale>
-                <instance_geometry url="#pSphereShape1">
-                    <bind_material>
-                        <technique_common>
-                            <instance_material symbol="lambert7SG" target="#Paint1">
-                                <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                            </instance_material>
-                        </technique_common>
-                    </bind_material>
-                </instance_geometry>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>pSphere1</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="pSphere2" name="pSphere2">
-                <translate sid="translate">21.7661 0 -13.6375</translate>
-                <scale sid="scale">1 1 1</scale>
-                <instance_geometry url="#pSphereShape2">
-                    <bind_material>
-                        <technique_common>
-                            <instance_material symbol="lambert7SG" target="#Paint1">
-                                <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                            </instance_material>
-                        </technique_common>
-                    </bind_material>
-                </instance_geometry>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>pSphere2</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="pSphere3" name="pSphere3">
-                <translate sid="translate">-13.862 0 -13.6154</translate>
-                <scale sid="scale">1 1 1</scale>
-                <instance_geometry url="#pSphereShape3">
-                    <bind_material>
-                        <technique_common>
-                            <instance_material symbol="lambert7SG" target="#Paint1">
-                                <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                            </instance_material>
-                        </technique_common>
-                    </bind_material>
-                </instance_geometry>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>pSphere3</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="pSphere5" name="pSphere5">
-                <translate sid="translate">31.0862 0 18.5992</translate>
-                <scale sid="scale">1 1 1</scale>
-                <instance_geometry url="#pSphereShape5">
-                    <bind_material>
-                        <technique_common>
-                            <instance_material symbol="lambert7SG" target="#Paint1">
-                                <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                            </instance_material>
-                        </technique_common>
-                    </bind_material>
-                </instance_geometry>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>pSphere5</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="pCube1" name="pCube1">
-                <translate sid="translate">0 0 0</translate>
-                <scale sid="scale">1 1 1</scale>
-                <instance_geometry url="#pCubeShape1">
-                    <bind_material>
-                        <technique_common>
-                            <instance_material symbol="lambert4SG" target="#lambert2">
-                                <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                            </instance_material>
-                        </technique_common>
-                    </bind_material>
-                </instance_geometry>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>pCube1</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="group1" name="group1">
-                <translate sid="translate">0 0 0</translate>
-                <rotate sid="rotateZ">0 0 1 -162.693</rotate>
-                <rotate sid="rotateY">0 1 0 21.3345</rotate>
-                <rotate sid="rotateX">1 0 0 -100.567</rotate>
-                <scale sid="scale">1 1 1</scale>
-                <node id="pSphere6" name="pSphere6">
-                    <translate sid="translate">-13.862 0 -13.6154</translate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape6">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert6SG" target="#Plastic">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere6</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <node id="pSphere7" name="pSphere7">
-                    <translate sid="translate">-9.69237 0 7.70498</translate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape7">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert6SG" target="#Plastic">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere7</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <node id="pSphere8" name="pSphere8">
-                    <translate sid="translate">21.7661 0 -13.6375</translate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape8">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert6SG" target="#Plastic">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere8</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <node id="pSphere9" name="pSphere9">
-                    <translate sid="translate">13.0966 0 5.76254</translate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape9">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert6SG" target="#Plastic">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere9</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>group1</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="group2" name="group2">
-                <translate sid="translate">0 0 0</translate>
-                <rotate sid="rotateZ">0 0 1 45.4017</rotate>
-                <rotate sid="rotateY">0 1 0 79.393</rotate>
-                <rotate sid="rotateX">1 0 0 5.10889</rotate>
-                <scale sid="scale">1 1 1</scale>
-                <node id="pSphere10" name="pSphere10">
-                    <translate sid="translate">31.0862 0 18.5992</translate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape10">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert5SG" target="#Metal">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere10</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <node id="pSphere11" name="pSphere11">
-                    <translate sid="translate">13.0966 0 5.76254</translate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape11">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert5SG" target="#Metal">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere11</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <node id="pSphere12" name="pSphere12">
-                    <translate sid="translate">7.4784 16.3496 7.36882</translate>
-                    <rotate sid="rotateZ">0 0 1 17.3073</rotate>
-                    <rotate sid="rotateY">0 1 0 158.666</rotate>
-                    <rotate sid="rotateX">1 0 0 79.4335</rotate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape12">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert5SG" target="#Metal">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere12</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <node id="pSphere13" name="pSphere13">
-                    <translate sid="translate">-9.69237 0 7.70498</translate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape13">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert5SG" target="#Metal">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere13</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <node id="pSphere14" name="pSphere14">
-                    <translate sid="translate">11.3635 -4.3926 2.21012</translate>
-                    <rotate sid="rotateZ">0 0 1 17.3073</rotate>
-                    <rotate sid="rotateY">0 1 0 158.666</rotate>
-                    <rotate sid="rotateX">1 0 0 79.4335</rotate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape14">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert5SG" target="#Metal">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere14</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <node id="pSphere15" name="pSphere15">
-                    <translate sid="translate">21.7661 0 -13.6375</translate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape15">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert5SG" target="#Metal">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere15</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <node id="pSphere16" name="pSphere16">
-                    <translate sid="translate">-9.5945 -8.92317 -5.74901</translate>
-                    <rotate sid="rotateZ">0 0 1 17.3073</rotate>
-                    <rotate sid="rotateY">0 1 0 158.666</rotate>
-                    <rotate sid="rotateX">1 0 0 79.4335</rotate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape16">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert5SG" target="#Metal">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere16</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <node id="pSphere17" name="pSphere17">
-                    <translate sid="translate">-13.862 0 -13.6154</translate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape17">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert5SG" target="#Metal">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere17</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <node id="pSphere18" name="pSphere18">
-                    <translate sid="translate">-24.2135 6.497 -5.58935</translate>
-                    <rotate sid="rotateZ">0 0 1 17.3073</rotate>
-                    <rotate sid="rotateY">0 1 0 158.666</rotate>
-                    <rotate sid="rotateX">1 0 0 79.4335</rotate>
-                    <scale sid="scale">1 1 1</scale>
-                    <instance_geometry url="#pSphereShape18">
-                        <bind_material>
-                            <technique_common>
-                                <instance_material symbol="lambert5SG" target="#Metal">
-                                    <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                                </instance_material>
-                            </technique_common>
-                        </bind_material>
-                    </instance_geometry>
-                    <extra>
-                        <technique profile="OpenCOLLADAMaya">
-                            <originalMayaNodeId>pSphere18</originalMayaNodeId>
-                        </technique>
-                    </extra>
-                </node>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>group2</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="pCube2" name="pCube2">
-                <translate sid="translate">0 0 0</translate>
-                <scale sid="scale">1 1 1</scale>
-                <instance_geometry url="#pCubeShape2">
-                    <bind_material>
-                        <technique_common>
-                            <instance_material symbol="lambert8SG" target="#PlasticCenter">
-                                <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                            </instance_material>
-                        </technique_common>
-                    </bind_material>
-                </instance_geometry>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>pCube2</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="pCube3" name="pCube3">
-                <translate sid="translate">15 0 0</translate>
-                <scale sid="scale">1 1 1</scale>
-                <instance_geometry url="#pCubeShape3">
-                    <bind_material>
-                        <technique_common>
-                            <instance_material symbol="lambert9SG" target="#PlasticRed">
-                                <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                            </instance_material>
-                        </technique_common>
-                    </bind_material>
-                </instance_geometry>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>pCube3</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="pCube4" name="pCube4">
-                <translate sid="translate">0 15 0</translate>
-                <scale sid="scale">1 1 1</scale>
-                <instance_geometry url="#pCubeShape4">
-                    <bind_material>
-                        <technique_common>
-                            <instance_material symbol="lambert10SG" target="#lambert10">
-                                <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                            </instance_material>
-                        </technique_common>
-                    </bind_material>
-                </instance_geometry>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>pCube4</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-            <node id="pCube5" name="pCube5">
-                <translate sid="translate">0 0 15</translate>
-                <scale sid="scale">1 1 1</scale>
-                <instance_geometry url="#pCubeShape5">
-                    <bind_material>
-                        <technique_common>
-                            <instance_material symbol="lambert11SG" target="#lambert11">
-                                <bind_vertex_input semantic="TEX0" input_semantic="TEXCOORD" input_set="0" />
-                            </instance_material>
-                        </technique_common>
-                    </bind_material>
-                </instance_geometry>
-                <extra>
-                    <technique profile="OpenCOLLADAMaya">
-                        <originalMayaNodeId>pCube5</originalMayaNodeId>
-                    </technique>
-                </extra>
-            </node>
-        </visual_scene>
-    </library_visual_scenes>
-    <scene>
-        <instance_visual_scene url="#VisualSceneNode" />
-    </scene>
-</COLLADA>
diff --git a/tests/RenderScriptTests/SceneGraph/assets/paint.jpg b/tests/RenderScriptTests/SceneGraph/assets/paint.jpg
deleted file mode 100644
index 0791045..0000000
--- a/tests/RenderScriptTests/SceneGraph/assets/paint.jpg
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/SceneGraph/assets/red.jpg b/tests/RenderScriptTests/SceneGraph/assets/red.jpg
deleted file mode 100644
index 320a2a6..0000000
--- a/tests/RenderScriptTests/SceneGraph/assets/red.jpg
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/SceneGraph/res/drawable-nodpi/icon.png b/tests/RenderScriptTests/SceneGraph/res/drawable-nodpi/icon.png
deleted file mode 100644
index ff34a7f..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/drawable-nodpi/icon.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/SceneGraph/res/drawable-nodpi/robot.png b/tests/RenderScriptTests/SceneGraph/res/drawable-nodpi/robot.png
deleted file mode 100644
index f7353fd..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/drawable-nodpi/robot.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/SceneGraph/res/menu/loader_menu.xml b/tests/RenderScriptTests/SceneGraph/res/menu/loader_menu.xml
deleted file mode 100644
index 9ea30107..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/menu/loader_menu.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-* Copyright (C) 2011 The Android Open Source Project
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
--->
-
-<menu xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:id="@+id/load_model"
-          android:title="@string/load_model" />
-    <item android:id="@+id/use_blur"
-          android:title="@string/use_blur" />
-</menu>
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/blur_h.glsl b/tests/RenderScriptTests/SceneGraph/res/raw/blur_h.glsl
deleted file mode 100644
index c34adc9..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/blur_h.glsl
+++ /dev/null
@@ -1,15 +0,0 @@
-varying vec2 varTex0;
-
-void main() {
-   vec2 blurCoord = varTex0;
-   blurCoord.x = varTex0.x + UNI_blurOffset0;
-   vec3 col = texture2D(UNI_color, blurCoord).rgb;
-   blurCoord.x = varTex0.x + UNI_blurOffset1;
-   col += texture2D(UNI_color, blurCoord).rgb;
-   blurCoord.x = varTex0.x + UNI_blurOffset2;
-   col += texture2D(UNI_color, blurCoord).rgb;
-   blurCoord.x = varTex0.x + UNI_blurOffset3;
-   col += texture2D(UNI_color, blurCoord).rgb;
-
-   gl_FragColor = vec4(col * 0.25, 0.0);
-}
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/blur_v.glsl b/tests/RenderScriptTests/SceneGraph/res/raw/blur_v.glsl
deleted file mode 100644
index ade05a2..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/blur_v.glsl
+++ /dev/null
@@ -1,17 +0,0 @@
-varying vec2 varTex0;
-
-void main() {
-   vec2 blurCoord = varTex0;
-   blurCoord.y = varTex0.y + UNI_blurOffset0;
-   vec3 col = texture2D(UNI_color, blurCoord).rgb;
-   blurCoord.y = varTex0.y + UNI_blurOffset1;
-   col += texture2D(UNI_color, blurCoord).rgb;
-   blurCoord.y = varTex0.y + UNI_blurOffset2;
-   col += texture2D(UNI_color, blurCoord).rgb;
-   blurCoord.y = varTex0.y + UNI_blurOffset3;
-   col += texture2D(UNI_color, blurCoord).rgb;
-
-   col = col * 0.25;
-
-   gl_FragColor = vec4(col, 0.0);
-}
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/blur_vertex.glsl b/tests/RenderScriptTests/SceneGraph/res/raw/blur_vertex.glsl
deleted file mode 100644
index bc824b6..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/blur_vertex.glsl
+++ /dev/null
@@ -1,7 +0,0 @@
-varying vec2 varTex0;
-
-void main() {
-   gl_Position = ATTRIB_position;
-   varTex0 = ATTRIB_texture0;
-}
-
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/diffuse.glsl b/tests/RenderScriptTests/SceneGraph/res/raw/diffuse.glsl
deleted file mode 100644
index 2eb1028..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/diffuse.glsl
+++ /dev/null
@@ -1,19 +0,0 @@
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-void main() {
-
-   vec3 V = normalize(UNI_cameraPos.xyz - varWorldPos.xyz);
-   vec3 worldNorm = (varWorldNormal);
-
-   vec3 light0Vec = V;
-   vec3 light0R = reflect(light0Vec, worldNorm);
-   float light0_Diffuse = dot(worldNorm, light0Vec);
-
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col = texture2D(UNI_diffuse, t0).rgba;
-   col.xyz = col.xyz * light0_Diffuse * 1.2;
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/diffuse_lights.glsl b/tests/RenderScriptTests/SceneGraph/res/raw/diffuse_lights.glsl
deleted file mode 100644
index ef93e1c..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/diffuse_lights.glsl
+++ /dev/null
@@ -1,22 +0,0 @@
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-void main() {
-
-   vec3 V = normalize(UNI_cameraPos.xyz - varWorldPos.xyz);
-   vec3 worldNorm = normalize(varWorldNormal);
-
-   vec3 light0Vec = normalize(UNI_lightPos_0.xyz - varWorldPos.xyz);
-   float light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0);
-
-   vec3 light1Vec = normalize(UNI_lightPos_1.xyz - varWorldPos.xyz);
-   float light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0);
-
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col = UNI_diffuse;
-   col.xyz = col.xyz * (light0_Diffuse * UNI_lightColor_0.xyz +
-                        light1_Diffuse * UNI_lightColor_1.xyz);
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/metal.glsl b/tests/RenderScriptTests/SceneGraph/res/raw/metal.glsl
deleted file mode 100644
index b90a7b2..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/metal.glsl
+++ /dev/null
@@ -1,23 +0,0 @@
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-void main() {
-
-   vec3 V = normalize(UNI_cameraPos.xyz - varWorldPos.xyz);
-   vec3 worldNorm = normalize(varWorldNormal);
-
-   vec3 light0Vec = V;
-   vec3 light0R = reflect(light0Vec, worldNorm);
-   float light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0);
-   float light0Spec = clamp(dot(-light0R, V), 0.001, 1.0);
-   float light0_Specular = pow(light0Spec, 15.0) * 0.5;
-
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col = texture2D(UNI_diffuse, t0).rgba;
-   col.xyz = col.xyz * (textureCube(UNI_reflection, worldNorm).rgb * 0.5 + vec3(light0_Diffuse));
-   col.xyz += light0_Specular * vec3(0.8, 0.8, 1.0);
-
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/paintf.glsl b/tests/RenderScriptTests/SceneGraph/res/raw/paintf.glsl
deleted file mode 100644
index f3b89ed..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/paintf.glsl
+++ /dev/null
@@ -1,26 +0,0 @@
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-void main() {
-
-   vec3 V = normalize(UNI_cameraPos.xyz - varWorldPos.xyz);
-   vec3 worldNorm = normalize(varWorldNormal);
-
-   vec3 light0Vec = V;
-   vec3 light0R = reflect(light0Vec, worldNorm);
-   float light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.01, 0.99);
-   float light0Spec = clamp(dot(-light0R, V), 0.001, 1.0);
-   float light0_Specular = pow(light0Spec, 150.0) * 0.5;
-
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col = texture2D(UNI_diffuse, t0).rgba;
-   col.xyz = col.xyz * light0_Diffuse * 1.1;
-   col.xyz += light0_Specular * vec3(0.8, 0.8, 1.0);
-
-   float fresnel = mix(pow(1.0 - light0_Diffuse, 15.0), 1.0, 0.1);
-   col.xyz = mix(col.xyz, textureCube(UNI_reflection, -light0R).rgb * 2.4, fresnel);
-   col.w = 0.8;
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/plastic.glsl b/tests/RenderScriptTests/SceneGraph/res/raw/plastic.glsl
deleted file mode 100644
index 56f7151f..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/plastic.glsl
+++ /dev/null
@@ -1,22 +0,0 @@
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-void main() {
-
-   vec3 V = normalize(UNI_cameraPos.xyz - varWorldPos.xyz);
-   vec3 worldNorm = normalize(varWorldNormal);
-
-   vec3 light0Vec = V;
-   vec3 light0R = reflect(light0Vec, worldNorm);
-   float light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0);
-   float light0Spec = clamp(dot(-light0R, V), 0.001, 1.0);
-   float light0_Specular = pow(light0Spec, 10.0) * 0.5;
-
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col = texture2D(UNI_diffuse, t0).rgba;
-   col.xyz = col.xyz * light0_Diffuse * 1.2;
-   col.xyz += light0_Specular * vec3(0.8, 0.8, 1.0);
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/plastic_lights.glsl b/tests/RenderScriptTests/SceneGraph/res/raw/plastic_lights.glsl
deleted file mode 100644
index b253622..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/plastic_lights.glsl
+++ /dev/null
@@ -1,29 +0,0 @@
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-void main() {
-
-   vec3 V = normalize(UNI_cameraPos.xyz - varWorldPos.xyz);
-   vec3 worldNorm = normalize(varWorldNormal);
-
-   vec3 light0Vec = normalize(UNI_lightPos_0.xyz - varWorldPos.xyz);
-   vec3 light0R = reflect(light0Vec, worldNorm);
-   float light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0);
-   float light0Spec = clamp(dot(-light0R, V), 0.001, 1.0);
-   float light0_Specular = pow(light0Spec, 10.0) * 0.7;
-
-   vec3 light1Vec = normalize(UNI_lightPos_1.xyz - varWorldPos.xyz);
-   vec3 light1R = reflect(light1Vec, worldNorm);
-   float light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0);
-   float light1Spec = clamp(dot(-light1R, V), 0.001, 1.0);
-   float light1_Specular = pow(light1Spec, 10.0) * 0.7;
-
-   vec2 t0 = varTex0.xy;
-   lowp vec4 col = UNI_diffuse;
-   col.xyz = col.xyz * (light0_Diffuse * UNI_lightColor_0.xyz +
-                        light1_Diffuse * UNI_lightColor_1.xyz);
-   col.xyz += (light0_Specular + light1_Specular);
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/robot.a3d b/tests/RenderScriptTests/SceneGraph/res/raw/robot.a3d
deleted file mode 100644
index f48895c..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/robot.a3d
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/select_color.glsl b/tests/RenderScriptTests/SceneGraph/res/raw/select_color.glsl
deleted file mode 100644
index 1a927ca..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/select_color.glsl
+++ /dev/null
@@ -1,13 +0,0 @@
-varying vec2 varTex0;
-
-void main() {
-   vec3 col = texture2D(UNI_color, varTex0).rgb;
-
-   vec3 desat = vec3(0.299, 0.587, 0.114);
-   float lum = dot(desat, col);
-   float stepVal = step(lum, 0.8);
-   col = mix(col, vec3(0.0), stepVal)*0.5;
-
-   gl_FragColor = vec4(col, 0.0);
-}
-
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/shader2v.glsl b/tests/RenderScriptTests/SceneGraph/res/raw/shader2v.glsl
deleted file mode 100644
index 7910a54..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/shader2v.glsl
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
-    rs_matrix4x4 model;
-    rs_matrix4x4 viewProj;
-*/
-
-varying vec3 varWorldPos;
-varying vec3 varWorldNormal;
-varying vec2 varTex0;
-
-// This is where actual shader code begins
-void main() {
-   vec4 objPos = ATTRIB_position;
-   vec4 worldPos = UNI_model * objPos;
-   gl_Position = UNI_viewProj * worldPos;
-
-   mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
-   vec3 worldNorm = model3 * ATTRIB_normal;
-
-   varWorldPos = worldPos.xyz;
-   varWorldNormal = worldNorm;
-   varTex0 = ATTRIB_texture0;
-}
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/texture.glsl b/tests/RenderScriptTests/SceneGraph/res/raw/texture.glsl
deleted file mode 100644
index 662ecd8..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/texture.glsl
+++ /dev/null
@@ -1,7 +0,0 @@
-varying vec2 varTex0;
-
-void main() {
-   lowp vec4 col = texture2D(UNI_color, varTex0).rgba;
-   gl_FragColor = col;
-}
-
diff --git a/tests/RenderScriptTests/SceneGraph/res/raw/unit_obj.a3d b/tests/RenderScriptTests/SceneGraph/res/raw/unit_obj.a3d
deleted file mode 100644
index 56eff04..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/raw/unit_obj.a3d
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/SceneGraph/res/values/strings.xml b/tests/RenderScriptTests/SceneGraph/res/values/strings.xml
deleted file mode 100644
index c916d79..0000000
--- a/tests/RenderScriptTests/SceneGraph/res/values/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-* Copyright (C) 2011 The Android Open Source Project
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
--->
-
-<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <skip />
-    <string name="load_model">Load Model</string>
-    <string name="use_blur">Use Blur</string>
-</resources>
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java
deleted file mode 100644
index 42f2be5..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import com.android.scenegraph.SceneManager;
-
-import android.renderscript.*;
-import android.renderscript.Matrix4f;
-import android.renderscript.RenderScriptGL;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class Camera extends SceneGraphBase {
-
-    Transform mTransform;
-
-    ScriptField_Camera_s.Item mData;
-    ScriptField_Camera_s mField;
-
-    public Camera() {
-        mData = new ScriptField_Camera_s.Item();
-        mData.near = 0.1f;
-        mData.far = 1000.0f;
-        mData.horizontalFOV = 60.0f;
-        mData.aspect = 0;
-    }
-
-    public void setTransform(Transform t) {
-        mTransform = t;
-        if (mField != null) {
-            mField.set_transformMatrix(0, mTransform.getRSData().getAllocation(), true);
-            mField.set_isDirty(0, 1, true);
-        }
-    }
-    public void setFOV(float fov) {
-        mData.horizontalFOV = fov;
-        if (mField != null) {
-            mField.set_horizontalFOV(0, fov, true);
-            mField.set_isDirty(0, 1, true);
-        }
-    }
-
-    public void setNear(float n) {
-        mData.near = n;
-        if (mField != null) {
-            mField.set_near(0, n, true);
-            mField.set_isDirty(0, 1, true);
-        }
-    }
-
-    public void setFar(float f) {
-        mData.far = f;
-        if (mField != null) {
-            mField.set_far(0, f, true);
-            mField.set_isDirty(0, 1, true);
-        }
-    }
-
-    public void setName(String n) {
-        super.setName(n);
-        if (mField != null) {
-            RenderScriptGL rs = SceneManager.getRS();
-            mData.name = getNameAlloc(rs);
-            mField.set_name(0, mData.name, true);
-            mField.set_isDirty(0, 1, true);
-        }
-    }
-
-    ScriptField_Camera_s getRSData() {
-        if (mField != null) {
-            return mField;
-        }
-
-        RenderScriptGL rs = SceneManager.getRS();
-        if (rs == null) {
-            return null;
-        }
-
-        if (mTransform == null) {
-            throw new RuntimeException("Cameras without transforms are invalid");
-        }
-
-        mField = new ScriptField_Camera_s(rs, 1);
-
-        mData.transformMatrix = mTransform.getRSData().getAllocation();
-        mData.transformTimestamp = 1;
-        mData.timestamp = 1;
-        mData.isDirty = 1;
-        mData.name = getNameAlloc(rs);
-        mField.set(mData, 0, true);
-
-        return mField;
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaParser.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaParser.java
deleted file mode 100644
index b4b6fb9..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaParser.java
+++ /dev/null
@@ -1,563 +0,0 @@
-/*

- * Copyright (C) 2011 The Android Open Source Project

- *

- * Licensed under the Apache License, Version 2.0 (the "License");

- * you may not use this file except in compliance with the License.

- * You may obtain a copy of the License at

- *

- *      http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing, software

- * distributed under the License is distributed on an "AS IS" BASIS,

- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- * See the License for the specific language governing permissions and

- * limitations under the License.

- */

-

-package com.android.scenegraph;

-import com.android.scenegraph.CompoundTransform.TranslateComponent;

-import com.android.scenegraph.CompoundTransform.RotateComponent;

-import com.android.scenegraph.CompoundTransform.ScaleComponent;

-import java.io.IOException;

-import java.io.InputStream;

-import java.util.ArrayList;

-import java.util.Iterator;

-import java.util.List;

-import java.util.StringTokenizer;

-import java.util.HashMap;

-

-import javax.xml.parsers.DocumentBuilder;

-import javax.xml.parsers.DocumentBuilderFactory;

-import javax.xml.parsers.ParserConfigurationException;

-

-import org.w3c.dom.Document;

-import org.w3c.dom.Element;

-import org.w3c.dom.Node;

-import org.w3c.dom.NodeList;

-import org.xml.sax.SAXException;

-

-import android.renderscript.*;

-import android.util.Log;

-

-public class ColladaParser {

-    static final String TAG = "ColladaParser";

-    Document mDom;

-

-    HashMap<String, LightBase> mLights;

-    HashMap<String, Camera> mCameras;

-    HashMap<String, ArrayList<ShaderParam> > mEffectsParams;

-    HashMap<String, Texture2D> mImages;

-    HashMap<String, Texture2D> mSamplerImageMap;

-    HashMap<String, String> mMeshIdNameMap;

-    Scene mScene;

-

-    String mRootDir;

-

-    String toString(Float3 v) {

-        String valueStr = v.x + " " + v.y + " " + v.z;

-        return valueStr;

-    }

-

-    String toString(Float4 v) {

-        String valueStr = v.x + " " + v.y + " " + v.z + " " + v.w;

-        return valueStr;

-    }

-

-    public ColladaParser(){

-        mLights = new HashMap<String, LightBase>();

-        mCameras = new HashMap<String, Camera>();

-        mEffectsParams = new HashMap<String, ArrayList<ShaderParam> >();

-        mImages = new HashMap<String, Texture2D>();

-        mMeshIdNameMap = new HashMap<String, String>();

-    }

-

-    public void init(InputStream is, String rootDir) {

-        mLights.clear();

-        mCameras.clear();

-        mEffectsParams.clear();

-

-        mRootDir = rootDir;

-

-        long start = System.currentTimeMillis();

-        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

-        try {

-            DocumentBuilder db = dbf.newDocumentBuilder();

-            mDom = db.parse(is);

-        } catch(ParserConfigurationException e) {

-            e.printStackTrace();

-        } catch(SAXException e) {

-            e.printStackTrace();

-        } catch(IOException e) {

-            e.printStackTrace();

-        }

-        long end = System.currentTimeMillis();

-        Log.v("TIMER", "    Parse time: " + (end - start));

-        exportSceneData();

-    }

-

-    Scene getScene() {

-        return mScene;

-    }

-

-    private void exportSceneData(){

-        mScene = new Scene();

-

-        Element docEle = mDom.getDocumentElement();

-        NodeList nl = docEle.getElementsByTagName("light");

-        if (nl != null) {

-            for(int i = 0; i < nl.getLength(); i++) {

-                Element l = (Element)nl.item(i);

-                convertLight(l);

-            }

-        }

-

-        nl = docEle.getElementsByTagName("camera");

-        if (nl != null) {

-            for(int i = 0; i < nl.getLength(); i++) {

-                Element c = (Element)nl.item(i);

-                convertCamera(c);

-            }

-        }

-

-        nl = docEle.getElementsByTagName("image");

-        if (nl != null) {

-            for(int i = 0; i < nl.getLength(); i++) {

-                Element img = (Element)nl.item(i);

-                convertImage(img);

-            }

-        }

-

-        nl = docEle.getElementsByTagName("effect");

-        if (nl != null) {

-            for(int i = 0; i < nl.getLength(); i++) {

-                Element e = (Element)nl.item(i);

-                convertEffects(e);

-            }

-        }

-

-        // Material is just a link to the effect

-        nl = docEle.getElementsByTagName("material");

-        if (nl != null) {

-            for(int i = 0; i < nl.getLength(); i++) {

-                Element m = (Element)nl.item(i);

-                convertMaterials(m);

-            }

-        }

-

-        // Look through the geometry list and build up a correlation between id's and names

-        nl = docEle.getElementsByTagName("geometry");

-        if (nl != null) {

-            for(int i = 0; i < nl.getLength(); i++) {

-                Element m = (Element)nl.item(i);

-                convertGeometries(m);

-            }

-        }

-

-

-        nl = docEle.getElementsByTagName("visual_scene");

-        if (nl != null) {

-            for(int i = 0; i < nl.getLength(); i++) {

-                Element s = (Element)nl.item(i);

-                getScene(s);

-            }

-        }

-    }

-

-    private void getRenderable(Element shape, Transform t) {

-        String geoURL = shape.getAttribute("url").substring(1);

-        String geoName = mMeshIdNameMap.get(geoURL);

-        if (geoName != null) {

-            geoURL = geoName;

-        }

-        //RenderableGroup group = new RenderableGroup();

-        //group.setName(geoURL.substring(1));

-        //mScene.appendRenderable(group);

-        NodeList nl = shape.getElementsByTagName("instance_material");

-        if (nl != null) {

-            for(int i = 0; i < nl.getLength(); i++) {

-                Element materialRef = (Element)nl.item(i);

-                String meshIndexName = materialRef.getAttribute("symbol");

-                String materialName = materialRef.getAttribute("target");

-

-                Renderable d = new Renderable();

-                d.setMesh(geoURL, meshIndexName);

-                d.setMaterialName(materialName.substring(1));

-                d.setName(geoURL);

-

-                //Log.v(TAG, "Created drawable geo " + geoURL + " index " + meshIndexName + " material " + materialName);

-

-                d.setTransform(t);

-                //Log.v(TAG, "Set source param " + t.getName());

-

-                // Now find all the parameters that exist on the material

-                ArrayList<ShaderParam> materialParams;

-                materialParams = mEffectsParams.get(materialName.substring(1));

-                for (int pI = 0; pI < materialParams.size(); pI ++) {

-                    d.appendSourceParams(materialParams.get(pI));

-                    //Log.v(TAG, "Set source param i: " + pI + " name " + materialParams.get(pI).getParamName());

-                }

-                mScene.appendRenderable(d);

-                //group.appendChildren(d);

-            }

-        }

-    }

-

-    private void updateLight(Element shape, Transform t) {

-        String lightURL = shape.getAttribute("url");

-        // collada uses a uri structure to link things,

-        // but we ignore it for now and do a simple search

-        LightBase light = mLights.get(lightURL.substring(1));

-        if (light != null) {

-            light.setTransform(t);

-            //Log.v(TAG, "Set Light " + light.getName() + " " + t.getName());

-        }

-    }

-

-    private void updateCamera(Element shape, Transform t) {

-        String camURL = shape.getAttribute("url");

-        // collada uses a uri structure to link things,

-        // but we ignore it for now and do a simple search

-        Camera cam = mCameras.get(camURL.substring(1));

-        if (cam != null) {

-            cam.setTransform(t);

-            //Log.v(TAG, "Set Camera " + cam.getName() + " " + t.getName());

-        }

-    }

-

-    private void getNode(Element node, Transform parent, String indent) {

-        String name = node.getAttribute("name");

-        String id = node.getAttribute("id");

-        CompoundTransform current = new CompoundTransform();

-        current.setName(name);

-        if (parent != null) {

-            parent.appendChild(current);

-        } else {

-            mScene.appendTransform(current);

-        }

-

-        mScene.addToTransformMap(current);

-

-        //Log.v(TAG, indent + "|");

-        //Log.v(TAG, indent + "[" + name + "]");

-

-        Node childNode = node.getFirstChild();

-        while (childNode != null) {

-            if (childNode.getNodeType() == Node.ELEMENT_NODE) {

-                Element field = (Element)childNode;

-                String fieldName = field.getTagName();

-                String description = field.getAttribute("sid");

-                if (fieldName.equals("translate")) {

-                    Float3 value = getFloat3(field);

-                    current.addTranslate(description, value);

-                    //Log.v(TAG, indent + " translate " + description + toString(value));

-                } else if (fieldName.equals("rotate")) {

-                    Float4 value = getFloat4(field);

-                    //Log.v(TAG, indent + " rotate " + description + toString(value));

-                    Float3 axis = new Float3(value.x, value.y, value.z);

-                    current.addRotate(description, axis, value.w);

-                } else if (fieldName.equals("scale")) {

-                    Float3 value = getFloat3(field);

-                    //Log.v(TAG, indent + " scale " + description + toString(value));

-                    current.addScale(description, value);

-                } else if (fieldName.equals("instance_geometry")) {

-                    getRenderable(field, current);

-                } else if (fieldName.equals("instance_light")) {

-                    updateLight(field, current);

-                } else if (fieldName.equals("instance_camera")) {

-                    updateCamera(field, current);

-                } else if (fieldName.equals("node")) {

-                    getNode(field, current, indent + "   ");

-                }

-            }

-            childNode = childNode.getNextSibling();

-        }

-    }

-

-    // This will find the actual texture node, which is sometimes hidden behind a sampler

-    // and sometimes referenced directly

-    Texture2D getTexture(String samplerName) {

-        String texName = samplerName;

-

-        // Check to see if the image file is hidden by a sampler surface link combo

-        Element sampler = mDom.getElementById(samplerName);

-        if (sampler != null) {

-            NodeList nl = sampler.getElementsByTagName("source");

-            if (nl != null && nl.getLength() == 1) {

-                Element ref = (Element)nl.item(0);

-                String surfaceName = getString(ref);

-                if (surfaceName == null) {

-                    return null;

-                }

-

-                Element surface = mDom.getElementById(surfaceName);

-                if (surface == null) {

-                    return null;

-                }

-                nl = surface.getElementsByTagName("init_from");

-                if (nl != null && nl.getLength() == 1) {

-                    ref = (Element)nl.item(0);

-                    texName = getString(ref);

-                }

-            }

-        }

-

-        //Log.v(TAG, "Extracted texture name " + texName);

-        return mImages.get(texName);

-    }

-

-    void extractParams(Element fx, ArrayList<ShaderParam> params) {

-        Node paramNode = fx.getFirstChild();

-        while (paramNode != null) {

-            if (paramNode.getNodeType() == Node.ELEMENT_NODE) {

-                String name = paramNode.getNodeName();

-                // Now find what type it is

-                Node typeNode = paramNode.getFirstChild();

-                while (typeNode != null && typeNode.getNodeType() != Node.ELEMENT_NODE) {

-                    typeNode = typeNode.getNextSibling();

-                }

-                String paramType = typeNode.getNodeName();

-                Element typeElem = (Element)typeNode;

-                ShaderParam sceneParam = null;

-                if (paramType.equals("color")) {

-                    Float4Param f4p = new Float4Param(name);

-                    Float4 value = getFloat4(typeElem);

-                    f4p.setValue(value);

-                    sceneParam = f4p;

-                    //Log.v(TAG, "Extracted " + sceneParam.getParamName() + " value " + toString(value));

-                } else if (paramType.equals("float")) {

-                    Float4Param f4p = new Float4Param(name);

-                    float value = getFloat(typeElem);

-                    f4p.setValue(new Float4(value, value, value, value));

-                    sceneParam = f4p;

-                    //Log.v(TAG, "Extracted " + sceneParam.getParamName() + " value " + value);

-                }  else if (paramType.equals("texture")) {

-                    String samplerName = typeElem.getAttribute("texture");

-                    Texture2D tex = getTexture(samplerName);

-                    TextureParam texP = new TextureParam(name);

-                    texP.setTexture(tex);

-                    sceneParam = texP;

-                    //Log.v(TAG, "Extracted texture " + tex);

-                }

-                if (sceneParam != null) {

-                    params.add(sceneParam);

-                }

-            }

-            paramNode = paramNode.getNextSibling();

-        }

-    }

-

-    private void convertMaterials(Element mat) {

-        String id = mat.getAttribute("id");

-        NodeList nl = mat.getElementsByTagName("instance_effect");

-        if (nl != null && nl.getLength() == 1) {

-            Element ref = (Element)nl.item(0);

-            String url = ref.getAttribute("url");

-            ArrayList<ShaderParam> params = mEffectsParams.get(url.substring(1));

-            mEffectsParams.put(id, params);

-        }

-    }

-

-    private void convertGeometries(Element geo) {

-        String id = geo.getAttribute("id");

-        String name = geo.getAttribute("name");

-        if (!id.equals(name)) {

-            mMeshIdNameMap.put(id, name);

-        }

-    }

-

-    private void convertEffects(Element fx) {

-        String id = fx.getAttribute("id");

-        ArrayList<ShaderParam> params = new ArrayList<ShaderParam>();

-

-        NodeList nl = fx.getElementsByTagName("newparam");

-        if (nl != null) {

-            for(int i = 0; i < nl.getLength(); i++) {

-                Element field = (Element)nl.item(i);

-                field.setIdAttribute("sid", true);

-            }

-        }

-

-        nl = fx.getElementsByTagName("blinn");

-        if (nl != null) {

-            for(int i = 0; i < nl.getLength(); i++) {

-                Element field = (Element)nl.item(i);

-                //Log.v(TAG, "blinn");

-                extractParams(field, params);

-            }

-        }

-        nl = fx.getElementsByTagName("lambert");

-        if (nl != null) {

-            for(int i = 0; i < nl.getLength(); i++) {

-                Element field = (Element)nl.item(i);

-                //Log.v(TAG, "lambert");

-                extractParams(field, params);

-            }

-        }

-        nl = fx.getElementsByTagName("phong");

-        if (nl != null) {

-            for(int i = 0; i < nl.getLength(); i++) {

-                Element field = (Element)nl.item(i);

-                //Log.v(TAG, "phong");

-                extractParams(field, params);

-            }

-        }

-        mEffectsParams.put(id, params);

-    }

-

-    private void convertLight(Element light) {

-        String name = light.getAttribute("name");

-        String id = light.getAttribute("id");

-

-        // Determine type

-        String[] knownTypes = { "point", "spot", "directional" };

-        final int POINT_LIGHT = 0;

-        final int SPOT_LIGHT = 1;

-        final int DIR_LIGHT = 2;

-        int type = -1;

-        for (int i = 0; i < knownTypes.length; i ++) {

-            NodeList nl = light.getElementsByTagName(knownTypes[i]);

-            if (nl != null && nl.getLength() != 0) {

-                type = i;

-                break;

-            }

-        }

-

-        //Log.v(TAG, "Found Light Type " + type);

-

-        LightBase sceneLight = null;

-        switch (type) {

-        case POINT_LIGHT:

-            sceneLight = new PointLight();

-            break;

-        case SPOT_LIGHT: // TODO: finish light types

-            break;

-        case DIR_LIGHT: // TODO: finish light types

-            break;

-        }

-

-        if (sceneLight == null) {

-            return;

-        }

-

-        Float3 color = getFloat3(light, "color");

-        sceneLight.setColor(color.x, color.y, color.z);

-        sceneLight.setName(name);

-        mScene.appendLight(sceneLight);

-        mLights.put(id, sceneLight);

-

-        //Log.v(TAG, "Light " + name + " color " + toString(color));

-    }

-

-    private void convertCamera(Element camera) {

-        String name = camera.getAttribute("name");

-        String id = camera.getAttribute("id");

-        float fov = 30.0f;

-        if (getString(camera, "yfov") != null) {

-            fov = getFloat(camera, "yfov");

-        } else if(getString(camera, "xfov") != null) {

-            float aspect = getFloat(camera, "aspect_ratio");

-            fov = getFloat(camera, "xfov") / aspect;

-        }

-

-        float near = getFloat(camera, "znear");

-        float far = getFloat(camera, "zfar");

-

-        Camera sceneCamera = new Camera();

-        sceneCamera.setFOV(fov);

-        sceneCamera.setNear(near);

-        sceneCamera.setFar(far);

-        sceneCamera.setName(name);

-        mScene.appendCamera(sceneCamera);

-        mCameras.put(id, sceneCamera);

-    }

-

-    private void convertImage(Element img) {

-        String name = img.getAttribute("name");

-        String id = img.getAttribute("id");

-        String file = getString(img, "init_from");

-

-        Texture2D tex = new Texture2D();

-        tex.setFileName(file);

-        tex.setFileDir(mRootDir);

-        mScene.appendTextures(tex);

-        mImages.put(id, tex);

-    }

-

-    private void getScene(Element scene) {

-        String name = scene.getAttribute("name");

-        String id = scene.getAttribute("id");

-

-        Node childNode = scene.getFirstChild();

-        while (childNode != null) {

-            if (childNode.getNodeType() == Node.ELEMENT_NODE) {

-                String indent = "";

-                getNode((Element)childNode, null, indent);

-            }

-            childNode = childNode.getNextSibling();

-        }

-    }

-

-    private String getString(Element elem, String name) {

-        String text = null;

-        NodeList nl = elem.getElementsByTagName(name);

-        if (nl != null && nl.getLength() != 0) {

-            text = ((Element)nl.item(0)).getFirstChild().getNodeValue();

-        }

-        return text;

-    }

-

-    private String getString(Element elem) {

-        String text = null;

-        text = elem.getFirstChild().getNodeValue();

-        return text;

-    }

-

-    private int getInt(Element elem, String name) {

-        return Integer.parseInt(getString(elem, name));

-    }

-

-    private float getFloat(Element elem, String name) {

-        return Float.parseFloat(getString(elem, name));

-    }

-

-    private float getFloat(Element elem) {

-        return Float.parseFloat(getString(elem));

-    }

-

-    private Float3 parseFloat3(String valueString) {

-        StringTokenizer st = new StringTokenizer(valueString);

-        float x = Float.parseFloat(st.nextToken());

-        float y = Float.parseFloat(st.nextToken());

-        float z = Float.parseFloat(st.nextToken());

-        return new Float3(x, y, z);

-    }

-

-    private Float4 parseFloat4(String valueString) {

-        StringTokenizer st = new StringTokenizer(valueString);

-        float x = Float.parseFloat(st.nextToken());

-        float y = Float.parseFloat(st.nextToken());

-        float z = Float.parseFloat(st.nextToken());

-        float w = Float.parseFloat(st.nextToken());

-        return new Float4(x, y, z, w);

-    }

-

-    private Float3 getFloat3(Element elem, String name) {

-        String valueString = getString(elem, name);

-        return parseFloat3(valueString);

-    }

-

-    private Float4 getFloat4(Element elem, String name) {

-        String valueString = getString(elem, name);

-        return parseFloat4(valueString);

-    }

-

-    private Float3 getFloat3(Element elem) {

-        String valueString = getString(elem);

-        return parseFloat3(valueString);

-    }

-

-    private Float4 getFloat4(Element elem) {

-        String valueString = getString(elem);

-        return parseFloat4(valueString);

-    }

-}

diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaScene.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaScene.java
deleted file mode 100644
index 301075e..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaScene.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.BufferedInputStream;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Vector;
-
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.os.AsyncTask;
-import android.renderscript.*;
-import android.renderscript.Allocation.MipmapControl;
-import android.renderscript.Element.Builder;
-import android.renderscript.Font.Style;
-import android.renderscript.Program.TextureType;
-import android.renderscript.ProgramStore.DepthFunc;
-import android.util.Log;
-import com.android.scenegraph.SceneManager.SceneLoadedCallback;
-
-
-public class ColladaScene {
-
-    private String modelName;
-    private static String TAG = "ColladaScene";
-    private final int STATE_LAST_FOCUS = 1;
-    boolean mLoadFromSD = false;
-
-    SceneLoadedCallback mCallback;
-
-    public ColladaScene(String name, SceneLoadedCallback cb) {
-        modelName = name;
-        mCallback = cb;
-    }
-
-    public void init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-
-        mLoadFromSD = SceneManager.isSDCardPath(modelName);
-
-        new ColladaLoaderTask().execute(modelName);
-    }
-
-    private Resources mRes;
-    private RenderScriptGL mRS;
-    Scene mActiveScene;
-
-    private class ColladaLoaderTask extends AsyncTask<String, Void, Boolean> {
-        ColladaParser sceneSource;
-        protected Boolean doInBackground(String... names) {
-            String rootDir = names[0].substring(0, names[0].lastIndexOf('/') + 1);
-            long start = System.currentTimeMillis();
-            sceneSource = new ColladaParser();
-            InputStream is = null;
-            try {
-                if (!mLoadFromSD) {
-                    is = mRes.getAssets().open(names[0]);
-                } else {
-                    File f = new File(names[0]);
-                    is = new BufferedInputStream(new FileInputStream(f));
-                }
-            } catch (IOException e) {
-                Log.e(TAG, "Could not open collada file");
-                return new Boolean(false);
-            }
-            long end = System.currentTimeMillis();
-            Log.v("TIMER", "Stream load time: " + (end - start));
-
-            start = System.currentTimeMillis();
-            sceneSource.init(is, rootDir);
-            end = System.currentTimeMillis();
-            Log.v("TIMER", "Collada parse time: " + (end - start));
-            return new Boolean(true);
-        }
-
-        protected void onPostExecute(Boolean result) {
-            mActiveScene = sceneSource.getScene();
-            if (mCallback != null) {
-                mCallback.mLoadedScene = mActiveScene;
-                mCallback.run();
-            }
-
-            String shortName = modelName.substring(0, modelName.lastIndexOf('.'));
-            new A3DLoaderTask().execute(shortName + ".a3d");
-        }
-    }
-
-    private class A3DLoaderTask extends AsyncTask<String, Void, Boolean> {
-        protected Boolean doInBackground(String... names) {
-            long start = System.currentTimeMillis();
-            FileA3D model;
-            if (!mLoadFromSD) {
-                model = FileA3D.createFromAsset(mRS, mRes.getAssets(), names[0]);
-            } else {
-                model = FileA3D.createFromFile(mRS, names[0]);
-            }
-            int numModels = model.getIndexEntryCount();
-            for (int i = 0; i < numModels; i ++) {
-                FileA3D.IndexEntry entry = model.getIndexEntry(i);
-                if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
-                    mActiveScene.meshLoaded(entry.getMesh());
-                }
-            }
-            long end = System.currentTimeMillis();
-            Log.v("TIMER", "A3D load time: " + (end - start));
-            return new Boolean(true);
-        }
-
-        protected void onPostExecute(Boolean result) {
-        }
-    }
-
-}
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/CompoundTransform.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/CompoundTransform.java
deleted file mode 100644
index 9274b17..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/CompoundTransform.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import com.android.scenegraph.SceneManager;
-
-import android.renderscript.*;
-import android.renderscript.Float3;
-import android.renderscript.Matrix4f;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class CompoundTransform extends Transform {
-
-    public static abstract class Component {
-        String mName;
-        CompoundTransform mParent;
-        int mParentIndex;
-        protected ScriptField_TransformComponent_s.Item mData;
-
-        Component(int type, String name) {
-            mData = new ScriptField_TransformComponent_s.Item();
-            mData.type = type;
-            mName = name;
-        }
-
-        void setNameAlloc() {
-            RenderScriptGL rs = SceneManager.getRS();
-            if (mData.name != null)  {
-                return;
-            }
-            mData.name = SceneManager.getCachedAlloc(getName());
-            if (mData.name == null) {
-                mData.name = SceneManager.getStringAsAllocation(rs, getName());
-                SceneManager.cacheAlloc(getName(), mData.name);
-            }
-        }
-
-        ScriptField_TransformComponent_s.Item getRSData() {
-            setNameAlloc();
-            return mData;
-        }
-
-        protected void update() {
-            if (mParent != null) {
-                mParent.updateRSComponent(this);
-            }
-        }
-
-        public String getName() {
-            return mName;
-        }
-    }
-
-    public static class TranslateComponent extends Component {
-        public TranslateComponent(String name, Float3 translate) {
-            super(ScriptC_export.const_Transform_TRANSLATE, name);
-            setValue(translate);
-        }
-        public Float3 getValue() {
-            return new Float3(mData.value.x, mData.value.y, mData.value.z);
-        }
-        public void setValue(Float3 val) {
-            mData.value.x = val.x;
-            mData.value.y = val.y;
-            mData.value.z = val.z;
-            update();
-        }
-    }
-
-    public static class RotateComponent extends Component {
-        public RotateComponent(String name, Float3 axis, float angle) {
-            super(ScriptC_export.const_Transform_ROTATE, name);
-            setAxis(axis);
-            setAngle(angle);
-        }
-        public Float3 getAxis() {
-            return new Float3(mData.value.x, mData.value.y, mData.value.z);
-        }
-        public float getAngle() {
-            return mData.value.w;
-        }
-        public void setAxis(Float3 val) {
-            mData.value.x = val.x;
-            mData.value.y = val.y;
-            mData.value.z = val.z;
-            update();
-        }
-        public void setAngle(float val) {
-            mData.value.w = val;
-            update();
-        }
-    }
-
-    public static class ScaleComponent extends Component {
-        public ScaleComponent(String name, Float3 scale) {
-            super(ScriptC_export.const_Transform_SCALE, name);
-            setValue(scale);
-        }
-        public Float3 getValue() {
-            return new Float3(mData.value.x, mData.value.y, mData.value.z);
-        }
-        public void setValue(Float3 val) {
-            mData.value.x = val.x;
-            mData.value.y = val.y;
-            mData.value.z = val.z;
-            update();
-        }
-    }
-
-    ScriptField_TransformComponent_s mComponentField;
-    public ArrayList<Component> mTransformComponents;
-
-    public CompoundTransform() {
-        mTransformComponents = new ArrayList<Component>();
-    }
-
-    public TranslateComponent addTranslate(String name, Float3 translate) {
-        TranslateComponent c = new TranslateComponent(name, translate);
-        addComponent(c);
-        return c;
-    }
-
-    public RotateComponent addRotate(String name, Float3 axis, float angle) {
-        RotateComponent c = new RotateComponent(name, axis, angle);
-        addComponent(c);
-        return c;
-    }
-
-    public ScaleComponent addScale(String name, Float3 scale) {
-        ScaleComponent c = new ScaleComponent(name, scale);
-        addComponent(c);
-        return c;
-    }
-
-    public void addComponent(Component c) {
-        if (c.mParent != null) {
-            throw new IllegalArgumentException("Transform components may not be shared");
-        }
-        c.mParent = this;
-        c.mParentIndex = mTransformComponents.size();
-        mTransformComponents.add(c);
-        updateRSComponentAllocation();
-    }
-
-    public void setComponent(int index, Component c) {
-        if (c.mParent != null) {
-            throw new IllegalArgumentException("Transform components may not be shared");
-        }
-        if (index >= mTransformComponents.size()) {
-            throw new IllegalArgumentException("Invalid component index");
-        }
-        c.mParent = this;
-        c.mParentIndex = index;
-        mTransformComponents.set(index, c);
-        updateRSComponent(c);
-    }
-
-    void updateRSComponent(Component c) {
-        if (mField == null || mComponentField == null) {
-            return;
-        }
-        mComponentField.set(c.getRSData(), c.mParentIndex, true);
-        mField.set_isDirty(0, 1, true);
-    }
-
-    void updateRSComponentAllocation() {
-        if (mField == null) {
-            return;
-        }
-        initLocalData();
-
-        mField.set_components(0, mTransformData.components, false);
-        mField.set_isDirty(0, 1, true);
-    }
-
-    void initLocalData() {
-        RenderScriptGL rs = SceneManager.getRS();
-        int numComponenets = mTransformComponents.size();
-        if (numComponenets > 0) {
-            mComponentField = new ScriptField_TransformComponent_s(rs, numComponenets);
-            for (int i = 0; i < numComponenets; i ++) {
-                Component ith = mTransformComponents.get(i);
-                mComponentField.set(ith.getRSData(), i, false);
-            }
-            mComponentField.copyAll();
-
-            mTransformData.components = mComponentField.getAllocation();
-        }
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java
deleted file mode 100644
index 1502458..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import com.android.scenegraph.Scene;
-import com.android.scenegraph.SceneManager;
-
-import android.renderscript.Element;
-import android.renderscript.Float4;
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.renderscript.RenderScriptGL;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class Float4Param extends ShaderParam {
-    private static String TAG = "Float4Param";
-
-    LightBase mLight;
-
-    public Float4Param(String name) {
-        super(name);
-    }
-
-    public Float4Param(String name, float x) {
-        super(name);
-        set(x, 0, 0, 0);
-    }
-
-    public Float4Param(String name, float x, float y) {
-        super(name);
-        set(x, y, 0, 0);
-    }
-
-    public Float4Param(String name, float x, float y, float z) {
-        super(name);
-        set(x, y, z, 0);
-    }
-
-    public Float4Param(String name, float x, float y, float z, float w) {
-        super(name);
-        set(x, y, z, w);
-    }
-
-    void set(float x, float y, float z, float w) {
-        mData.float_value.x = x;
-        mData.float_value.y = y;
-        mData.float_value.z = z;
-        mData.float_value.w = w;
-        if (mField != null) {
-            mField.set_float_value(0, mData.float_value, true);
-        }
-        incTimestamp();
-    }
-
-    public void setValue(Float4 v) {
-        set(v.x, v.y, v.z, v.w);
-    }
-
-    public Float4 getValue() {
-        return mData.float_value;
-    }
-
-    public void setLight(LightBase l) {
-        mLight = l;
-        if (mField != null) {
-            mData.light = mLight.getRSData().getAllocation();
-            mField.set_light(0, mData.light, true);
-        }
-        incTimestamp();
-    }
-
-    boolean findLight(String property) {
-        String indexStr = mParamName.substring(property.length() + 1);
-        if (indexStr == null) {
-            Log.e(TAG, "Invalid light index.");
-            return false;
-        }
-        int index = Integer.parseInt(indexStr);
-        if (index == -1) {
-            return false;
-        }
-        Scene parentScene = SceneManager.getInstance().getActiveScene();
-        ArrayList<LightBase> allLights = parentScene.getLights();
-        if (index >= allLights.size()) {
-            return false;
-        }
-        mLight = allLights.get(index);
-        if (mLight == null) {
-            return false;
-        }
-        return true;
-    }
-
-    int getTypeFromName() {
-        int paramType = ScriptC_export.const_ShaderParam_FLOAT4_DATA;
-        if (mParamName.equalsIgnoreCase(cameraPos)) {
-            paramType = ScriptC_export.const_ShaderParam_FLOAT4_CAMERA_POS;
-        } else if(mParamName.equalsIgnoreCase(cameraDir)) {
-            paramType = ScriptC_export.const_ShaderParam_FLOAT4_CAMERA_DIR;
-        } else if(mParamName.startsWith(lightColor) && findLight(lightColor)) {
-            paramType = ScriptC_export.const_ShaderParam_FLOAT4_LIGHT_COLOR;
-        } else if(mParamName.startsWith(lightPos) && findLight(lightPos)) {
-            paramType = ScriptC_export.const_ShaderParam_FLOAT4_LIGHT_POS;
-        } else if(mParamName.startsWith(lightDir) && findLight(lightDir)) {
-            paramType = ScriptC_export.const_ShaderParam_FLOAT4_LIGHT_DIR;
-        }
-        return paramType;
-    }
-
-    void initLocalData() {
-        mData.type = getTypeFromName();
-        if (mCamera != null) {
-            mData.camera = mCamera.getRSData().getAllocation();
-        }
-        if (mLight != null) {
-            mData.light = mLight.getRSData().getAllocation();
-        }
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java
deleted file mode 100644
index 8a468db..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import com.android.scenegraph.TextureBase;
-
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.renderscript.ProgramFragment.Builder;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class FragmentShader extends Shader {
-    ProgramFragment mProgram;
-    ScriptField_FragmentShader_s mField;
-
-    public static class Builder {
-
-        FragmentShader mShader;
-        ProgramFragment.Builder mBuilder;
-
-        public Builder(RenderScriptGL rs) {
-            mShader = new FragmentShader();
-            mBuilder = new ProgramFragment.Builder(rs);
-        }
-
-        public Builder setShader(Resources resources, int resourceID) {
-            mBuilder.setShader(resources, resourceID);
-            return this;
-        }
-
-        public Builder setShader(String code) {
-            mBuilder.setShader(code);
-            return this;
-        }
-
-        public Builder setObjectConst(Type type) {
-            mShader.mPerObjConstants = type;
-            return this;
-        }
-
-        public Builder setShaderConst(Type type) {
-            mShader.mPerShaderConstants = type;
-            return this;
-        }
-
-        public Builder addShaderTexture(Program.TextureType texType, String name) {
-            mShader.mShaderTextureNames.add(name);
-            mShader.mShaderTextureTypes.add(texType);
-            return this;
-        }
-
-        public Builder addTexture(Program.TextureType texType, String name) {
-            mShader.mTextureNames.add(name);
-            mShader.mTextureTypes.add(texType);
-            return this;
-        }
-
-        public FragmentShader create() {
-            if (mShader.mPerShaderConstants != null) {
-                mBuilder.addConstant(mShader.mPerShaderConstants);
-            }
-            if (mShader.mPerObjConstants != null) {
-                mBuilder.addConstant(mShader.mPerObjConstants);
-            }
-            for (int i = 0; i < mShader.mTextureTypes.size(); i ++) {
-                mBuilder.addTexture(mShader.mTextureTypes.get(i),
-                                    mShader.mTextureNames.get(i));
-            }
-            for (int i = 0; i < mShader.mShaderTextureTypes.size(); i ++) {
-                mBuilder.addTexture(mShader.mShaderTextureTypes.get(i),
-                                    mShader.mShaderTextureNames.get(i));
-            }
-
-            mShader.mProgram = mBuilder.create();
-            return mShader;
-        }
-    }
-
-    public ProgramFragment getProgram() {
-        return mProgram;
-    }
-
-    ScriptField_ShaderParam_s getTextureParams() {
-        RenderScriptGL rs = SceneManager.getRS();
-        Resources res = SceneManager.getRes();
-        if (rs == null || res == null) {
-            return null;
-        }
-
-        ArrayList<ScriptField_ShaderParam_s.Item> paramList;
-        paramList = new ArrayList<ScriptField_ShaderParam_s.Item>();
-
-        int shaderTextureStart = mTextureTypes.size();
-        for (int i = 0; i < mShaderTextureNames.size(); i ++) {
-            ShaderParam sp = mSourceParams.get(mShaderTextureNames.get(i));
-            if (sp != null && sp instanceof TextureParam) {
-                TextureParam p = (TextureParam)sp;
-                ScriptField_ShaderParam_s.Item paramRS = new ScriptField_ShaderParam_s.Item();
-                paramRS.bufferOffset = shaderTextureStart + i;
-                paramRS.transformTimestamp = 0;
-                paramRS.dataTimestamp = 0;
-                paramRS.data = p.getRSData().getAllocation();
-                paramList.add(paramRS);
-            }
-        }
-
-        ScriptField_ShaderParam_s rsParams = null;
-        int paramCount = paramList.size();
-        if (paramCount != 0) {
-            rsParams = new ScriptField_ShaderParam_s(rs, paramCount);
-            for (int i = 0; i < paramCount; i++) {
-                rsParams.set(paramList.get(i), i, false);
-            }
-            rsParams.copyAll();
-        }
-        return rsParams;
-    }
-
-    ScriptField_FragmentShader_s getRSData() {
-        if (mField != null) {
-            return mField;
-        }
-
-        RenderScriptGL rs = SceneManager.getRS();
-        Resources res = SceneManager.getRes();
-        if (rs == null || res == null) {
-            return null;
-        }
-
-        ScriptField_FragmentShader_s.Item item = new ScriptField_FragmentShader_s.Item();
-        item.program = mProgram;
-
-        ScriptField_ShaderParam_s texParams = getTextureParams();
-        if (texParams != null) {
-            item.shaderTextureParams = texParams.getAllocation();
-        }
-
-        linkConstants(rs);
-        if (mPerShaderConstants != null) {
-            item.shaderConst = mConstantBuffer;
-            item.shaderConstParams = mConstantBufferParams.getAllocation();
-            mProgram.bindConstants(item.shaderConst, 0);
-        }
-
-        item.objectConstIndex = -1;
-        if (mPerObjConstants != null) {
-            item.objectConstIndex = mPerShaderConstants != null ? 1 : 0;
-        }
-
-        mField = new ScriptField_FragmentShader_s(rs, 1);
-        mField.set(item, 0, true);
-        return mField;
-    }
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/LightBase.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/LightBase.java
deleted file mode 100644
index 8f5e2e7..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/LightBase.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import android.renderscript.Float3;
-import android.renderscript.Float4;
-import android.renderscript.Matrix4f;
-import android.renderscript.RenderScriptGL;
-import android.util.Log;
-
-/**
- * @hide
- */
-public abstract class LightBase extends SceneGraphBase {
-    static final int RS_LIGHT_POINT = 0;
-    static final int RS_LIGHT_DIRECTIONAL = 1;
-
-    ScriptField_Light_s mField;
-    ScriptField_Light_s.Item mFieldData;
-    Transform mTransform;
-    Float4 mColor;
-    float mIntensity;
-    public LightBase() {
-        mColor = new Float4(0.0f, 0.0f, 0.0f, 0.0f);
-        mIntensity = 1.0f;
-    }
-
-    public void setTransform(Transform t) {
-        mTransform = t;
-        updateRSData();
-    }
-
-    public void setColor(float r, float g, float b) {
-        mColor.x = r;
-        mColor.y = g;
-        mColor.z = b;
-        updateRSData();
-    }
-
-    public void setColor(Float3 c) {
-        setColor(c.x, c.y, c.z);
-    }
-
-    public void setIntensity(float i) {
-        mIntensity = i;
-        updateRSData();
-    }
-
-    public void setName(String n) {
-        super.setName(n);
-        updateRSData();
-    }
-
-    protected void updateRSData() {
-        if (mField == null) {
-            return;
-        }
-        RenderScriptGL rs = SceneManager.getRS();
-        mFieldData.transformMatrix = mTransform.getRSData().getAllocation();
-        mFieldData.name = getNameAlloc(rs);
-        mFieldData.color = mColor;
-        mFieldData.intensity = mIntensity;
-
-        initLocalData();
-
-        mField.set(mFieldData, 0, true);
-    }
-
-    abstract void initLocalData();
-
-    ScriptField_Light_s getRSData() {
-        if (mField != null) {
-            return mField;
-        }
-
-        RenderScriptGL rs = SceneManager.getRS();
-        if (rs == null) {
-            return null;
-        }
-        if (mField == null) {
-            mField = new ScriptField_Light_s(rs, 1);
-            mFieldData = new ScriptField_Light_s.Item();
-        }
-
-        updateRSData();
-
-        return mField;
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/MatrixTransform.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/MatrixTransform.java
deleted file mode 100644
index 6d70bc9..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/MatrixTransform.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import android.renderscript.Matrix4f;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class MatrixTransform extends Transform {
-
-    Matrix4f mLocalMatrix;
-    public MatrixTransform() {
-        mLocalMatrix = new Matrix4f();
-    }
-
-    public void setMatrix(Matrix4f matrix) {
-        mLocalMatrix = matrix;
-        updateRSData();
-    }
-
-    public Matrix4f getMatrix() {
-        return new Matrix4f(mLocalMatrix.getArray());
-    }
-
-    void initLocalData() {
-        mTransformData.localMat = mLocalMatrix;
-    }
-
-    void updateRSData() {
-        if (mField == null) {
-            return;
-        }
-        mField.set_localMat(0, mLocalMatrix, false);
-        mField.set_isDirty(0, 1, true);
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/PointLight.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/PointLight.java
deleted file mode 100644
index 574bafc..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/PointLight.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class PointLight extends LightBase {
-    public PointLight() {
-    }
-
-     void initLocalData() {
-        mFieldData.type = RS_LIGHT_POINT;
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderPass.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderPass.java
deleted file mode 100644
index 02fd69d..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderPass.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import android.util.Log;
-
-import android.renderscript.*;
-import android.content.res.Resources;
-
-/**
- * @hide
- */
-public class RenderPass extends SceneGraphBase {
-
-    TextureRenderTarget mColorTarget;
-    Float4 mClearColor;
-    boolean mShouldClearColor;
-
-    TextureRenderTarget mDepthTarget;
-    float mClearDepth;
-    boolean mShouldClearDepth;
-
-    ArrayList<RenderableBase> mObjectsToDraw;
-
-    Camera mCamera;
-
-    ScriptField_RenderPass_s.Item mRsField;
-
-    public RenderPass() {
-        mObjectsToDraw = new ArrayList<RenderableBase>();
-        mClearColor = new Float4(0.0f, 0.0f, 0.0f, 0.0f);
-        mShouldClearColor = true;
-        mClearDepth = 1.0f;
-        mShouldClearDepth = true;
-    }
-
-    public void appendRenderable(Renderable d) {
-        mObjectsToDraw.add(d);
-    }
-
-    public void setCamera(Camera c) {
-        mCamera = c;
-    }
-
-    public void setColorTarget(TextureRenderTarget colorTarget) {
-        mColorTarget = colorTarget;
-    }
-    public void setClearColor(Float4 clearColor) {
-        mClearColor = clearColor;
-    }
-    public void setShouldClearColor(boolean shouldClearColor) {
-        mShouldClearColor = shouldClearColor;
-    }
-
-    public void setDepthTarget(TextureRenderTarget depthTarget) {
-        mDepthTarget = depthTarget;
-    }
-    public void setClearDepth(float clearDepth) {
-        mClearDepth = clearDepth;
-    }
-    public void setShouldClearDepth(boolean shouldClearDepth) {
-        mShouldClearDepth = shouldClearDepth;
-    }
-
-    public ArrayList<RenderableBase> getRenderables() {
-        return mObjectsToDraw;
-    }
-
-    ScriptField_RenderPass_s.Item getRsField(RenderScriptGL rs, Resources res) {
-        if (mRsField != null) {
-            return mRsField;
-        }
-
-        mRsField = new ScriptField_RenderPass_s.Item();
-        if (mColorTarget != null) {
-            mRsField.color_target = mColorTarget.getRsData(true).get_texture(0);
-        }
-        if (mColorTarget != null) {
-            mRsField.depth_target = mDepthTarget.getRsData(true).get_texture(0);
-        }
-        mRsField.camera = mCamera != null ? mCamera.getRSData().getAllocation() : null;
-
-        if (mObjectsToDraw.size() != 0) {
-            Allocation drawableData = Allocation.createSized(rs,
-                                                              Element.ALLOCATION(rs),
-                                                              mObjectsToDraw.size());
-            Allocation[] drawableAllocs = new Allocation[mObjectsToDraw.size()];
-            for (int i = 0; i < mObjectsToDraw.size(); i ++) {
-                Renderable dI = (Renderable)mObjectsToDraw.get(i);
-                drawableAllocs[i] = dI.getRsField(rs, res).getAllocation();
-            }
-            drawableData.copyFrom(drawableAllocs);
-            mRsField.objects = drawableData;
-        }
-
-        mRsField.clear_color = mClearColor;
-        mRsField.clear_depth = mClearDepth;
-        mRsField.should_clear_color = mShouldClearColor;
-        mRsField.should_clear_depth = mShouldClearDepth;
-        return mRsField;
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java
deleted file mode 100644
index c08a722..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-import android.content.res.Resources;
-
-import android.renderscript.Allocation;
-import android.renderscript.Element;
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramRaster;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.renderscript.RSRuntimeException;
-import android.renderscript.RenderScript;
-import android.renderscript.RenderScriptGL;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class RenderState extends SceneGraphBase {
-    VertexShader mVertex;
-    FragmentShader mFragment;
-    ProgramStore mStore;
-    ProgramRaster mRaster;
-
-    ScriptField_RenderState_s mField;
-
-    public RenderState(VertexShader pv,
-                       FragmentShader pf,
-                       ProgramStore ps,
-                       ProgramRaster pr) {
-        mVertex = pv;
-        mFragment = pf;
-        mStore = ps;
-        mRaster = pr;
-    }
-
-    public RenderState(RenderState r) {
-        mVertex = r.mVertex;
-        mFragment = r.mFragment;
-        mStore = r.mStore;
-        mRaster = r.mRaster;
-    }
-
-    public void setProgramVertex(VertexShader pv) {
-        mVertex = pv;
-        updateRSData();
-    }
-
-    public void setProgramFragment(FragmentShader pf) {
-        mFragment = pf;
-        updateRSData();
-    }
-
-    public void setProgramStore(ProgramStore ps) {
-        mStore = ps;
-        updateRSData();
-    }
-
-    public void setProgramRaster(ProgramRaster pr) {
-        mRaster = pr;
-        updateRSData();
-    }
-
-    void updateRSData() {
-        if (mField == null) {
-            return;
-        }
-        ScriptField_RenderState_s.Item item = new ScriptField_RenderState_s.Item();
-        item.pv = mVertex.getRSData().getAllocation();
-        item.pf = mFragment.getRSData().getAllocation();
-        item.ps = mStore;
-        item.pr = mRaster;
-
-        mField.set(item, 0, true);
-    }
-
-    public ScriptField_RenderState_s getRSData() {
-        if (mField != null) {
-            return mField;
-        }
-
-        RenderScriptGL rs = SceneManager.getRS();
-        if (rs == null) {
-            return null;
-        }
-
-        mField = new ScriptField_RenderState_s(rs, 1);
-        updateRSData();
-
-        return mField;
-    }
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java
deleted file mode 100644
index 9266f30..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import com.android.scenegraph.Float4Param;
-import com.android.scenegraph.MatrixTransform;
-import com.android.scenegraph.SceneManager;
-import com.android.scenegraph.ShaderParam;
-import com.android.scenegraph.TransformParam;
-
-import android.content.res.Resources;
-import android.renderscript.Allocation;
-import android.renderscript.Element;
-import android.renderscript.Element.DataType;
-import android.renderscript.Matrix4f;
-import android.renderscript.Mesh;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.renderscript.RenderScriptGL;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class Renderable extends RenderableBase {
-    HashMap<String, ShaderParam> mSourceParams;
-
-    RenderState mRenderState;
-    Transform mTransform;
-
-    String mMeshName;
-    String mMeshIndexName;
-
-    public String mMaterialName;
-
-    ScriptField_Renderable_s mField;
-    ScriptField_Renderable_s.Item mData;
-
-    public Renderable() {
-        mSourceParams = new HashMap<String, ShaderParam>();
-        mData = new ScriptField_Renderable_s.Item();
-    }
-
-    public void setCullType(int cull) {
-        mData.cullType = cull;
-    }
-
-    public void setRenderState(RenderState renderState) {
-        mRenderState = renderState;
-        if (mField != null) {
-            RenderScriptGL rs = SceneManager.getRS();
-            updateFieldItem(rs);
-            mField.set(mData, 0, true);
-        }
-    }
-
-    public void setMesh(Mesh mesh) {
-        mData.mesh = mesh;
-        if (mField != null) {
-            mField.set_mesh(0, mData.mesh, true);
-        }
-    }
-
-    public void setMesh(String mesh, String indexName) {
-        mMeshName = mesh;
-        mMeshIndexName = indexName;
-    }
-
-    public void setMaterialName(String name) {
-        mMaterialName = name;
-    }
-
-    public Transform getTransform() {
-        return mTransform;
-    }
-
-    public void setTransform(Transform t) {
-        mTransform = t;
-        if (mField != null) {
-            RenderScriptGL rs = SceneManager.getRS();
-            updateFieldItem(rs);
-            mField.set(mData, 0, true);
-        }
-    }
-
-    public void appendSourceParams(ShaderParam p) {
-        mSourceParams.put(p.getParamName(), p);
-        // Possibly lift this restriction later
-        if (mField != null) {
-            throw new RuntimeException("Can't add source params to objects that are rendering");
-        }
-    }
-
-    public void resolveMeshData(Mesh mesh) {
-        mData.mesh = mesh;
-        if (mData.mesh == null) {
-            Log.v("DRAWABLE: ", "*** NO MESH *** " + mMeshName);
-            return;
-        }
-        int subIndexCount = mData.mesh.getPrimitiveCount();
-        if (subIndexCount == 1 || mMeshIndexName == null) {
-            mData.meshIndex = 0;
-        } else {
-            for (int i = 0; i < subIndexCount; i ++) {
-                if (mData.mesh.getIndexSetAllocation(i).getName().equals(mMeshIndexName)) {
-                    mData.meshIndex = i;
-                    break;
-                }
-            }
-        }
-        if (mField != null) {
-            mField.set(mData, 0, true);
-        }
-    }
-
-    void updateTextures(RenderScriptGL rs) {
-        Iterator<ShaderParam> allParamsIter = mSourceParams.values().iterator();
-        int paramIndex = 0;
-        while (allParamsIter.hasNext()) {
-            ShaderParam sp = allParamsIter.next();
-            if (sp instanceof TextureParam) {
-                TextureParam p = (TextureParam)sp;
-                TextureBase tex = p.getTexture();
-                if (tex != null) {
-                    mData.pf_textures[paramIndex++] = tex.getRsData(false).getAllocation();
-                }
-            }
-        }
-        ProgramFragment pf = mRenderState.mFragment.mProgram;
-        mData.pf_num_textures = pf != null ? Math.min(pf.getTextureCount(), paramIndex) : 0;
-        if (mField != null) {
-            mField.set_pf_textures(0, mData.pf_textures, true);
-            mField.set_pf_num_textures(0, mData.pf_num_textures, true);
-        }
-    }
-
-    public void setVisible(boolean vis) {
-        mData.cullType = vis ? 0 : 2;
-        if (mField != null) {
-            mField.set_cullType(0, mData.cullType, true);
-        }
-    }
-
-    ScriptField_Renderable_s getRsField(RenderScriptGL rs, Resources res) {
-        if (mField != null) {
-            return mField;
-        }
-        updateFieldItem(rs);
-        updateTextures(rs);
-
-        mField = new ScriptField_Renderable_s(rs, 1);
-        mField.set(mData, 0, true);
-
-        return mField;
-    }
-
-    void updateVertexConstants(RenderScriptGL rs) {
-        Allocation pvParams = null, vertexConstants = null;
-        VertexShader pv = mRenderState.mVertex;
-        if (pv != null && pv.getObjectConstants() != null) {
-            vertexConstants = Allocation.createTyped(rs, pv.getObjectConstants());
-            Element vertexConst = vertexConstants.getType().getElement();
-            pvParams = ShaderParam.fillInParams(vertexConst, mSourceParams,
-                                                mTransform).getAllocation();
-        }
-        mData.pv_const = vertexConstants;
-        mData.pv_constParams = pvParams;
-    }
-
-    void updateFragmentConstants(RenderScriptGL rs) {
-        Allocation pfParams = null, fragmentConstants = null;
-        FragmentShader pf = mRenderState.mFragment;
-        if (pf != null && pf.getObjectConstants() != null) {
-            fragmentConstants = Allocation.createTyped(rs, pf.getObjectConstants());
-            Element fragmentConst = fragmentConstants.getType().getElement();
-            pfParams = ShaderParam.fillInParams(fragmentConst, mSourceParams,
-                                                mTransform).getAllocation();
-        }
-        mData.pf_const = fragmentConstants;
-        mData.pf_constParams = pfParams;
-    }
-
-    void updateFieldItem(RenderScriptGL rs) {
-        if (mRenderState == null) {
-            mRenderState = SceneManager.getDefaultState();
-        }
-        if (mTransform == null) {
-            mTransform = SceneManager.getDefaultTransform();
-        }
-        updateVertexConstants(rs);
-        updateFragmentConstants(rs);
-
-        mData.transformMatrix = mTransform.getRSData().getAllocation();
-
-        mData.name = getNameAlloc(rs);
-        mData.render_state = mRenderState.getRSData().getAllocation();
-        mData.bVolInitialized = 0;
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderableBase.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderableBase.java
deleted file mode 100644
index 74535dd..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderableBase.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class RenderableBase extends SceneGraphBase {
-    public RenderableBase() {
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderableGroup.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderableGroup.java
deleted file mode 100644
index 590bbab..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderableGroup.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class RenderableGroup extends RenderableBase {
-
-    ArrayList<RenderableBase> mChildren;
-
-    public RenderableGroup() {
-        mChildren = new ArrayList<RenderableBase>();
-    }
-
-    public void appendChildren(RenderableBase d) {
-        mChildren.add(d);
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java
deleted file mode 100644
index 27336ab..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import com.android.scenegraph.Camera;
-import com.android.scenegraph.CompoundTransform;
-import com.android.scenegraph.RenderPass;
-import com.android.scenegraph.Renderable;
-import com.android.scenegraph.SceneManager;
-import com.android.scenegraph.TextureBase;
-
-import android.content.res.Resources;
-import android.os.AsyncTask;
-import android.renderscript.*;
-import android.renderscript.Mesh;
-import android.renderscript.RenderScriptGL;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class Scene extends SceneGraphBase {
-    private static String TIMER_TAG = "TIMER";
-
-    CompoundTransform mRootTransforms;
-    HashMap<String, Transform> mTransformMap;
-    ArrayList<RenderPass> mRenderPasses;
-    ArrayList<LightBase> mLights;
-    ArrayList<Camera> mCameras;
-    ArrayList<FragmentShader> mFragmentShaders;
-    ArrayList<VertexShader> mVertexShaders;
-    ArrayList<RenderableBase> mRenderables;
-    HashMap<String, RenderableBase> mRenderableMap;
-    ArrayList<Texture2D> mTextures;
-
-    HashMap<String, ArrayList<Renderable> > mRenderableMeshMap;
-
-    // RS Specific stuff
-    ScriptField_SgTransform mTransformRSData;
-
-    RenderScriptGL mRS;
-    Resources mRes;
-
-    ScriptField_RenderPass_s mRenderPassAlloc;
-
-    public Scene() {
-        mRenderPasses = new ArrayList<RenderPass>();
-        mLights = new ArrayList<LightBase>();
-        mCameras = new ArrayList<Camera>();
-        mFragmentShaders = new ArrayList<FragmentShader>();
-        mVertexShaders = new ArrayList<VertexShader>();
-        mRenderables = new ArrayList<RenderableBase>();
-        mRenderableMap = new HashMap<String, RenderableBase>();
-        mRenderableMeshMap = new HashMap<String, ArrayList<Renderable> >();
-        mTextures = new ArrayList<Texture2D>();
-        mRootTransforms = new CompoundTransform();
-        mRootTransforms.setName("_scene_root_");
-        mTransformMap = new HashMap<String, Transform>();
-    }
-
-    public void appendTransform(Transform t) {
-        if (t == null) {
-            throw new RuntimeException("Adding null object");
-        }
-        mRootTransforms.appendChild(t);
-    }
-
-    public CompoundTransform appendNewCompoundTransform() {
-        CompoundTransform t = new CompoundTransform();
-        appendTransform(t);
-        return t;
-    }
-
-    public MatrixTransform appendNewMatrixTransform() {
-        MatrixTransform t = new MatrixTransform();
-        appendTransform(t);
-        return t;
-    }
-
-    // temporary
-    public void addToTransformMap(Transform t) {
-        mTransformMap.put(t.getName(), t);
-    }
-
-    public Transform getTransformByName(String name) {
-        return mTransformMap.get(name);
-    }
-
-    public void appendRenderPass(RenderPass p) {
-        if (p == null) {
-            throw new RuntimeException("Adding null object");
-        }
-        mRenderPasses.add(p);
-    }
-
-    public RenderPass appendNewRenderPass() {
-        RenderPass p = new RenderPass();
-        appendRenderPass(p);
-        return p;
-    }
-
-    public void clearRenderPasses() {
-        mRenderPasses.clear();
-    }
-
-    public void appendLight(LightBase l) {
-        if (l == null) {
-            throw new RuntimeException("Adding null object");
-        }
-        mLights.add(l);
-    }
-
-    public void appendCamera(Camera c) {
-        if (c == null) {
-            throw new RuntimeException("Adding null object");
-        }
-        mCameras.add(c);
-    }
-
-    public Camera appendNewCamera() {
-        Camera c = new Camera();
-        appendCamera(c);
-        return c;
-    }
-
-    public void appendShader(FragmentShader f) {
-        if (f == null) {
-            throw new RuntimeException("Adding null object");
-        }
-        mFragmentShaders.add(f);
-    }
-
-    public void appendShader(VertexShader v) {
-        if (v == null) {
-            throw new RuntimeException("Adding null object");
-        }
-        mVertexShaders.add(v);
-    }
-
-    public ArrayList<Camera> getCameras() {
-        return mCameras;
-    }
-
-    public ArrayList<LightBase> getLights() {
-        return mLights;
-    }
-
-    public void appendRenderable(RenderableBase d) {
-        if (d == null) {
-            throw new RuntimeException("Adding null object");
-        }
-        mRenderables.add(d);
-        if (d.getName() != null) {
-            mRenderableMap.put(d.getName(), d);
-        }
-    }
-
-    public Renderable appendNewRenderable() {
-        Renderable r = new Renderable();
-        appendRenderable(r);
-        return r;
-    }
-
-    public ArrayList<RenderableBase> getRenderables() {
-        return mRenderables;
-    }
-
-    public RenderableBase getRenderableByName(String name) {
-        return mRenderableMap.get(name);
-    }
-
-    public void appendTextures(Texture2D tex) {
-        if (tex == null) {
-            throw new RuntimeException("Adding null object");
-        }
-        mTextures.add(tex);
-    }
-
-    public void assignRenderStateToMaterial(RenderState renderState, String regex) {
-        Pattern pattern = Pattern.compile(regex);
-        int numRenderables = mRenderables.size();
-        for (int i = 0; i < numRenderables; i ++) {
-            Renderable shape = (Renderable)mRenderables.get(i);
-            Matcher m = pattern.matcher(shape.mMaterialName);
-            if (m.find()) {
-                shape.setRenderState(renderState);
-            }
-        }
-    }
-
-    public void assignRenderState(RenderState renderState) {
-        int numRenderables = mRenderables.size();
-        for (int i = 0; i < numRenderables; i ++) {
-            Renderable shape = (Renderable)mRenderables.get(i);
-            shape.setRenderState(renderState);
-        }
-    }
-
-    public void meshLoaded(Mesh m) {
-        ArrayList<Renderable> entries = mRenderableMeshMap.get(m.getName());
-        int numEntries = entries.size();
-        for (int i = 0; i < numEntries; i++) {
-            Renderable d = entries.get(i);
-            d.resolveMeshData(m);
-        }
-    }
-
-    void addToMeshMap(Renderable d) {
-        ArrayList<Renderable> entries = mRenderableMeshMap.get(d.mMeshName);
-        if (entries == null) {
-            entries = new ArrayList<Renderable>();
-            mRenderableMeshMap.put(d.mMeshName, entries);
-        }
-        entries.add(d);
-    }
-
-    public void destroyRS() {
-        SceneManager sceneManager = SceneManager.getInstance();
-        mTransformRSData = null;
-        sceneManager.mRenderLoop.bind_gRootNode(mTransformRSData);
-        sceneManager.mRenderLoop.set_gRenderableObjects(null);
-        mRenderPassAlloc = null;
-        sceneManager.mRenderLoop.set_gRenderPasses(null);
-        sceneManager.mRenderLoop.bind_gFrontToBack(null);
-        sceneManager.mRenderLoop.bind_gBackToFront(null);
-        sceneManager.mRenderLoop.set_gCameras(null);
-
-        mTransformMap = null;
-        mRenderPasses = null;
-        mLights = null;
-        mCameras = null;
-        mRenderables = null;
-        mRenderableMap = null;
-        mTextures = null;
-        mRenderableMeshMap = null;
-        mRootTransforms = null;
-    }
-
-    public void initRenderPassRS(RenderScriptGL rs, SceneManager sceneManager) {
-        if (mRenderPasses.size() != 0) {
-            mRenderPassAlloc = new ScriptField_RenderPass_s(mRS, mRenderPasses.size());
-            for (int i = 0; i < mRenderPasses.size(); i ++) {
-                mRenderPassAlloc.set(mRenderPasses.get(i).getRsField(mRS, mRes), i, false);
-            }
-            mRenderPassAlloc.copyAll();
-            sceneManager.mRenderLoop.set_gRenderPasses(mRenderPassAlloc.getAllocation());
-        }
-    }
-
-    private void addDrawables(RenderScriptGL rs, Resources res, SceneManager sceneManager) {
-        Allocation drawableData = Allocation.createSized(rs,
-                                                         Element.ALLOCATION(rs),
-                                                         mRenderables.size());
-        Allocation[] drawableAllocs = new Allocation[mRenderables.size()];
-        for (int i = 0; i < mRenderables.size(); i ++) {
-            Renderable dI = (Renderable)mRenderables.get(i);
-            addToMeshMap(dI);
-            drawableAllocs[i] = dI.getRsField(rs, res).getAllocation();
-        }
-        drawableData.copyFrom(drawableAllocs);
-        sceneManager.mRenderLoop.set_gRenderableObjects(drawableData);
-
-        initRenderPassRS(rs, sceneManager);
-    }
-
-    private void addShaders(RenderScriptGL rs, Resources res, SceneManager sceneManager) {
-        if (mVertexShaders.size() > 0) {
-            Allocation shaderData = Allocation.createSized(rs, Element.ALLOCATION(rs),
-                                                           mVertexShaders.size());
-            Allocation[] shaderAllocs = new Allocation[mVertexShaders.size()];
-            for (int i = 0; i < mVertexShaders.size(); i ++) {
-                VertexShader sI = mVertexShaders.get(i);
-                shaderAllocs[i] = sI.getRSData().getAllocation();
-            }
-            shaderData.copyFrom(shaderAllocs);
-            sceneManager.mRenderLoop.set_gVertexShaders(shaderData);
-        }
-
-        if (mFragmentShaders.size() > 0) {
-            Allocation shaderData = Allocation.createSized(rs, Element.ALLOCATION(rs),
-                                                           mFragmentShaders.size());
-            Allocation[] shaderAllocs = new Allocation[mFragmentShaders.size()];
-            for (int i = 0; i < mFragmentShaders.size(); i ++) {
-                FragmentShader sI = mFragmentShaders.get(i);
-                shaderAllocs[i] = sI.getRSData().getAllocation();
-            }
-            shaderData.copyFrom(shaderAllocs);
-            sceneManager.mRenderLoop.set_gFragmentShaders(shaderData);
-        }
-    }
-
-    public void initRS() {
-        SceneManager sceneManager = SceneManager.getInstance();
-        mRS = SceneManager.getRS();
-        mRes = SceneManager.getRes();
-        long start = System.currentTimeMillis();
-        mTransformRSData = mRootTransforms.getRSData();
-        long end = System.currentTimeMillis();
-        Log.v(TIMER_TAG, "Transform init time: " + (end - start));
-
-        start = System.currentTimeMillis();
-
-        sceneManager.mRenderLoop.bind_gRootNode(mTransformRSData);
-        end = System.currentTimeMillis();
-        Log.v(TIMER_TAG, "Script init time: " + (end - start));
-
-        start = System.currentTimeMillis();
-        addDrawables(mRS, mRes, sceneManager);
-        end = System.currentTimeMillis();
-        Log.v(TIMER_TAG, "Renderable init time: " + (end - start));
-
-        addShaders(mRS, mRes, sceneManager);
-
-        Allocation opaqueBuffer = null;
-        if (mRenderables.size() > 0) {
-            opaqueBuffer = Allocation.createSized(mRS, Element.U32(mRS), mRenderables.size());
-        }
-        Allocation transparentBuffer = null;
-        if (mRenderables.size() > 0) {
-            transparentBuffer = Allocation.createSized(mRS, Element.U32(mRS), mRenderables.size());
-        }
-
-        sceneManager.mRenderLoop.bind_gFrontToBack(opaqueBuffer);
-        sceneManager.mRenderLoop.bind_gBackToFront(transparentBuffer);
-
-        if (mCameras.size() > 0) {
-            Allocation cameraData;
-            cameraData = Allocation.createSized(mRS, Element.ALLOCATION(mRS), mCameras.size());
-            Allocation[] cameraAllocs = new Allocation[mCameras.size()];
-            for (int i = 0; i < mCameras.size(); i ++) {
-                cameraAllocs[i] = mCameras.get(i).getRSData().getAllocation();
-            }
-            cameraData.copyFrom(cameraAllocs);
-            sceneManager.mRenderLoop.set_gCameras(cameraData);
-        }
-
-        if (mLights.size() > 0) {
-            Allocation lightData = Allocation.createSized(mRS,
-                                                          Element.ALLOCATION(mRS),
-                                                          mLights.size());
-            Allocation[] lightAllocs = new Allocation[mLights.size()];
-            for (int i = 0; i < mLights.size(); i ++) {
-                lightAllocs[i] = mLights.get(i).getRSData().getAllocation();
-            }
-            lightData.copyFrom(lightAllocs);
-            sceneManager.mRenderLoop.set_gLights(lightData);
-        }
-    }
-}
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneGraphBase.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneGraphBase.java
deleted file mode 100644
index 412ffbf..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneGraphBase.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import com.android.scenegraph.SceneManager;
-
-import android.renderscript.Allocation;
-import android.renderscript.Element;
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.renderscript.RSRuntimeException;
-import android.renderscript.RenderScript;
-import android.renderscript.RenderScriptGL;
-import android.util.Log;
-
-/**
- * @hide
- */
-public abstract class SceneGraphBase {
-    String mName;
-    Allocation mNameAlloc;
-    public void setName(String n) {
-        mName = n;
-        mNameAlloc = null;
-    }
-
-    public String getName() {
-        return mName;
-    }
-
-    Allocation getNameAlloc(RenderScriptGL rs) {
-        if (mNameAlloc == null)  {
-            mNameAlloc = SceneManager.getStringAsAllocation(rs, getName());
-        }
-        return mNameAlloc;
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
deleted file mode 100644
index 4ff2c8b..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
+++ /dev/null
@@ -1,503 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Writer;
-import java.lang.Math;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import com.android.scenegraph.Camera;
-import com.android.scenegraph.FragmentShader;
-import com.android.scenegraph.MatrixTransform;
-import com.android.scenegraph.Scene;
-import com.android.scenegraph.VertexShader;
-import com.android.testapp.R;
-
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.os.AsyncTask;
-import android.renderscript.*;
-import android.renderscript.Allocation.MipmapControl;
-import android.renderscript.Mesh;
-import android.renderscript.RenderScriptGL;
-import android.util.Log;
-import android.view.SurfaceHolder;
-
-/**
- * @hide
- */
-public class SceneManager extends SceneGraphBase {
-
-    HashMap<String, Allocation> mAllocationMap;
-
-    ScriptC_render mRenderLoop;
-    ScriptC mCameraScript;
-    ScriptC mLightScript;
-    ScriptC mObjectParamsScript;
-    ScriptC mFragmentParamsScript;
-    ScriptC mVertexParamsScript;
-    ScriptC mCullScript;
-    ScriptC_transform mTransformScript;
-    ScriptC_export mExportScript;
-
-    RenderScriptGL mRS;
-    Resources mRes;
-    Mesh mQuad;
-    int mWidth;
-    int mHeight;
-
-    Scene mActiveScene;
-    private static SceneManager sSceneManager;
-
-    private Allocation mDefault2D;
-    private Allocation mDefaultCube;
-
-    private FragmentShader mColor;
-    private FragmentShader mTexture;
-    private VertexShader mDefaultVertex;
-
-    private RenderState mDefaultState;
-    private Transform mDefaultTransform;
-
-    private static Allocation getDefault(boolean isCube) {
-        final int dimension = 4;
-        final int bytesPerPixel = 4;
-        int arraySize = dimension * dimension * bytesPerPixel;
-
-        RenderScriptGL rs = sSceneManager.mRS;
-        Type.Builder b = new Type.Builder(rs, Element.RGBA_8888(rs));
-        b.setX(dimension).setY(dimension);
-        if (isCube) {
-            b.setFaces(true);
-            arraySize *= 6;
-        }
-        Type bitmapType = b.create();
-
-        Allocation.MipmapControl mip = Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE;
-        int usage =  Allocation.USAGE_GRAPHICS_TEXTURE;
-        Allocation defaultImage = Allocation.createTyped(rs, bitmapType, mip, usage);
-
-        byte imageData[] = new byte[arraySize];
-        defaultImage.copyFrom(imageData);
-        return defaultImage;
-    }
-
-    static Allocation getDefaultTex2D() {
-        if (sSceneManager == null) {
-            return null;
-        }
-        if (sSceneManager.mDefault2D == null) {
-            sSceneManager.mDefault2D = getDefault(false);
-        }
-        return sSceneManager.mDefault2D;
-    }
-
-    static Allocation getDefaultTexCube() {
-        if (sSceneManager == null) {
-            return null;
-        }
-        if (sSceneManager.mDefaultCube == null) {
-            sSceneManager.mDefaultCube = getDefault(true);
-        }
-        return sSceneManager.mDefaultCube;
-    }
-
-    public static boolean isSDCardPath(String path) {
-        int sdCardIndex = path.indexOf("sdcard/");
-        // We are looking for /sdcard/ or sdcard/
-        if (sdCardIndex == 0 || sdCardIndex == 1) {
-            return true;
-        }
-        sdCardIndex = path.indexOf("mnt/sdcard/");
-        if (sdCardIndex == 0 || sdCardIndex == 1) {
-            return true;
-        }
-        return false;
-    }
-
-    static Bitmap loadBitmap(String name, Resources res) {
-        InputStream is = null;
-        boolean loadFromSD = isSDCardPath(name);
-        try {
-            if (!loadFromSD) {
-                is = res.getAssets().open(name);
-            } else {
-                File f = new File(name);
-                is = new BufferedInputStream(new FileInputStream(f));
-            }
-        } catch (IOException e) {
-            Log.e("ImageLoaderTask", " Message: " + e.getMessage());
-            return null;
-        }
-
-        Bitmap b = BitmapFactory.decodeStream(is);
-        try {
-            is.close();
-        } catch (IOException e) {
-            Log.e("ImageLoaderTask", " Message: " + e.getMessage());
-        }
-        return b;
-    }
-
-    static Allocation createFromBitmap(Bitmap b, RenderScriptGL rs, boolean isCube) {
-        if (b == null) {
-            return null;
-        }
-        MipmapControl mip = MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE;
-        int usage = Allocation.USAGE_GRAPHICS_TEXTURE;
-        if (isCube) {
-            return Allocation.createCubemapFromBitmap(rs, b, mip, usage);
-        }
-        return Allocation.createFromBitmap(rs, b, mip, usage);
-    }
-
-    public static Allocation loadCubemap(String name, RenderScriptGL rs, Resources res) {
-        return createFromBitmap(loadBitmap(name, res), rs, true);
-    }
-
-    public static Allocation loadCubemap(int id, RenderScriptGL rs, Resources res) {
-        return createFromBitmap(BitmapFactory.decodeResource(res, id), rs, true);
-    }
-
-    public static Allocation loadTexture2D(String name, RenderScriptGL rs, Resources res) {
-        return createFromBitmap(loadBitmap(name, res), rs, false);
-    }
-
-    public static Allocation loadTexture2D(int id, RenderScriptGL rs, Resources res) {
-        return createFromBitmap(BitmapFactory.decodeResource(res, id), rs, false);
-    }
-
-    public static ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) {
-        ProgramStore.Builder builder = new ProgramStore.Builder(rs);
-        builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
-        builder.setBlendFunc(ProgramStore.BlendSrcFunc.ONE, ProgramStore.BlendDstFunc.ONE);
-        builder.setDitherEnabled(false);
-        builder.setDepthMaskEnabled(false);
-        return builder.create();
-    }
-
-    static Allocation getStringAsAllocation(RenderScript rs, String str) {
-        if (str == null) {
-            return null;
-        }
-        if (str.length() == 0) {
-            return null;
-        }
-        byte[] allocArray = null;
-        byte[] nullChar = new byte[1];
-        nullChar[0] = 0;
-        try {
-            allocArray = str.getBytes("UTF-8");
-            Allocation alloc = Allocation.createSized(rs, Element.U8(rs),
-                                                      allocArray.length + 1,
-                                                      Allocation.USAGE_SCRIPT);
-            alloc.copy1DRangeFrom(0, allocArray.length, allocArray);
-            alloc.copy1DRangeFrom(allocArray.length, 1, nullChar);
-            return alloc;
-        }
-        catch (Exception e) {
-            throw new RSRuntimeException("Could not convert string to utf-8.");
-        }
-    }
-
-    static Allocation getCachedAlloc(String str) {
-        if (sSceneManager == null) {
-            throw new RuntimeException("Scene manager not initialized");
-        }
-        return sSceneManager.mAllocationMap.get(str);
-    }
-
-    static void cacheAlloc(String str, Allocation alloc) {
-        if (sSceneManager == null) {
-            throw new RuntimeException("Scene manager not initialized");
-        }
-        sSceneManager.mAllocationMap.put(str, alloc);
-    }
-
-    public static class SceneLoadedCallback implements Runnable {
-        public Scene mLoadedScene;
-        public String mName;
-        public void run() {
-        }
-    }
-
-    public Scene getActiveScene() {
-        return mActiveScene;
-    }
-
-    public void setActiveScene(Scene s) {
-        mActiveScene = s;
-
-        if (mActiveScene == null) {
-            return;
-        }
-
-        // Do some sanity checking
-        if (mActiveScene.getCameras().size() == 0) {
-            Matrix4f camPos = new Matrix4f();
-            camPos.translate(0, 0, 10);
-            MatrixTransform cameraTransform = new MatrixTransform();
-            cameraTransform.setName("_DefaultCameraTransform");
-            cameraTransform.setMatrix(camPos);
-            mActiveScene.appendTransform(cameraTransform);
-            Camera cam = new Camera();
-            cam.setName("_DefaultCamera");
-            cam.setTransform(cameraTransform);
-            mActiveScene.appendCamera(cam);
-        }
-
-        mActiveScene.appendShader(getDefaultVS());
-        mActiveScene.appendTransform(getDefaultTransform());
-    }
-
-    static RenderScriptGL getRS() {
-        if (sSceneManager == null) {
-            return null;
-        }
-        return sSceneManager.mRS;
-    }
-
-    static Resources getRes() {
-        if (sSceneManager == null) {
-            return null;
-        }
-        return sSceneManager.mRes;
-    }
-
-    // Provides the folowing inputs to fragment shader
-    // Assigned by default if nothing is present
-    // vec3 varWorldPos;
-    // vec3 varWorldNormal;
-    // vec2 varTex0;
-    public static VertexShader getDefaultVS() {
-        if (sSceneManager == null) {
-            return null;
-        }
-
-        if (sSceneManager.mDefaultVertex == null) {
-            RenderScriptGL rs = getRS();
-            Element.Builder b = new Element.Builder(rs);
-            b.add(Element.MATRIX_4X4(rs), "model");
-            Type.Builder objConstBuilder = new Type.Builder(rs, b.create());
-
-            b = new Element.Builder(rs);
-            b.add(Element.MATRIX_4X4(rs), "viewProj");
-            Type.Builder shaderConstBuilder = new Type.Builder(rs, b.create());
-
-            b = new Element.Builder(rs);
-            b.add(Element.F32_4(rs), "position");
-            b.add(Element.F32_2(rs), "texture0");
-            b.add(Element.F32_3(rs), "normal");
-            Element defaultIn = b.create();
-
-            final String code = "\n" +
-                "varying vec3 varWorldPos;\n" +
-                "varying vec3 varWorldNormal;\n" +
-                "varying vec2 varTex0;\n" +
-                "void main() {" +
-                "   vec4 objPos = ATTRIB_position;\n" +
-                "   vec4 worldPos = UNI_model * objPos;\n" +
-                "   gl_Position = UNI_viewProj * worldPos;\n" +
-                "   mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);\n" +
-                "   vec3 worldNorm = model3 * ATTRIB_normal;\n" +
-                "   varWorldPos = worldPos.xyz;\n" +
-                "   varWorldNormal = worldNorm;\n" +
-                "   varTex0 = ATTRIB_texture0;\n" +
-                "}\n";
-
-            VertexShader.Builder sb = new VertexShader.Builder(rs);
-            sb.addInput(defaultIn);
-            sb.setObjectConst(objConstBuilder.setX(1).create());
-            sb.setShaderConst(shaderConstBuilder.setX(1).create());
-            sb.setShader(code);
-            sSceneManager.mDefaultVertex = sb.create();
-        }
-
-        return sSceneManager.mDefaultVertex;
-    }
-
-    public static FragmentShader getColorFS() {
-        if (sSceneManager == null) {
-            return null;
-        }
-        if (sSceneManager.mColor == null) {
-            RenderScriptGL rs = getRS();
-            Element.Builder b = new Element.Builder(rs);
-            b.add(Element.F32_4(rs), "color");
-            Type.Builder objConstBuilder = new Type.Builder(rs, b.create());
-
-            final String code = "\n" +
-                "varying vec2 varTex0;\n" +
-                "void main() {\n" +
-                "   lowp vec4 col = UNI_color;\n" +
-                "   gl_FragColor = col;\n" +
-                "}\n";
-            FragmentShader.Builder fb = new FragmentShader.Builder(rs);
-            fb.setShader(code);
-            fb.setObjectConst(objConstBuilder.create());
-            sSceneManager.mColor = fb.create();
-        }
-
-        return sSceneManager.mColor;
-    }
-
-    public static FragmentShader getTextureFS() {
-        if (sSceneManager == null) {
-            return null;
-        }
-        if (sSceneManager.mTexture == null) {
-            RenderScriptGL rs = getRS();
-
-            final String code = "\n" +
-                "varying vec2 varTex0;\n" +
-                "void main() {\n" +
-                "   lowp vec4 col = texture2D(UNI_color, varTex0).rgba;\n" +
-                "   gl_FragColor = col;\n" +
-                "}\n";
-
-            FragmentShader.Builder fb = new FragmentShader.Builder(rs);
-            fb.setShader(code);
-            fb.addTexture(Program.TextureType.TEXTURE_2D, "color");
-            sSceneManager.mTexture = fb.create();
-            sSceneManager.mTexture.mProgram.bindSampler(Sampler.CLAMP_LINEAR_MIP_LINEAR(rs), 0);
-        }
-
-        return sSceneManager.mTexture;
-    }
-
-    static RenderState getDefaultState() {
-        if (sSceneManager == null) {
-            return null;
-        }
-        if (sSceneManager.mDefaultState == null) {
-            sSceneManager.mDefaultState = new RenderState(getDefaultVS(), getColorFS(), null, null);
-            sSceneManager.mDefaultState.setName("__DefaultState");
-        }
-        return sSceneManager.mDefaultState;
-    }
-
-    static Transform getDefaultTransform() {
-        if (sSceneManager == null) {
-            return null;
-        }
-        if (sSceneManager.mDefaultTransform == null) {
-            sSceneManager.mDefaultTransform = new MatrixTransform();
-            sSceneManager.mDefaultTransform.setName("__DefaultTransform");
-        }
-        return sSceneManager.mDefaultTransform;
-    }
-
-    public static SceneManager getInstance() {
-        if (sSceneManager == null) {
-            sSceneManager = new SceneManager();
-        }
-        return sSceneManager;
-    }
-
-    protected SceneManager() {
-    }
-
-    public void loadModel(String name, SceneLoadedCallback cb) {
-        ColladaScene scene = new ColladaScene(name, cb);
-        scene.init(mRS, mRes);
-    }
-
-    public Mesh getScreenAlignedQuad() {
-        if (mQuad != null) {
-            return mQuad;
-        }
-
-        Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS,
-                                           3, Mesh.TriangleMeshBuilder.TEXTURE_0);
-
-        tmb.setTexture(0.0f, 1.0f).addVertex(-1.0f, 1.0f, 1.0f);
-        tmb.setTexture(0.0f, 0.0f).addVertex(-1.0f, -1.0f, 1.0f);
-        tmb.setTexture(1.0f, 0.0f).addVertex(1.0f, -1.0f, 1.0f);
-        tmb.setTexture(1.0f, 1.0f).addVertex(1.0f, 1.0f, 1.0f);
-
-        tmb.addTriangle(0, 1, 2);
-        tmb.addTriangle(2, 3, 0);
-
-        mQuad = tmb.create(true);
-        return mQuad;
-    }
-
-    public Renderable getRenderableQuad(String name, RenderState state) {
-        Renderable quad = new Renderable();
-        quad.setTransform(new MatrixTransform());
-        quad.setMesh(getScreenAlignedQuad());
-        quad.setName(name);
-        quad.setRenderState(state);
-        quad.setCullType(1);
-        return quad;
-    }
-
-    public void initRS(RenderScriptGL rs, Resources res, int w, int h) {
-        mRS = rs;
-        mRes = res;
-        mAllocationMap = new HashMap<String, Allocation>();
-
-        mQuad = null;
-        mDefault2D = null;
-        mDefaultCube = null;
-        mDefaultVertex = null;
-        mColor = null;
-        mTexture = null;
-        mDefaultState = null;
-        mDefaultTransform = null;
-
-        mExportScript = new ScriptC_export(rs, res, R.raw.export);
-
-        mTransformScript = new ScriptC_transform(rs, res, R.raw.transform);
-        mTransformScript.set_gTransformScript(mTransformScript);
-
-        mCameraScript = new ScriptC_camera(rs, res, R.raw.camera);
-        mLightScript = new ScriptC_light(rs, res, R.raw.light);
-        mObjectParamsScript = new ScriptC_object_params(rs, res, R.raw.object_params);
-        mFragmentParamsScript = new ScriptC_object_params(rs, res, R.raw.fragment_params);
-        mVertexParamsScript = new ScriptC_object_params(rs, res, R.raw.vertex_params);
-        mCullScript = new ScriptC_cull(rs, res, R.raw.cull);
-
-        mRenderLoop = new ScriptC_render(rs, res, R.raw.render);
-        mRenderLoop.set_gTransformScript(mTransformScript);
-        mRenderLoop.set_gCameraScript(mCameraScript);
-        mRenderLoop.set_gLightScript(mLightScript);
-        mRenderLoop.set_gObjectParamsScript(mObjectParamsScript);
-        mRenderLoop.set_gFragmentParamsScript(mFragmentParamsScript);
-        mRenderLoop.set_gVertexParamsScript(mVertexParamsScript);
-        mRenderLoop.set_gCullScript(mCullScript);
-
-        mRenderLoop.set_gPFSBackground(ProgramStore.BLEND_NONE_DEPTH_TEST(mRS));
-    }
-
-    public ScriptC getRenderLoop() {
-        return mRenderLoop;
-    }
-}
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java
deleted file mode 100644
index 4975114..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import com.android.scenegraph.SceneGraphBase;
-import com.android.scenegraph.ShaderParam;
-
-import android.renderscript.*;
-import android.renderscript.ProgramFragment.Builder;
-import android.util.Log;
-
-/**
- * @hide
- */
-public abstract class Shader extends SceneGraphBase {
-    protected Type mPerObjConstants;
-    protected Type mPerShaderConstants;
-
-    protected HashMap<String, ShaderParam> mSourceParams;
-    protected ArrayList<String> mShaderTextureNames;
-    protected ArrayList<Program.TextureType > mShaderTextureTypes;
-    protected ArrayList<String> mTextureNames;
-    protected ArrayList<Program.TextureType > mTextureTypes;
-
-    protected Allocation mConstantBuffer;
-    protected ScriptField_ShaderParam_s mConstantBufferParams;
-
-    public Shader() {
-        mSourceParams = new HashMap<String, ShaderParam>();
-        mShaderTextureNames = new ArrayList<String>();
-        mShaderTextureTypes = new ArrayList<Program.TextureType>();
-        mTextureNames = new ArrayList<String>();
-        mTextureTypes = new ArrayList<Program.TextureType>();
-    }
-
-    public void appendSourceParams(ShaderParam p) {
-        mSourceParams.put(p.getParamName(), p);
-    }
-
-    public Type getObjectConstants() {
-        return mPerObjConstants;
-    }
-
-    public Type getShaderConstants() {
-        return mPerObjConstants;
-    }
-
-    void linkConstants(RenderScriptGL rs) {
-        if (mPerShaderConstants == null) {
-            return;
-        }
-
-        Element constElem = mPerShaderConstants.getElement();
-        mConstantBufferParams  = ShaderParam.fillInParams(constElem, mSourceParams, null);
-
-        mConstantBuffer = Allocation.createTyped(rs, mPerShaderConstants);
-    }
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java
deleted file mode 100644
index 3dd41ca..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import com.android.scenegraph.SceneManager;
-import com.android.scenegraph.Transform;
-
-import android.renderscript.Element;
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.renderscript.RenderScriptGL;
-import android.util.Log;
-
-/**
- * @hide
- */
-public abstract class ShaderParam extends SceneGraphBase {
-
-    static final String cameraPos        = "cameraPos";
-    static final String cameraDir        = "cameraDir";
-
-    static final String lightColor       = "lightColor";
-    static final String lightPos         = "lightPos";
-    static final String lightDir         = "lightDir";
-
-    static final String view             = "view";
-    static final String proj             = "proj";
-    static final String viewProj         = "viewProj";
-    static final String model            = "model";
-    static final String modelView        = "modelView";
-    static final String modelViewProj    = "modelViewProj";
-
-    static final long sMaxTimeStamp = 0xffffffffL;
-
-    ScriptField_ShaderParamData_s.Item mData;
-    ScriptField_ShaderParamData_s mField;
-
-    String mParamName;
-    Camera mCamera;
-
-    static ScriptField_ShaderParam_s fillInParams(Element constantElem,
-                                                  HashMap<String, ShaderParam> sourceParams,
-                                                  Transform transform) {
-        RenderScriptGL rs = SceneManager.getRS();
-        ArrayList<ScriptField_ShaderParam_s.Item> paramList;
-        paramList = new ArrayList<ScriptField_ShaderParam_s.Item>();
-
-        int subElemCount = constantElem.getSubElementCount();
-        for (int i = 0; i < subElemCount; i ++) {
-            String inputName = constantElem.getSubElementName(i);
-            int offset = constantElem.getSubElementOffsetBytes(i);
-
-            ShaderParam matchingParam = sourceParams.get(inputName);
-            Element subElem = constantElem.getSubElement(i);
-            // Make one if it's not there
-            if (matchingParam == null) {
-                if (subElem.getDataType() == Element.DataType.FLOAT_32) {
-                    matchingParam = new Float4Param(inputName, 0.5f, 0.5f, 0.5f, 0.5f);
-                } else if (subElem.getDataType() == Element.DataType.MATRIX_4X4) {
-                    TransformParam trParam = new TransformParam(inputName);
-                    trParam.setTransform(transform);
-                    matchingParam = trParam;
-                }
-            }
-            ScriptField_ShaderParam_s.Item paramRS = new ScriptField_ShaderParam_s.Item();
-            paramRS.bufferOffset = offset;
-            paramRS.transformTimestamp = 0;
-            paramRS.dataTimestamp = 0;
-            paramRS.data = matchingParam.getRSData().getAllocation();
-            if (subElem.getDataType() == Element.DataType.FLOAT_32) {
-                paramRS.float_vecSize = subElem.getVectorSize();
-            }
-
-            paramList.add(paramRS);
-        }
-
-        ScriptField_ShaderParam_s rsParams = null;
-        int paramCount = paramList.size();
-        if (paramCount != 0) {
-            rsParams = new ScriptField_ShaderParam_s(rs, paramCount);
-            for (int i = 0; i < paramCount; i++) {
-                rsParams.set(paramList.get(i), i, false);
-            }
-            rsParams.copyAll();
-        }
-        return rsParams;
-    }
-
-    public ShaderParam(String name) {
-        mParamName = name;
-        mData = new ScriptField_ShaderParamData_s.Item();
-    }
-
-    public String getParamName() {
-        return mParamName;
-    }
-
-    public void setCamera(Camera c) {
-        mCamera = c;
-        if (mField != null) {
-            mData.camera = mCamera.getRSData().getAllocation();
-            mField.set_camera(0, mData.camera, true);
-        }
-    }
-
-    protected void incTimestamp() {
-        if (mField != null) {
-            mData.timestamp ++;
-            mData.timestamp %= sMaxTimeStamp;
-            mField.set_timestamp(0, mData.timestamp, true);
-        }
-    }
-
-    abstract void initLocalData();
-
-    public ScriptField_ShaderParamData_s getRSData() {
-        if (mField != null) {
-            return mField;
-        }
-
-        RenderScriptGL rs = SceneManager.getRS();
-        mField = new ScriptField_ShaderParamData_s(rs, 1);
-
-        if (mParamName != null) {
-            mData.paramName = SceneManager.getCachedAlloc(mParamName);
-            if (mData.paramName == null) {
-                mData.paramName = SceneManager.getStringAsAllocation(rs, mParamName);
-                SceneManager.cacheAlloc(mParamName, mData.paramName);
-            }
-        }
-        initLocalData();
-        mData.timestamp = 1;
-
-        mField.set(mData, 0, true);
-        return mField;
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
deleted file mode 100644
index b53ab88..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-
-import com.android.scenegraph.SceneManager;
-
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class Texture2D extends TextureBase {
-    String mFileName;
-    String mFileDir;
-    int mResourceID;
-
-    public Texture2D() {
-        super(ScriptC_export.const_TextureType_TEXTURE_2D);
-    }
-
-    public Texture2D(Allocation tex) {
-        super(ScriptC_export.const_TextureType_TEXTURE_2D);
-        setTexture(tex);
-    }
-
-    public Texture2D(String dir, String file) {
-        super(ScriptC_export.const_TextureType_TEXTURE_CUBE);
-        setFileDir(dir);
-        setFileName(file);
-    }
-
-    public Texture2D(int resourceID) {
-        super(ScriptC_export.const_TextureType_TEXTURE_2D);
-        mResourceID = resourceID;
-    }
-
-    public void setFileDir(String dir) {
-        mFileDir = dir;
-    }
-
-    public void setFileName(String file) {
-        mFileName = file;
-    }
-
-    public String getFileName() {
-        return mFileName;
-    }
-
-    public void setTexture(Allocation tex) {
-        mData.texture = tex != null ? tex : SceneManager.getDefaultTex2D();
-        if (mField != null) {
-            mField.set_texture(0, mData.texture, true);
-        }
-    }
-
-    void load() {
-        RenderScriptGL rs = SceneManager.getRS();
-        Resources res = SceneManager.getRes();
-        if (mFileName != null && mFileName.length() > 0) {
-            String shortName = mFileName.substring(mFileName.lastIndexOf('/') + 1);
-            setTexture(SceneManager.loadTexture2D(mFileDir + shortName, rs, res));
-        } else if (mResourceID != 0) {
-            setTexture(SceneManager.loadTexture2D(mResourceID, rs, res));
-        }
-    }
-
-    ScriptField_Texture_s getRsData(boolean loadNow) {
-        if (mField != null) {
-            return mField;
-        }
-
-        RenderScriptGL rs = SceneManager.getRS();
-        Resources res = SceneManager.getRes();
-        if (rs == null || res == null) {
-            return null;
-        }
-
-        mField = new ScriptField_Texture_s(rs, 1);
-
-        if (loadNow) {
-            load();
-        } else {
-            mData.texture = SceneManager.getDefaultTex2D();
-            new SingleImageLoaderTask().execute(this);
-        }
-
-        mField.set(mData, 0, true);
-        return mField;
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureBase.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureBase.java
deleted file mode 100644
index ba49d4e..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureBase.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-
-import com.android.scenegraph.SceneManager;
-import android.os.AsyncTask;
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.util.Log;
-
-/**
- * @hide
- */
-public abstract class TextureBase extends SceneGraphBase {
-
-    class SingleImageLoaderTask extends AsyncTask<TextureBase, Void, Boolean> {
-        protected Boolean doInBackground(TextureBase... objects) {
-            TextureBase tex = objects[0];
-            tex.load();
-            return new Boolean(true);
-        }
-        protected void onPostExecute(Boolean result) {
-        }
-    }
-
-    ScriptField_Texture_s.Item mData;
-    ScriptField_Texture_s mField;
-    TextureBase(int type) {
-        mData = new ScriptField_Texture_s.Item();
-        mData.type = type;
-    }
-
-    protected Allocation mRsTexture;
-    abstract ScriptField_Texture_s getRsData(boolean loadNow);
-    abstract void load();
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureCube.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureCube.java
deleted file mode 100644
index 1269e3c..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureCube.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-
-import com.android.scenegraph.SceneManager;
-import com.android.scenegraph.TextureBase;
-
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class TextureCube extends TextureBase {
-    String mFileName;
-    String mFileDir;
-    int mResourceID;
-
-    public TextureCube() {
-        super(ScriptC_export.const_TextureType_TEXTURE_CUBE);
-    }
-
-    public TextureCube(Allocation tex) {
-        super(ScriptC_export.const_TextureType_TEXTURE_CUBE);
-        setTexture(tex);
-    }
-
-    public TextureCube(String dir, String file) {
-        super(ScriptC_export.const_TextureType_TEXTURE_CUBE);
-        setFileDir(dir);
-        setFileName(file);
-    }
-
-    public TextureCube(int resourceID) {
-        super(ScriptC_export.const_TextureType_TEXTURE_2D);
-        mResourceID = resourceID;
-    }
-
-    public void setFileDir(String dir) {
-        mFileDir = dir;
-    }
-
-    public void setFileName(String file) {
-        mFileName = file;
-    }
-
-    public String getFileName() {
-        return mFileName;
-    }
-
-    public void setTexture(Allocation tex) {
-        mData.texture = tex != null ? tex : SceneManager.getDefaultTexCube();
-        if (mField != null) {
-            mField.set_texture(0, mData.texture, true);
-        }
-    }
-
-    void load() {
-        RenderScriptGL rs = SceneManager.getRS();
-        Resources res = SceneManager.getRes();
-        if (mFileName != null && mFileName.length() > 0) {
-            String shortName = mFileName.substring(mFileName.lastIndexOf('/') + 1);
-            setTexture(SceneManager.loadCubemap(mFileDir + shortName, rs, res));
-        } else if (mResourceID != 0) {
-            setTexture(SceneManager.loadCubemap(mResourceID , rs, res));
-        }
-    }
-
-    ScriptField_Texture_s getRsData(boolean loadNow) {
-        if (mField != null) {
-            return mField;
-        }
-
-        RenderScriptGL rs = SceneManager.getRS();
-        Resources res = SceneManager.getRes();
-        if (rs == null || res == null) {
-            return null;
-        }
-
-        mField = new ScriptField_Texture_s(rs, 1);
-
-        if (loadNow) {
-            load();
-        } else {
-            mData.texture = SceneManager.getDefaultTexCube();
-            new SingleImageLoaderTask().execute(this);
-        }
-
-        mField.set(mData, 0, true);
-        return mField;
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureParam.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureParam.java
deleted file mode 100644
index e656ed2..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureParam.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import android.graphics.Camera;
-import android.renderscript.RenderScriptGL;
-import android.renderscript.Float4;
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.renderscript.Element;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class TextureParam extends ShaderParam {
-
-    TextureBase mTexture;
-
-    public TextureParam(String name) {
-        super(name);
-    }
-
-    public TextureParam(String name, TextureBase t) {
-        super(name);
-        setTexture(t);
-    }
-
-    public void setTexture(TextureBase t) {
-        mTexture = t;
-    }
-
-    public TextureBase getTexture() {
-        return mTexture;
-    }
-
-    void initLocalData() {
-        mData.type = ScriptC_export.const_ShaderParam_TEXTURE;
-        if (mTexture != null) {
-            mData.texture = mTexture.getRsData(false).getAllocation();
-        }
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureRenderTarget.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureRenderTarget.java
deleted file mode 100644
index 6aa29a5..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureRenderTarget.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-
-import com.android.scenegraph.SceneManager;
-
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class TextureRenderTarget extends TextureBase {
-    public TextureRenderTarget() {
-        super(ScriptC_export.const_TextureType_TEXTURE_RENDER_TARGET);
-    }
-
-    public TextureRenderTarget(Allocation tex) {
-        super(ScriptC_export.const_TextureType_TEXTURE_RENDER_TARGET);
-        setTexture(tex);
-    }
-
-    public void setTexture(Allocation tex) {
-        mData.texture = tex;
-        if (mField != null) {
-            mField.set_texture(0, mData.texture, true);
-        }
-    }
-
-    void load() {
-    }
-
-    ScriptField_Texture_s getRsData(boolean loadNow) {
-        if (mField != null) {
-            return mField;
-        }
-
-        RenderScriptGL rs = SceneManager.getRS();
-        if (rs == null) {
-            return null;
-        }
-
-        mField = new ScriptField_Texture_s(rs, 1);
-        mField.set(mData, 0, true);
-        return mField;
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Transform.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Transform.java
deleted file mode 100644
index 8180bd0..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Transform.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import android.renderscript.*;
-import android.renderscript.Matrix4f;
-import android.util.Log;
-
-/**
- * @hide
- */
-public abstract class Transform extends SceneGraphBase {
-    Transform mParent;
-    ArrayList<Transform> mChildren;
-
-    ScriptField_SgTransform mField;
-    ScriptField_SgTransform.Item mTransformData;
-
-    public Transform() {
-        mChildren = new ArrayList<Transform>();
-        mParent = null;
-    }
-
-    public void appendChild(Transform t) {
-        mChildren.add(t);
-        t.mParent = this;
-        updateRSChildData(true);
-    }
-
-    abstract void initLocalData();
-
-    void updateRSChildData(boolean copyData) {
-        if (mField == null) {
-            return;
-        }
-        RenderScriptGL rs = SceneManager.getRS();
-        if (mChildren.size() != 0) {
-            Allocation childRSData = Allocation.createSized(rs, Element.ALLOCATION(rs),
-                                                            mChildren.size());
-            mTransformData.children = childRSData;
-
-            Allocation[] childrenAllocs = new Allocation[mChildren.size()];
-            for (int i = 0; i < mChildren.size(); i ++) {
-                Transform child = mChildren.get(i);
-                childrenAllocs[i] = child.getRSData().getAllocation();
-            }
-            childRSData.copyFrom(childrenAllocs);
-        }
-        if (copyData) {
-            mField.set(mTransformData, 0, true);
-        }
-    }
-
-    ScriptField_SgTransform getRSData() {
-        if (mField != null) {
-            return mField;
-        }
-
-        RenderScriptGL rs = SceneManager.getRS();
-        if (rs == null) {
-            return null;
-        }
-        mField = new ScriptField_SgTransform(rs, 1);
-
-        mTransformData = new ScriptField_SgTransform.Item();
-        mTransformData.name = getNameAlloc(rs);
-        mTransformData.isDirty = 1;
-        mTransformData.timestamp = 1;
-
-        initLocalData();
-        updateRSChildData(false);
-
-        mField.set(mTransformData, 0, true);
-        return mField;
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java
deleted file mode 100644
index d120d5d..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import android.renderscript.RenderScriptGL;
-import android.renderscript.Matrix4f;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.renderscript.Element;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class TransformParam extends ShaderParam {
-
-    Transform mTransform;
-    LightBase mLight;
-
-    public TransformParam(String name) {
-        super(name);
-    }
-
-    public void setTransform(Transform t) {
-        mTransform = t;
-        if (mField != null && mTransform != null) {
-            mData.transform = mTransform.getRSData().getAllocation();
-        }
-        incTimestamp();
-    }
-
-    int getTypeFromName() {
-        int paramType = ScriptC_export.const_ShaderParam_TRANSFORM_DATA;
-        if (mParamName.equalsIgnoreCase(view)) {
-            paramType = ScriptC_export.const_ShaderParam_TRANSFORM_VIEW;
-        } else if(mParamName.equalsIgnoreCase(proj)) {
-            paramType = ScriptC_export.const_ShaderParam_TRANSFORM_PROJ;
-        } else if(mParamName.equalsIgnoreCase(viewProj)) {
-            paramType = ScriptC_export.const_ShaderParam_TRANSFORM_VIEW_PROJ;
-        } else if(mParamName.equalsIgnoreCase(model)) {
-            paramType = ScriptC_export.const_ShaderParam_TRANSFORM_MODEL;
-        } else if(mParamName.equalsIgnoreCase(modelView)) {
-            paramType = ScriptC_export.const_ShaderParam_TRANSFORM_MODEL_VIEW;
-        } else if(mParamName.equalsIgnoreCase(modelViewProj)) {
-            paramType = ScriptC_export.const_ShaderParam_TRANSFORM_MODEL_VIEW_PROJ;
-        }
-        return paramType;
-    }
-
-    void initLocalData() {
-        mData.type = getTypeFromName();
-        if (mTransform != null) {
-            mData.transform = mTransform.getRSData().getAllocation();
-        }
-        if (mCamera != null) {
-            mData.camera = mCamera.getRSData().getAllocation();
-        }
-        if (mLight != null) {
-            mData.light = mLight.getRSData().getAllocation();
-        }
-    }
-}
-
-
-
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java
deleted file mode 100644
index 4efaff7..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.scenegraph;
-
-import java.lang.Math;
-import java.util.ArrayList;
-
-import android.content.res.Resources;
-import android.renderscript.*;
-import android.util.Log;
-
-/**
- * @hide
- */
-public class VertexShader extends Shader {
-    ProgramVertex mProgram;
-    ScriptField_VertexShader_s mField;
-
-    public static class Builder {
-        VertexShader mShader;
-        ProgramVertex.Builder mBuilder;
-
-        public Builder(RenderScriptGL rs) {
-            mShader = new VertexShader();
-            mBuilder = new ProgramVertex.Builder(rs);
-        }
-
-        public Builder setShader(Resources resources, int resourceID) {
-            mBuilder.setShader(resources, resourceID);
-            return this;
-        }
-
-        public Builder setShader(String code) {
-            mBuilder.setShader(code);
-            return this;
-        }
-
-        public Builder setObjectConst(Type type) {
-            mShader.mPerObjConstants = type;
-            return this;
-        }
-
-        public Builder setShaderConst(Type type) {
-            mShader.mPerShaderConstants = type;
-            return this;
-        }
-
-        public Builder addInput(Element e) {
-            mBuilder.addInput(e);
-            return this;
-        }
-
-        public VertexShader create() {
-            if (mShader.mPerShaderConstants != null) {
-                mBuilder.addConstant(mShader.mPerShaderConstants);
-            }
-            if (mShader.mPerObjConstants != null) {
-                mBuilder.addConstant(mShader.mPerObjConstants);
-            }
-            mShader.mProgram = mBuilder.create();
-            return mShader;
-        }
-    }
-
-    public ProgramVertex getProgram() {
-        return mProgram;
-    }
-
-    ScriptField_VertexShader_s getRSData() {
-        if (mField != null) {
-            return mField;
-        }
-
-        RenderScriptGL rs = SceneManager.getRS();
-        Resources res = SceneManager.getRes();
-        if (rs == null || res == null) {
-            return null;
-        }
-
-        ScriptField_VertexShader_s.Item item = new ScriptField_VertexShader_s.Item();
-        item.program = mProgram;
-
-        linkConstants(rs);
-        if (mPerShaderConstants != null) {
-            item.shaderConst = mConstantBuffer;
-            item.shaderConstParams = mConstantBufferParams.getAllocation();
-            mProgram.bindConstants(item.shaderConst, 0);
-        }
-
-        item.objectConstIndex = -1;
-        if (mPerObjConstants != null) {
-            item.objectConstIndex = mPerShaderConstants != null ? 1 : 0;
-        }
-
-        mField = new ScriptField_VertexShader_s(rs, 1);
-        mField.set(item, 0, true);
-        return mField;
-    }
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/camera.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/camera.rs
deleted file mode 100644
index dc0a885..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/camera.rs
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.scenegraph)
-
-//#define DEBUG_CAMERA
-#include "scenegraph_objects.rsh"
-
-void root(const rs_allocation *v_in, rs_allocation *v_out, const float *usrData) {
-
-    SgCamera *cam = (SgCamera *)rsGetElementAt(*v_in, 0);
-    float aspect = *usrData;
-    if (cam->aspect != aspect) {
-        cam->isDirty = 1;
-        cam->aspect = aspect;
-    }
-    if (cam->isDirty) {
-        rsMatrixLoadPerspective(&cam->proj, cam->horizontalFOV, cam->aspect, cam->near, cam->far);
-    }
-
-    const SgTransform *camTransform = (const SgTransform *)rsGetElementAt(cam->transformMatrix, 0);
-    //rsDebug("Camera stamp", cam->transformTimestamp);
-    //rsDebug("Transform stamp", camTransform->timestamp);
-    if (camTransform->timestamp != cam->transformTimestamp || cam->isDirty) {
-        cam->isDirty = 1;
-        rs_matrix4x4 camPosMatrix;
-        rsMatrixLoad(&camPosMatrix, &camTransform->globalMat);
-        float4 zero = {0.0f, 0.0f, 0.0f, 1.0f};
-        cam->position = rsMatrixMultiply(&camPosMatrix, zero);
-
-        rsMatrixInverse(&camPosMatrix);
-        rsMatrixLoad(&cam->view, &camPosMatrix);
-
-        rsMatrixLoad(&cam->viewProj, &cam->proj);
-        rsMatrixMultiply(&cam->viewProj, &cam->view);
-
-        rsExtractFrustumPlanes(&cam->viewProj,
-                               &cam->frustumPlanes[0], &cam->frustumPlanes[1],
-                               &cam->frustumPlanes[2], &cam->frustumPlanes[3],
-                               &cam->frustumPlanes[3], &cam->frustumPlanes[4]);
-    }
-
-    if (cam->isDirty) {
-        cam->timestamp ++;
-    }
-
-    cam->isDirty = 0;
-    cam->transformTimestamp = camTransform->timestamp;
-
-#ifdef DEBUG_CAMERA
-    printCameraInfo(cam);
-#endif //DEBUG_CAMERA
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs
deleted file mode 100644
index 024e026..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright (C) 2012 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.scenegraph)
-
-#include "scenegraph_objects.rsh"
-
-static void getTransformedSphere(SgRenderable *obj) {
-    obj->worldBoundingSphere = obj->boundingSphere;
-    obj->worldBoundingSphere.w = 1.0f;
-    const SgTransform *objTransform = (const SgTransform *)rsGetElementAt(obj->transformMatrix, 0);
-    obj->worldBoundingSphere = rsMatrixMultiply(&objTransform->globalMat, obj->worldBoundingSphere);
-
-    const float4 unitVec = {0.57735f, 0.57735f, 0.57735f, 0.0f};
-    float4 scaledVec = rsMatrixMultiply(&objTransform->globalMat, unitVec);
-    scaledVec.w = 0.0f;
-    obj->worldBoundingSphere.w = obj->boundingSphere.w * length(scaledVec);
-}
-
-static bool frustumCulled(SgRenderable *obj, SgCamera *cam) {
-    if (!obj->bVolInitialized) {
-        float minX, minY, minZ, maxX, maxY, maxZ;
-        rsgMeshComputeBoundingBox(obj->mesh,
-                                  &minX, &minY, &minZ,
-                                  &maxX, &maxY, &maxZ);
-        //rsDebug("min", minX, minY, minZ);
-        //rsDebug("max", maxX, maxY, maxZ);
-        float4 sphere;
-        sphere.x = (maxX + minX) * 0.5f;
-        sphere.y = (maxY + minY) * 0.5f;
-        sphere.z = (maxZ + minZ) * 0.5f;
-        float3 radius;
-        radius.x = (maxX - sphere.x);
-        radius.y = (maxY - sphere.y);
-        radius.z = (maxZ - sphere.z);
-
-        sphere.w = length(radius);
-        obj->boundingSphere = sphere;
-        obj->bVolInitialized = 1;
-        //rsDebug("Sphere", sphere);
-    }
-
-    getTransformedSphere(obj);
-
-    return !rsIsSphereInFrustum(&obj->worldBoundingSphere,
-                                &cam->frustumPlanes[0], &cam->frustumPlanes[1],
-                                &cam->frustumPlanes[2], &cam->frustumPlanes[3],
-                                &cam->frustumPlanes[4], &cam->frustumPlanes[5]);
-}
-
-
-void root(rs_allocation *v_out, const void *usrData) {
-
-    SgRenderable *drawable = (SgRenderable *)rsGetElementAt(*v_out, 0);
-    const SgCamera *camera = (const SgCamera*)usrData;
-
-    drawable->isVisible = 0;
-    // Not loaded yet
-    if (!rsIsObject(drawable->mesh) || drawable->cullType == CULL_ALWAYS) {
-        return;
-    }
-
-    // check to see if we are culling this object and if it's
-    // outside the frustum
-    if (drawable->cullType == CULL_FRUSTUM && frustumCulled(drawable, (SgCamera*)camera)) {
-#ifdef DEBUG_RENDERABLES
-        rsDebug("Culled", drawable);
-        printName(drawable->name);
-#endif // DEBUG_RENDERABLES
-        return;
-    }
-    drawable->isVisible = 1;
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs
deleted file mode 100644
index b438a43..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.scenegraph)
-
-// The sole purpose of this script is to have various structs exposed
-// so that java reflected classes are generated
-#include "scenegraph_objects.rsh"
-
-// Export our native constants to java so that we don't have parallel definitions
-const int ShaderParam_FLOAT4_DATA = SHADER_PARAM_FLOAT4_DATA;
-const int ShaderParam_TRANSFORM_DATA = SHADER_PARAM_TRANSFORM_DATA;
-const int ShaderParam_TRANSFORM_MODEL = SHADER_PARAM_TRANSFORM_MODEL;
-
-const int ShaderParam_FLOAT4_CAMERA_POS = SHADER_PARAM_FLOAT4_CAMERA_POS;
-const int ShaderParam_FLOAT4_CAMERA_DIR = SHADER_PARAM_FLOAT4_CAMERA_DIR;
-const int ShaderParam_TRANSFORM_VIEW = SHADER_PARAM_TRANSFORM_VIEW;
-const int ShaderParam_TRANSFORM_PROJ = SHADER_PARAM_TRANSFORM_PROJ;
-const int ShaderParam_TRANSFORM_VIEW_PROJ = SHADER_PARAM_TRANSFORM_VIEW_PROJ;
-const int ShaderParam_TRANSFORM_MODEL_VIEW = SHADER_PARAM_TRANSFORM_MODEL_VIEW;
-const int ShaderParam_TRANSFORM_MODEL_VIEW_PROJ = SHADER_PARAM_TRANSFORM_MODEL_VIEW_PROJ;
-
-const int ShaderParam_FLOAT4_LIGHT_COLOR = SHADER_PARAM_FLOAT4_LIGHT_COLOR;
-const int ShaderParam_FLOAT4_LIGHT_POS = SHADER_PARAM_FLOAT4_LIGHT_POS;
-const int ShaderParam_FLOAT4_LIGHT_DIR = SHADER_PARAM_FLOAT4_LIGHT_DIR;
-
-const int ShaderParam_TEXTURE = SHADER_PARAM_TEXTURE;
-
-const int Transform_TRANSLATE = TRANSFORM_TRANSLATE;
-const int Transform_ROTATE = TRANSFORM_ROTATE;
-const int Transform_SCALE = TRANSFORM_SCALE;
-
-const int TextureType_TEXTURE_2D = TEXTURE_2D;
-const int TextureType_TEXTURE_CUBE = TEXTURE_CUBE;
-const int TextureType_TEXTURE_RENDER_TARGET = TEXTURE_RENDER_TARGET;
-
-SgTransform *exportPtr;
-SgTransformComponent *componentPtr;
-SgRenderState *sExport;
-SgRenderable *drExport;
-SgRenderPass *pExport;
-SgCamera *exportPtrCam;
-SgLight *exportPtrLight;
-SgShaderParam *spExport;
-SgShaderParamData *spDataExport;
-SgVertexShader *pvExport;
-SgFragmentShader *pfExport;
-SgTexture *texExport;
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/fragment_params.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/fragment_params.rs
deleted file mode 100644
index 7202285..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/fragment_params.rs
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2012 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.scenegraph)
-
-#include "scenegraph_objects.rsh"
-
-//#define DEBUG_PARAMS
-
-#include "params.rsh"
-
-void root(rs_allocation *v_out, const void *usrData) {
-    SgFragmentShader *shader = (SgFragmentShader *)rsGetElementAt(*v_out, 0);
-    const SgCamera *camera = (const SgCamera*)usrData;
-    processAllParams(shader->shaderConst, shader->shaderConstParams, camera);
-    processTextureParams(shader);
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/light.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/light.rs
deleted file mode 100644
index e11979f..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/light.rs
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.scenegraph)
-
-//#define DEBUG_LIGHT
-#include "scenegraph_objects.rsh"
-
-void root(const rs_allocation *v_in, rs_allocation *v_out) {
-
-    SgLight *light = (SgLight *)rsGetElementAt(*v_in, 0);
-    const SgTransform *lTransform = (const SgTransform *)rsGetElementAt(light->transformMatrix, 0);
-
-    float4 zero = {0.0f, 0.0f, 0.0f, 1.0f};
-    light->position = rsMatrixMultiply(&lTransform->globalMat, zero);
-
-#ifdef DEBUG_LIGHT
-    printLightInfo(light);
-#endif //DEBUG_LIGHT
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/object_params.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/object_params.rs
deleted file mode 100644
index 0d524a6..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/object_params.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2012 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.scenegraph)
-
-#include "scenegraph_objects.rsh"
-
-//#define DEBUG_PARAMS
-
-#include "params.rsh"
-
-void root(rs_allocation *v_out, const void *usrData) {
-
-    SgRenderable *drawable = (SgRenderable *)rsGetElementAt(*v_out, 0);
-    // Visibility flag was set earlier in the cull stage
-    if (!drawable->isVisible) {
-        return;
-    }
-
-    const SgCamera *camera = (const SgCamera*)usrData;
-    processAllParams(drawable->pf_const, drawable->pf_constParams, camera);
-    processAllParams(drawable->pv_const, drawable->pv_constParams, camera);
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh
deleted file mode 100644
index 00793c0..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh
+++ /dev/null
@@ -1,192 +0,0 @@
-// Copyright (C) 2012 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.scenegraph)
-
-#include "scenegraph_objects.rsh"
-
-//#define DEBUG_PARAMS
-static inline void debugParam(SgShaderParam *p, SgShaderParamData *pData) {
-    rsDebug("____________ Param ____________", p);
-    printName(pData->paramName);
-    rsDebug("bufferOffset", p->bufferOffset);
-    rsDebug("type ", pData->type);
-    rsDebug("data timestamp ", pData->timestamp);
-    rsDebug("param timestamp", p->dataTimestamp);
-
-    const SgTransform *pTransform = NULL;
-    if (rsIsObject(pData->transform)) {
-        pTransform = (const SgTransform *)rsGetElementAt(pData->transform, 0);
-
-        rsDebug("transform", pTransform);
-        printName(pTransform->name);
-        rsDebug("timestamp", pTransform->timestamp);
-        rsDebug("param timestamp", p->transformTimestamp);
-    }
-
-    const SgLight *pLight = NULL;
-    if (rsIsObject(pData->light)) {
-        pLight = (const SgLight *)rsGetElementAt(pData->light, 0);
-        printLightInfo(pLight);
-    }
-}
-
-static inline void writeFloatData(float *ptr, const float4 *input, uint32_t vecSize) {
-#ifdef DEBUG_PARAMS
-    rsDebug("Writing value ", *input);
-    rsDebug("Writing vec size ", vecSize);
-#endif // DEBUG_PARAMS
-
-    switch (vecSize) {
-    case 1:
-        *ptr = input->x;
-        break;
-    case 2:
-        *((float2*)ptr) = (*input).xy;
-        break;
-    case 3:
-        *((float3*)ptr) = (*input).xyz;
-        break;
-    case 4:
-        *((float4*)ptr) = *input;
-        break;
-    }
-}
-
-static inline bool processParam(SgShaderParam *p, SgShaderParamData *pData,
-                         uint8_t *constantBuffer,
-                         const SgCamera *currentCam,
-                         SgFragmentShader *shader) {
-    bool isDataOnly = (pData->type > SHADER_PARAM_DATA_ONLY);
-    const SgTransform *pTransform = NULL;
-    if (rsIsObject(pData->transform)) {
-        pTransform = (const SgTransform *)rsGetElementAt(pData->transform, 0);
-    }
-
-    if (isDataOnly) {
-        // If we are a transform param and our transform is unchanged, nothing to do
-        if (pTransform) {
-            if (p->transformTimestamp == pTransform->timestamp) {
-                return false;
-            }
-            p->transformTimestamp = pTransform->timestamp;
-        } else {
-            if (p->dataTimestamp == pData->timestamp) {
-                return false;
-            }
-            p->dataTimestamp = pData->timestamp;
-        }
-    }
-
-    const SgLight *pLight = NULL;
-    if (rsIsObject(pData->light)) {
-        pLight = (const SgLight *)rsGetElementAt(pData->light, 0);
-    }
-
-    uint8_t *dataPtr = NULL;
-    const SgTexture *tex = NULL;
-    if (pData->type == SHADER_PARAM_TEXTURE) {
-        tex = rsGetElementAt(pData->texture, 0);
-    } else {
-        dataPtr = constantBuffer + p->bufferOffset;
-    }
-
-    switch (pData->type) {
-    case SHADER_PARAM_TEXTURE:
-        rsgBindTexture(shader->program, p->bufferOffset, tex->texture);
-        break;
-    case SHADER_PARAM_FLOAT4_DATA:
-        writeFloatData((float*)dataPtr, &pData->float_value, p->float_vecSize);
-        break;
-    case SHADER_PARAM_FLOAT4_CAMERA_POS:
-        writeFloatData((float*)dataPtr, &currentCam->position, p->float_vecSize);
-        break;
-    case SHADER_PARAM_FLOAT4_CAMERA_DIR: break;
-    case SHADER_PARAM_FLOAT4_LIGHT_COLOR:
-        writeFloatData((float*)dataPtr, &pLight->color, p->float_vecSize);
-        break;
-    case SHADER_PARAM_FLOAT4_LIGHT_POS:
-        writeFloatData((float*)dataPtr, &pLight->position, p->float_vecSize);
-        break;
-    case SHADER_PARAM_FLOAT4_LIGHT_DIR: break;
-
-    case SHADER_PARAM_TRANSFORM_DATA:
-        rsMatrixLoad((rs_matrix4x4*)dataPtr, &pTransform->globalMat);
-        break;
-    case SHADER_PARAM_TRANSFORM_VIEW:
-        rsMatrixLoad((rs_matrix4x4*)dataPtr, &currentCam->view);
-        break;
-    case SHADER_PARAM_TRANSFORM_PROJ:
-        rsMatrixLoad((rs_matrix4x4*)dataPtr, &currentCam->proj);
-        break;
-    case SHADER_PARAM_TRANSFORM_VIEW_PROJ:
-        rsMatrixLoad((rs_matrix4x4*)dataPtr, &currentCam->viewProj);
-        break;
-    case SHADER_PARAM_TRANSFORM_MODEL:
-        rsMatrixLoad((rs_matrix4x4*)dataPtr, &pTransform->globalMat);
-        break;
-    case SHADER_PARAM_TRANSFORM_MODEL_VIEW:
-        rsMatrixLoad((rs_matrix4x4*)dataPtr, &currentCam->view);
-        rsMatrixLoadMultiply((rs_matrix4x4*)dataPtr,
-                             (rs_matrix4x4*)dataPtr,
-                             &pTransform->globalMat);
-        break;
-    case SHADER_PARAM_TRANSFORM_MODEL_VIEW_PROJ:
-        rsMatrixLoad((rs_matrix4x4*)dataPtr, &currentCam->viewProj);
-        rsMatrixLoadMultiply((rs_matrix4x4*)dataPtr,
-                             (rs_matrix4x4*)dataPtr,
-                             &pTransform->globalMat);
-        break;
-    }
-    return true;
-}
-
-static inline void processAllParams(rs_allocation shaderConst,
-                             rs_allocation allParams,
-                             const SgCamera *camera) {
-    if (rsIsObject(shaderConst)) {
-        uint8_t *constantBuffer = (uint8_t*)rsGetElementAt(shaderConst, 0);
-
-        int numParams = 0;
-        if (rsIsObject(allParams)) {
-            numParams = rsAllocationGetDimX(allParams);
-        }
-        bool updated = false;
-        for (int i = 0; i < numParams; i ++) {
-            SgShaderParam *current = (SgShaderParam*)rsGetElementAt(allParams, i);
-            SgShaderParamData *currentData = (SgShaderParamData*)rsGetElementAt(current->data, 0);
-#ifdef DEBUG_PARAMS
-            debugParam(current, currentData);
-#endif // DEBUG_PARAMS
-            updated = processParam(current, currentData, constantBuffer, camera, NULL) || updated;
-        }
-    }
-}
-
-static inline void processTextureParams(SgFragmentShader *shader) {
-    int numParams = 0;
-    if (rsIsObject(shader->shaderTextureParams)) {
-        numParams = rsAllocationGetDimX(shader->shaderTextureParams);
-    }
-    for (int i = 0; i < numParams; i ++) {
-        SgShaderParam *current = (SgShaderParam*)rsGetElementAt(shader->shaderTextureParams, i);
-        SgShaderParamData *currentData = (SgShaderParamData*)rsGetElementAt(current->data, 0);
-#ifdef DEBUG_PARAMS
-        debugParam(current, currentData);
-#endif // DEBUG_PARAMS
-        processParam(current, currentData, NULL, NULL, shader);
-    }
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs
deleted file mode 100644
index 205b2cb..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs
+++ /dev/null
@@ -1,244 +0,0 @@
-// Copyright (C) 2011-2012 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.scenegraph)
-
-#include "rs_graphics.rsh"
-#include "scenegraph_objects.rsh"
-
-rs_script gTransformScript;
-rs_script gCameraScript;
-rs_script gLightScript;
-rs_script gObjectParamsScript;
-rs_script gFragmentParamsScript;
-rs_script gVertexParamsScript;
-rs_script gCullScript;
-
-SgTransform *gRootNode;
-rs_allocation gCameras;
-rs_allocation gLights;
-rs_allocation gFragmentShaders;
-rs_allocation gVertexShaders;
-rs_allocation gRenderableObjects;
-
-rs_allocation gRenderPasses;
-
-// Temporary shaders
-rs_program_store gPFSBackground;
-
-uint32_t *gFrontToBack;
-static uint32_t gFrontToBackCount = 0;
-uint32_t *gBackToFront;
-static uint32_t gBackToFrontCount = 0;
-
-static SgCamera *gActiveCamera = NULL;
-
-static rs_allocation nullAlloc;
-
-// #define DEBUG_RENDERABLES
-static void draw(SgRenderable *obj) {
-#ifdef DEBUG_RENDERABLES
-    const SgTransform *objTransform = (const SgTransform *)rsGetElementAt(obj->transformMatrix, 0);
-    rsDebug("**** Drawing object with transform", obj);
-    printName(objTransform->name);
-    rsDebug("Model matrix: ", &objTransform->globalMat);
-    printName(obj->name);
-#endif //DEBUG_RENDERABLES
-
-    const SgRenderState *renderState = (const SgRenderState *)rsGetElementAt(obj->render_state, 0);
-    const SgVertexShader *pv = (const SgVertexShader *)rsGetElementAt(renderState->pv, 0);
-    const SgFragmentShader *pf = (const SgFragmentShader *)rsGetElementAt(renderState->pf, 0);
-
-    if (pv->objectConstIndex != -1) {
-        rsgBindConstant(pv->program, pv->objectConstIndex, obj->pv_const);
-    }
-    if (pf->objectConstIndex != -1) {
-        rsgBindConstant(pf->program, pf->objectConstIndex, obj->pf_const);
-    }
-
-    if (rsIsObject(renderState->ps)) {
-        rsgBindProgramStore(renderState->ps);
-    } else {
-        rsgBindProgramStore(gPFSBackground);
-    }
-
-    if (rsIsObject(renderState->pr)) {
-        rsgBindProgramRaster(renderState->pr);
-    } else {
-        rs_program_raster pr = {0};
-        rsgBindProgramRaster(pr);
-    }
-
-    rsgBindProgramVertex(pv->program);
-    rsgBindProgramFragment(pf->program);
-
-    for (uint32_t i = 0; i < obj->pf_num_textures; i ++) {
-        const SgTexture *tex = rsGetElementAt(obj->pf_textures[i], 0);
-        rsgBindTexture(pf->program, i, tex->texture);
-    }
-
-    rsgDrawMesh(obj->mesh, obj->meshIndex);
-}
-
-static void sortToBucket(SgRenderable *obj) {
-    const SgRenderState *renderState = (const SgRenderState *)rsGetElementAt(obj->render_state, 0);
-    if (rsIsObject(renderState->ps)) {
-        bool isOpaque = false;
-        if (isOpaque) {
-            gFrontToBack[gFrontToBackCount++] = (uint32_t)obj;
-        } else {
-            gBackToFront[gBackToFrontCount++] = (uint32_t)obj;
-        }
-    } else {
-        gFrontToBack[gFrontToBackCount++] = (uint32_t)obj;
-    }
-}
-
-static void updateActiveCamera(rs_allocation cam) {
-    gActiveCamera = (SgCamera *)rsGetElementAt(cam, 0);
-}
-
-static void prepareCameras() {
-    // now compute all the camera matrices
-    if (rsIsObject(gCameras)) {
-        float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
-        rsForEach(gCameraScript, gCameras, nullAlloc, &aspect, sizeof(aspect));
-    }
-}
-
-static void prepareLights() {
-    if (rsIsObject(gLights)) {
-        rsForEach(gLightScript, gLights, nullAlloc);
-    }
-}
-
-static void drawSorted() {
-    for (int i = 0; i < gFrontToBackCount; i ++) {
-        SgRenderable *current = (SgRenderable*)gFrontToBack[i];
-        draw(current);
-    }
-
-    for (int i = 0; i < gBackToFrontCount; i ++) {
-        SgRenderable *current = (SgRenderable*)gBackToFront[i];
-        draw(current);
-    }
-}
-
-static void drawAllObjects(rs_allocation allObj) {
-    if (!rsIsObject(allObj)) {
-        return;
-    }
-
-    if (rsIsObject(gVertexShaders)) {
-        rsForEach(gVertexParamsScript, nullAlloc, gVertexShaders,
-                  gActiveCamera, sizeof(gActiveCamera));
-    }
-    if (rsIsObject(gFragmentShaders)) {
-        rsForEach(gFragmentParamsScript, nullAlloc, gFragmentShaders,
-                  gActiveCamera, sizeof(gActiveCamera));
-    }
-
-    // Run the params and cull script
-    rsForEach(gCullScript, nullAlloc, allObj, gActiveCamera, sizeof(gActiveCamera));
-    rsForEach(gObjectParamsScript, nullAlloc, allObj, gActiveCamera, sizeof(gActiveCamera));
-
-    int numRenderables = rsAllocationGetDimX(allObj);
-    for (int i = 0; i < numRenderables; i ++) {
-        rs_allocation *drawAlloc = (rs_allocation*)rsGetElementAt(allObj, i);
-        SgRenderable *current = (SgRenderable*)rsGetElementAt(*drawAlloc, 0);
-        if (current->isVisible) {
-            sortToBucket(current);
-        }
-    }
-    drawSorted();
-}
-
-int root(void) {
-#ifdef DEBUG_RENDERABLES
-    rsDebug("=============================================================================", 0);
-#endif // DEBUG_RENDERABLES
-
-    // first step is to update the transform hierachy
-    if (gRootNode && rsIsObject(gRootNode->children)) {
-        rsForEach(gTransformScript, gRootNode->children, nullAlloc, 0, 0);
-    }
-
-    prepareCameras();
-    prepareLights();
-
-    if (rsIsObject(gRenderPasses)) {
-        rsgClearDepth(1.0f);
-        int numPasses = rsAllocationGetDimX(gRenderPasses);
-        for (uint i = 0; i < numPasses; i ++) {
-            gFrontToBackCount = 0;
-            gBackToFrontCount = 0;
-            SgRenderPass *pass = (SgRenderPass*)rsGetElementAt(gRenderPasses, i);
-            if (rsIsObject(pass->color_target)) {
-                rsgBindColorTarget(pass->color_target, 0);
-            }
-            if (rsIsObject(pass->depth_target)) {
-                rsgBindDepthTarget(pass->depth_target);
-            }
-            if (!rsIsObject(pass->color_target) &&
-                !rsIsObject(pass->depth_target)) {
-                rsgClearAllRenderTargets();
-            }
-            updateActiveCamera(pass->camera);
-            if (pass->should_clear_color) {
-                rsgClearColor(pass->clear_color.x, pass->clear_color.y,
-                              pass->clear_color.z, pass->clear_color.w);
-            }
-            if (pass->should_clear_depth) {
-                rsgClearDepth(pass->clear_depth);
-            }
-            drawAllObjects(pass->objects);
-        }
-    } else {
-        gFrontToBackCount = 0;
-        gBackToFrontCount = 0;
-        rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
-        rsgClearDepth(1.0f);
-
-        if (rsIsObject(gCameras)) {
-            rs_allocation *camAlloc = (rs_allocation*)rsGetElementAt(gCameras, 0);
-            updateActiveCamera(*camAlloc);
-        }
-        drawAllObjects(gRenderableObjects);
-    }
-    return 10;
-}
-
-// Search through sorted and culled objects
-void pick(int screenX, int screenY) {
-    float3 pnt, vec;
-    getCameraRay(gActiveCamera, screenX, screenY, &pnt, &vec);
-
-    for (int i = 0; i < gFrontToBackCount; i ++) {
-        SgRenderable *current = (SgRenderable*)gFrontToBack[i];
-        bool isPicked = intersect(current, pnt, vec);
-        if (isPicked) {
-            current->cullType = CULL_ALWAYS;
-        }
-    }
-
-    for (int i = 0; i < gBackToFrontCount; i ++) {
-        SgRenderable *current = (SgRenderable*)gBackToFront[i];
-        bool isPicked = intersect(current, pnt, vec);
-        if (isPicked) {
-            current->cullType = CULL_ALWAYS;
-        }
-    }
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh
deleted file mode 100644
index 90ae212..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh
+++ /dev/null
@@ -1,323 +0,0 @@
-// Copyright (C) 2011-2012 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.scenegraph)
-
-#ifndef _TRANSFORM_DEF_
-#define _TRANSFORM_DEF_
-
-#include "rs_graphics.rsh"
-
-#define TRANSFORM_NONE      0
-#define TRANSFORM_TRANSLATE 1
-#define TRANSFORM_ROTATE    2
-#define TRANSFORM_SCALE     3
-
-#define CULL_FRUSTUM 0
-#define CULL_ALWAYS  2
-
-#define LIGHT_POINT       0
-#define LIGHT_DIRECTIONAL 1
-
-// Shader params that involve only data
-#define SHADER_PARAM_DATA_ONLY                 10000
-#define SHADER_PARAM_FLOAT4_DATA               10001
-#define SHADER_PARAM_TRANSFORM_DATA            10002
-#define SHADER_PARAM_TRANSFORM_MODEL           10003
-
-// Shader params that involve camera
-#define SHADER_PARAM_CAMERA                    1000
-#define SHADER_PARAM_FLOAT4_CAMERA_POS         1001
-#define SHADER_PARAM_FLOAT4_CAMERA_DIR         1002
-#define SHADER_PARAM_TRANSFORM_VIEW            1003
-#define SHADER_PARAM_TRANSFORM_PROJ            1004
-#define SHADER_PARAM_TRANSFORM_VIEW_PROJ       1005
-#define SHADER_PARAM_TRANSFORM_MODEL_VIEW      1006
-#define SHADER_PARAM_TRANSFORM_MODEL_VIEW_PROJ 1007
-
-// Shader Params that only involve lights
-#define SHADER_PARAM_LIGHT                     100
-#define SHADER_PARAM_FLOAT4_LIGHT_COLOR        103
-#define SHADER_PARAM_FLOAT4_LIGHT_POS          104
-#define SHADER_PARAM_FLOAT4_LIGHT_DIR          105
-
-#define SHADER_PARAM_TEXTURE                   10
-
-#define TEXTURE_NONE          0
-#define TEXTURE_2D            1
-#define TEXTURE_CUBE          2
-#define TEXTURE_RENDER_TARGET 3
-
-typedef struct TransformComponent_s {
-    float4 value;
-    int type;
-    rs_allocation name;
-} SgTransformComponent;
-
-typedef struct __attribute__((packed, aligned(4))) SgTransform {
-    rs_matrix4x4 globalMat;
-    rs_matrix4x4 localMat;
-
-    rs_allocation components;
-    int isDirty;
-
-    rs_allocation children;
-    rs_allocation name;
-
-    // Used to check whether transform params need to be updated
-    uint32_t timestamp;
-} SgTransform;
-
-typedef struct VertexShader_s {
-    rs_program_vertex program;
-    // Buffer with vertex constant data
-    rs_allocation shaderConst;
-    // ShaderParam's that populate data
-    rs_allocation shaderConstParams;
-    // location of the per object constants on the buffer
-    int objectConstIndex;
-} SgVertexShader;
-
-typedef struct FragmentShader_s {
-    rs_program_fragment program;
-    // Buffer with vertex constant data
-    rs_allocation shaderConst;
-    // ShaderParam's that populate data
-    rs_allocation shaderConstParams;
-    // ShaderParam's that set textures
-    rs_allocation shaderTextureParams;
-    // location of the per object constants on the buffer
-    int objectConstIndex;
-} SgFragmentShader;
-
-typedef struct RenderState_s {
-    rs_allocation pv; // VertexShader struct
-    rs_allocation pf; // FragmentShader struct
-    rs_program_store ps;
-    rs_program_raster pr;
-} SgRenderState;
-
-typedef struct Renderable_s {
-    rs_allocation render_state;
-    // Buffer with vertex constant data
-    rs_allocation pv_const;
-    // ShaderParam's that populate data
-    rs_allocation pv_constParams;
-    // Buffer with fragment constant data
-    rs_allocation pf_const;
-    // ShaderParam's that populate data
-    rs_allocation pf_constParams;
-    rs_allocation pf_textures[8];
-    int pf_num_textures;
-    rs_mesh mesh;
-    int meshIndex;
-    rs_allocation transformMatrix;
-    rs_allocation name;
-    float4 boundingSphere;
-    float4 worldBoundingSphere;
-    int bVolInitialized;
-    int cullType; // specifies whether to frustum cull
-    int isVisible;
-} SgRenderable;
-
-typedef struct RenderPass_s {
-    rs_allocation color_target;
-    rs_allocation depth_target;
-    rs_allocation camera;
-    rs_allocation objects;
-
-    float4 clear_color;
-    float clear_depth;
-    bool should_clear_color;
-    bool should_clear_depth;
-} SgRenderPass;
-
-typedef struct Camera_s {
-    rs_matrix4x4 proj;
-    rs_matrix4x4 view;
-    rs_matrix4x4 viewProj;
-    float4 position;
-    float near;
-    float far;
-    float horizontalFOV;
-    float aspect;
-    rs_allocation name;
-    rs_allocation transformMatrix;
-    float4 frustumPlanes[6];
-
-    int isDirty;
-    // Timestamp of the camera itself to signal params if anything changes
-    uint32_t timestamp;
-    // Timestamp of our transform
-    uint32_t transformTimestamp;
-} SgCamera;
-
-typedef struct Light_s {
-    float4 position;
-    float4 color;
-    float intensity;
-    int type;
-    rs_allocation name;
-    rs_allocation transformMatrix;
-} SgLight;
-
-// This represents the shader parameter data needed to set a float or transform data
-typedef struct ShaderParamData_s {
-    int type;
-    float4 float_value;
-    uint32_t timestamp;
-    rs_allocation paramName;
-    rs_allocation camera;
-    rs_allocation light;
-    rs_allocation transform;
-    rs_allocation texture;
-} SgShaderParamData;
-
-// This represents a shader parameter that knows how to update itself for a given
-// renderable or shader and contains a timestamp for the last time this buffer was updated
-typedef struct ShaderParam_s {
-    // Used to check whether transform params need to be updated
-    uint32_t transformTimestamp;
-    // Used to check whether data params need to be updated
-    // These are used when somebody set the matrix of float value directly in java
-    uint32_t dataTimestamp;
-    // Specifies where in the constant buffer data gets written to
-    int bufferOffset;
-    // An instance of SgShaderParamData that could be shared by multiple objects
-    rs_allocation data;
-    // How many components of the vector we need to write
-    int float_vecSize;
-} SgShaderParam;
-
-// This represents a texture object
-typedef struct Texture_s {
-    uint32_t type;
-    rs_allocation texture;
-} SgTexture;
-
-static inline void printName(rs_allocation name) {
-    if (!rsIsObject(name)) {
-        rsDebug("no name", 0);
-        return;
-    }
-
-    rsDebug((const char*)rsGetElementAt(name, 0), 0);
-}
-
-static inline void printCameraInfo(const SgCamera *cam) {
-    rsDebug("***** Camera information. ptr:", cam);
-    printName(cam->name);
-    const SgTransform *camTransform = (const SgTransform *)rsGetElementAt(cam->transformMatrix, 0);
-    rsDebug("Transform name:", camTransform);
-    printName(camTransform->name);
-
-    rsDebug("Aspect: ", cam->aspect);
-    rsDebug("Near: ", cam->near);
-    rsDebug("Far: ", cam->far);
-    rsDebug("Fov: ", cam->horizontalFOV);
-    rsDebug("Position: ", cam->position);
-    rsDebug("Proj: ", &cam->proj);
-    rsDebug("View: ", &cam->view);
-}
-
-static inline void printLightInfo(const SgLight *light) {
-    rsDebug("***** Light information. ptr:", light);
-    printName(light->name);
-    const SgTransform *lTransform = (const SgTransform *)rsGetElementAt(light->transformMatrix, 0);
-    rsDebug("Transform name:", lTransform);
-    printName(lTransform->name);
-
-    rsDebug("Position: ", light->position);
-    rsDebug("Color : ", light->color);
-    rsDebug("Intensity: ", light->intensity);
-    rsDebug("Type: ", light->type);
-}
-
-static inline void getCameraRay(const SgCamera *cam, int screenX, int screenY, float3 *pnt, float3 *vec) {
-    rsDebug("=================================", screenX);
-    rsDebug("Point X", screenX);
-    rsDebug("Point Y", screenY);
-
-    rs_matrix4x4 mvpInv;
-    rsMatrixLoad(&mvpInv, &cam->viewProj);
-    rsMatrixInverse(&mvpInv);
-
-    float width = (float)rsgGetWidth();
-    float height = (float)rsgGetHeight();
-
-    float4 pos = {(float)screenX, height - (float)screenY, 0.0f, 1.0f};
-
-    pos.x /= width;
-    pos.y /= height;
-
-    rsDebug("Pre Norm X", pos.x);
-    rsDebug("Pre Norm Y", pos.y);
-
-    pos.xy = pos.xy * 2.0f - 1.0f;
-
-    rsDebug("Norm X", pos.x);
-    rsDebug("Norm Y", pos.y);
-
-    pos = rsMatrixMultiply(&mvpInv, pos);
-    float oneOverW = 1.0f / pos.w;
-    pos.xyz *= oneOverW;
-
-    rsDebug("World X", pos.x);
-    rsDebug("World Y", pos.y);
-    rsDebug("World Z", pos.z);
-
-    rsDebug("Cam X", cam->position.x);
-    rsDebug("Cam Y", cam->position.y);
-    rsDebug("Cam Z", cam->position.z);
-
-    *vec = normalize(pos.xyz - cam->position.xyz);
-    rsDebug("Vec X", vec->x);
-    rsDebug("Vec Y", vec->y);
-    rsDebug("Vec Z", vec->z);
-    *pnt = cam->position.xyz;
-}
-
-static inline bool intersect(const SgRenderable *obj, float3 pnt, float3 vec) {
-    // Solving for t^2 + Bt + C = 0
-    float3 originMinusCenter = pnt - obj->worldBoundingSphere.xyz;
-    float B = dot(originMinusCenter, vec) * 2.0f;
-    float C = dot(originMinusCenter, originMinusCenter) -
-              obj->worldBoundingSphere.w * obj->worldBoundingSphere.w;
-
-    float discriminant = B * B - 4.0f * C;
-    if (discriminant < 0.0f) {
-        return false;
-    }
-    discriminant = sqrt(discriminant);
-
-    float t0 = (-B - discriminant) * 0.5f;
-    float t1 = (-B + discriminant) * 0.5f;
-
-    if (t0 > t1) {
-        float temp = t0;
-        t0 = t1;
-        t1 = temp;
-    }
-
-    // The sphere is behind us
-    if (t1 < 0.0f) {
-        return false;
-    }
-    return true;
-}
-
-
-#endif // _TRANSFORM_DEF_
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform.rs
deleted file mode 100644
index 1d0b5be..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform.rs
+++ /dev/null
@@ -1,129 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.modelviewer)
-
-#include "scenegraph_objects.rsh"
-
-rs_script gTransformScript;
-
-typedef struct {
-    int changed;
-    rs_matrix4x4 *mat;
-} ParentData;
-
-//#define DEBUG_TRANSFORMS
-/* Unused function:
-static void debugTransform(SgTransform *data, const ParentData *parent) {
-    rsDebug("****** <Transform> ******", (int)data);
-    printName(data->name);
-    rsDebug("isDirty", data->isDirty);
-    rsDebug("parent", (int)parent);
-    rsDebug("child ", rsIsObject(data->children));
-
-    // Refresh matrices if dirty
-    if (data->isDirty && rsIsObject(data->components)) {
-        uint32_t numComponenets = rsAllocationGetDimX(data->components);
-        for (int i = 0; i < numComponenets; i ++) {
-            const SgTransformComponent *comp = NULL;
-            comp = (const SgTransformComponent *)rsGetElementAt(data->components, i);
-
-            if (rsIsObject(comp->name)) {
-                rsDebug((const char*)rsGetElementAt(comp->name, 0), comp->value);
-                rsDebug("Type", comp->type);
-            } else {
-                rsDebug("no name", comp->value);
-                rsDebug("Type", comp->type);
-            }
-        }
-    }
-
-    rsDebug("timestamp", data->timestamp);
-    rsDebug("****** </Transform> ******", (int)data);
-}
-*/
-
-static void appendTransformation(int type, float4 data, rs_matrix4x4 *mat) {
-    rs_matrix4x4 temp;
-
-    switch (type) {
-    case TRANSFORM_TRANSLATE:
-        rsMatrixLoadTranslate(&temp, data.x, data.y, data.z);
-        break;
-    case TRANSFORM_ROTATE:
-        rsMatrixLoadRotate(&temp, data.w, data.x, data.y, data.z);
-        break;
-    case TRANSFORM_SCALE:
-        rsMatrixLoadScale(&temp, data.x, data.y, data.z);
-        break;
-    }
-    rsMatrixMultiply(mat, &temp);
-}
-
-void root(const rs_allocation *v_in, rs_allocation *v_out, const void *usrData) {
-
-    SgTransform *data = (SgTransform *)rsGetElementAt(*v_in, 0);
-    const ParentData *parent = (const ParentData *)usrData;
-
-#ifdef DEBUG_TRANSFORMS
-    debugTransform(data, parent);
-#endif //DEBUG_TRANSFORMS
-
-    rs_matrix4x4 *localMat = &data->localMat;
-    rs_matrix4x4 *globalMat = &data->globalMat;
-
-    // Refresh matrices if dirty
-    if (data->isDirty && rsIsObject(data->components)) {
-        bool resetLocal = false;
-        uint32_t numComponenets = rsAllocationGetDimX(data->components);
-        for (int i = 0; i < numComponenets; i ++) {
-            if (!resetLocal) {
-                // Reset our local matrix only for component transforms
-                rsMatrixLoadIdentity(localMat);
-                resetLocal = true;
-            }
-            const SgTransformComponent *comp = NULL;
-            comp = (const SgTransformComponent *)rsGetElementAt(data->components, i);
-            appendTransformation(comp->type, comp->value, localMat);
-        }
-    }
-
-    if (parent) {
-        data->isDirty = (parent->changed || data->isDirty) ? 1 : 0;
-        if (data->isDirty) {
-            rsMatrixLoad(globalMat, parent->mat);
-            rsMatrixMultiply(globalMat, localMat);
-        }
-    } else if (data->isDirty) {
-        rsMatrixLoad(globalMat, localMat);
-    }
-
-    ParentData toChild;
-    toChild.changed = 0;
-    toChild.mat = globalMat;
-
-    if (data->isDirty) {
-        toChild.changed = 1;
-        data->timestamp ++;
-    }
-
-    if (rsIsObject(data->children)) {
-        rs_allocation nullAlloc = {0};
-        rsForEach(gTransformScript, data->children, nullAlloc, &toChild, sizeof(toChild));
-    }
-
-    data->isDirty = 0;
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/vertex_params.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/vertex_params.rs
deleted file mode 100644
index 88955a8..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/vertex_params.rs
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) 2012 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.scenegraph)
-
-#include "scenegraph_objects.rsh"
-
-//#define DEBUG_PARAMS
-
-#include "params.rsh"
-
-void root(rs_allocation *v_out, const void *usrData) {
-    SgVertexShader *shader = (SgVertexShader *)rsGetElementAt(*v_out, 0);
-    const SgCamera *camera = (const SgCamera*)usrData;
-    processAllParams(shader->shaderConst, shader->shaderConstParams, camera);
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FileSelector.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FileSelector.java
deleted file mode 100644
index 420e133..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FileSelector.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testapp;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.util.ArrayList;
-import java.util.List;
-
-import android.app.ListActivity;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-
-/**
- * A list view where the last item the user clicked is placed in
- * the "activated" state, causing its background to highlight.
- */
-public class FileSelector extends ListActivity {
-
-    File[] mCurrentSubList;
-    File mCurrentFile;
-
-    class DAEFilter implements FileFilter {
-        public boolean accept(File file) {
-            if (file.isDirectory()) {
-                return true;
-            }
-            return file.getName().endsWith(".dae");
-        }
-    }
-
-    private void populateList(File file) {
-
-        mCurrentFile = file;
-        setTitle(mCurrentFile.getAbsolutePath() + "/*.dae");
-        List<String> names = new ArrayList<String>();
-        names.add("..");
-
-        mCurrentSubList = mCurrentFile.listFiles(new DAEFilter());
-
-        if (mCurrentSubList != null) {
-            for (int i = 0; i < mCurrentSubList.length; i ++) {
-                String fileName = mCurrentSubList[i].getName();
-                if (mCurrentSubList[i].isDirectory()) {
-                    fileName = "/" + fileName;
-                }
-                names.add(fileName);
-            }
-        }
-
-        // Use the built-in layout for showing a list item with a single
-        // line of text whose background is changes when activated.
-        setListAdapter(new ArrayAdapter<String>(this,
-                android.R.layout.simple_list_item_activated_1, names));
-        getListView().setTextFilterEnabled(true);
-
-        // Tell the list view to show one checked/activated item at a time.
-        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
-    }
-
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        populateList(new File("/sdcard/"));
-    }
-
-    @Override
-    protected void onListItemClick(ListView l, View v, int position, long id) {
-        if (position == 0) {
-            File parent = mCurrentFile.getParentFile();
-            if (parent == null) {
-                return;
-            }
-            populateList(parent);
-            return;
-        }
-
-        // the first thing in list is parent directory
-        File selectedFile = mCurrentSubList[position - 1];
-        if (selectedFile.isDirectory()) {
-            populateList(selectedFile);
-            return;
-        }
-
-        Intent resultIntent = new Intent();
-        resultIntent.setData(Uri.fromFile(selectedFile));
-        setResult(RESULT_OK, resultIntent);
-        finish();
-    }
-
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FullscreenBlur.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FullscreenBlur.java
deleted file mode 100644
index 28f916c..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FullscreenBlur.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*

- * Copyright (C) 2011 The Android Open Source Project

- *

- * Licensed under the Apache License, Version 2.0 (the "License");

- * you may not use this file except in compliance with the License.

- * You may obtain a copy of the License at

- *

- *      http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing, software

- * distributed under the License is distributed on an "AS IS" BASIS,

- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- * See the License for the specific language governing permissions and

- * limitations under the License.

- */

-

-

-package com.android.testapp;

-

-import java.util.ArrayList;

-

-import com.android.scenegraph.*;

-

-import android.content.res.Resources;

-import android.graphics.Bitmap;

-import android.graphics.BitmapFactory;

-import android.os.AsyncTask;

-import android.renderscript.*;

-import android.renderscript.Allocation.MipmapControl;

-import android.renderscript.Element.Builder;

-import android.renderscript.Font.Style;

-import android.renderscript.Program.TextureType;

-import android.renderscript.ProgramStore.DepthFunc;

-import android.util.Log;

-

-class FullscreenBlur {

-

-    static TextureRenderTarget sRenderTargetBlur0Color;

-    static TextureRenderTarget sRenderTargetBlur0Depth;

-    static TextureRenderTarget sRenderTargetBlur1Color;

-    static TextureRenderTarget sRenderTargetBlur1Depth;

-    static TextureRenderTarget sRenderTargetBlur2Color;

-    static TextureRenderTarget sRenderTargetBlur2Depth;

-

-    static FragmentShader mPF_BlurH;

-    static FragmentShader mPF_BlurV;

-    static FragmentShader mPF_SelectColor;

-    static FragmentShader mPF_Texture;

-    static VertexShader mPV_Paint;

-    static VertexShader mPV_Blur;

-

-    static int targetWidth;

-    static int targetHeight;

-

-    // This is only used when full screen blur is enabled

-    // Basically, it's the offscreen render targets

-    static void createRenderTargets(RenderScriptGL rs, int w, int h) {

-        targetWidth = w/8;

-        targetHeight = h/8;

-        Type.Builder b = new Type.Builder(rs, Element.RGBA_8888(rs));

-        Type renderType = b.setX(targetWidth).setY(targetHeight).create();

-        int usage = Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_GRAPHICS_RENDER_TARGET;

-        sRenderTargetBlur0Color = new TextureRenderTarget(Allocation.createTyped(rs, renderType, usage));

-        sRenderTargetBlur1Color = new TextureRenderTarget(Allocation.createTyped(rs, renderType, usage));

-        sRenderTargetBlur2Color = new TextureRenderTarget(Allocation.createTyped(rs, renderType, usage));

-

-        b = new Type.Builder(rs, Element.createPixel(rs, Element.DataType.UNSIGNED_16,

-                                                     Element.DataKind.PIXEL_DEPTH));

-        renderType = b.setX(targetWidth).setY(targetHeight).create();

-        usage = Allocation.USAGE_GRAPHICS_RENDER_TARGET;

-        sRenderTargetBlur0Depth = new TextureRenderTarget(Allocation.createTyped(rs, renderType, usage));

-        sRenderTargetBlur1Depth = new TextureRenderTarget(Allocation.createTyped(rs, renderType, usage));

-        sRenderTargetBlur2Depth = new TextureRenderTarget(Allocation.createTyped(rs, renderType, usage));

-    }

-

-    static void addOffsets(Renderable quad, float advance) {

-        quad.appendSourceParams(new Float4Param("blurOffset0", - advance * 2.5f));

-        quad.appendSourceParams(new Float4Param("blurOffset1", - advance * 0.5f));

-        quad.appendSourceParams(new Float4Param("blurOffset2", advance * 1.5f));

-        quad.appendSourceParams(new Float4Param("blurOffset3", advance * 3.5f));

-    }

-

-    static RenderPass addPass(Scene scene, Camera cam, TextureRenderTarget color, TextureRenderTarget depth) {

-        RenderPass pass = new RenderPass();

-        pass.setColorTarget(color);

-        pass.setDepthTarget(depth);

-        pass.setShouldClearColor(false);

-        pass.setShouldClearDepth(false);

-        pass.setCamera(cam);

-        scene.appendRenderPass(pass);

-        return pass;

-    }

-

-    static void addBlurPasses(Scene scene, RenderScriptGL rs, Camera cam) {

-        SceneManager sceneManager = SceneManager.getInstance();

-        ArrayList<RenderableBase> allDraw = scene.getRenderables();

-        int numDraw = allDraw.size();

-

-        ProgramRaster cullNone = ProgramRaster.CULL_NONE(rs);

-        ProgramStore blendAdd = SceneManager.BLEND_ADD_DEPTH_NONE(rs);

-        ProgramStore blendNone = ProgramStore.BLEND_NONE_DEPTH_NONE(rs);

-

-        RenderState drawTex = new RenderState(mPV_Blur, mPF_Texture, blendAdd, cullNone);

-        RenderState selectCol = new RenderState(mPV_Blur, mPF_SelectColor, blendNone, cullNone);

-        RenderState hBlur = new RenderState(mPV_Blur, mPF_BlurH, blendNone, cullNone);

-        RenderState vBlur = new RenderState(mPV_Blur, mPF_BlurV, blendNone, cullNone);

-

-        // Renders the scene off screen

-        RenderPass blurSourcePass = addPass(scene, cam,

-                                            sRenderTargetBlur0Color,

-                                            sRenderTargetBlur0Depth);

-        blurSourcePass.setClearColor(new Float4(1.0f, 1.0f, 1.0f, 1.0f));

-        blurSourcePass.setShouldClearColor(true);

-        blurSourcePass.setClearDepth(1.0f);

-        blurSourcePass.setShouldClearDepth(true);

-        for (int i = 0; i < numDraw; i ++) {

-            blurSourcePass.appendRenderable((Renderable)allDraw.get(i));

-        }

-

-        // Pass for selecting bright colors

-        RenderPass selectColorPass = addPass(scene, cam,

-                                             sRenderTargetBlur2Color,

-                                             sRenderTargetBlur2Depth);

-        Renderable quad = sceneManager.getRenderableQuad("ScreenAlignedQuadS", selectCol);

-        quad.appendSourceParams(new TextureParam("color", sRenderTargetBlur0Color));

-        selectColorPass.appendRenderable(quad);

-

-        // Horizontal blur

-        RenderPass horizontalBlurPass = addPass(scene, cam,

-                                                sRenderTargetBlur1Color,

-                                                sRenderTargetBlur1Depth);

-        quad = sceneManager.getRenderableQuad("ScreenAlignedQuadH", hBlur);

-        quad.appendSourceParams(new TextureParam("color", sRenderTargetBlur2Color));

-        addOffsets(quad, 1.0f / (float)targetWidth);

-        horizontalBlurPass.appendRenderable(quad);

-

-        // Vertical Blur

-        RenderPass verticalBlurPass = addPass(scene, cam,

-                                              sRenderTargetBlur2Color,

-                                              sRenderTargetBlur2Depth);

-        quad = sceneManager.getRenderableQuad("ScreenAlignedQuadV", vBlur);

-        quad.appendSourceParams(new TextureParam("color", sRenderTargetBlur1Color));

-        addOffsets(quad, 1.0f / (float)targetHeight);

-        verticalBlurPass.appendRenderable(quad);

-    }

-

-    // Additively renders the blurred colors on top of the scene

-    static void addCompositePass(Scene scene, RenderScriptGL rs, Camera cam) {

-        SceneManager sceneManager = SceneManager.getInstance();

-        RenderState drawTex = new RenderState(mPV_Blur, mPF_Texture,

-                                              SceneManager.BLEND_ADD_DEPTH_NONE(rs),

-                                              ProgramRaster.CULL_NONE(rs));

-

-        RenderPass compositePass = addPass(scene, cam, null, null);

-        Renderable quad = sceneManager.getRenderableQuad("ScreenAlignedQuadComposite", drawTex);

-        quad.appendSourceParams(new TextureParam("color", sRenderTargetBlur2Color));

-        compositePass.appendRenderable(quad);

-    }

-

-    static private FragmentShader getShader(Resources res, RenderScriptGL rs,

-                                            int resID, Type constants) {

-        FragmentShader.Builder fb = new FragmentShader.Builder(rs);

-        fb.setShader(res, resID);

-        fb.addTexture(TextureType.TEXTURE_2D, "color");

-        if (constants != null) {

-            fb.setObjectConst(constants);

-        }

-        FragmentShader prog = fb.create();

-        prog.getProgram().bindSampler(Sampler.CLAMP_LINEAR(rs), 0);

-        return prog;

-    }

-

-    static void initShaders(Resources res, RenderScriptGL rs) {

-        ScriptField_BlurOffsets blurConst = new ScriptField_BlurOffsets(rs, 1);

-        VertexShader.Builder vb = new VertexShader.Builder(rs);

-        vb.addInput(ScriptField_VertexShaderInputs.createElement(rs));

-        vb.setShader(res, R.raw.blur_vertex);

-        mPV_Blur = vb.create();

-

-        mPF_Texture = getShader(res, rs, R.raw.texture, null);

-        mPF_Texture.getProgram().bindSampler(Sampler.WRAP_LINEAR_MIP_LINEAR(rs), 0);

-        mPF_BlurH = getShader(res, rs, R.raw.blur_h, blurConst.getAllocation().getType());

-        mPF_BlurV = getShader(res, rs, R.raw.blur_v, blurConst.getAllocation().getType());

-        mPF_SelectColor = getShader(res, rs, R.raw.select_color, null);

-    }

-

-}

-

-

-

-

-

diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/SimpleApp.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/SimpleApp.java
deleted file mode 100644
index 314db80..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/SimpleApp.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testapp;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-import android.view.Window;
-import android.view.Window;
-import android.net.Uri;
-
-import java.lang.Runtime;
-
-public class SimpleApp extends Activity {
-
-    private SimpleAppView mView;
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        // Create our Preview view and set it as the content of our
-        // Activity
-        mView = new SimpleAppView(this);
-        setContentView(mView);
-    }
-}
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/SimpleAppRS.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/SimpleAppRS.java
deleted file mode 100644
index fff6f34..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/SimpleAppRS.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testapp;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Vector;
-
-import com.android.scenegraph.*;
-import com.android.scenegraph.SceneManager.SceneLoadedCallback;
-
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.os.AsyncTask;
-import android.renderscript.*;
-import android.renderscript.Program.TextureType;
-import android.util.Log;
-
-// This is where the scenegraph and the rendered objects are initialized and used
-public class SimpleAppRS {
-    SceneManager mSceneManager;
-
-    RenderScriptGL mRS;
-    Resources mRes;
-
-    Scene mScene;
-    Mesh mSimpleMesh;
-    Mesh mSphereMesh;
-    Mesh mCubeMesh;
-
-    public void init(RenderScriptGL rs, Resources res, int width, int height) {
-        mRS = rs;
-        mRes = res;
-        mSceneManager = SceneManager.getInstance();
-        mSceneManager.initRS(mRS, mRes, width, height);
-
-        mScene = new Scene();
-
-        setupGeometry();
-        setupColoredQuad();
-        setupTexturedQuad();
-        setupShadedGeometry();
-        setupCamera();
-        setupRenderPass();
-
-        mSceneManager.setActiveScene(mScene);
-
-        mScene.initRS();
-        mRS.bindRootScript(mSceneManager.getRenderLoop());
-    }
-
-    private void setupGeometry() {
-        Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS, 3,
-                                                         Mesh.TriangleMeshBuilder.TEXTURE_0);
-
-        // Create four vertices with texture coordinates
-        tmb.setTexture(0.0f, 1.0f).addVertex(-1.0f, 1.0f, 0.0f);
-        tmb.setTexture(0.0f, 0.0f).addVertex(-1.0f, -1.0f, 0.0f);
-        tmb.setTexture(1.0f, 0.0f).addVertex(1.0f, -1.0f, 0.0f);
-        tmb.setTexture(1.0f, 1.0f).addVertex(1.0f, 1.0f, 0.0f);
-
-        tmb.addTriangle(0, 1, 2);
-        tmb.addTriangle(2, 3, 0);
-        mSimpleMesh = tmb.create(true);
-
-        // Load a file that constains two pieces of geometry, a sphere and a cube
-        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.unit_obj);
-        for (int i = 0; i < model.getIndexEntryCount(); i ++) {
-            FileA3D.IndexEntry entry = model.getIndexEntry(i);
-            if (entry != null && entry.getName().equals("CubeMesh")) {
-                mCubeMesh = entry.getMesh();
-            } else if (entry != null && entry.getName().equals("SphereMesh")) {
-                mSphereMesh = entry.getMesh();
-            }
-        }
-    }
-
-    private void setupColoredQuad() {
-        // Built-in shader that provides position, texcoord and normal
-        VertexShader genericV = SceneManager.getDefaultVS();
-        // Built-in shader that displays a color
-        FragmentShader colorF = SceneManager.getColorFS();
-        RenderState colorRS = new RenderState(genericV, colorF, null, null);
-
-        // Draw a simple colored quad
-        Renderable quad = mScene.appendNewRenderable();
-        quad.setMesh(mSimpleMesh);
-        // Our shader has a constant input called "color"
-        // This tells the scenegraph to assign the following float3 to that input
-        quad.appendSourceParams(new Float4Param("color", 0.2f, 0.3f, 0.4f));
-        quad.setRenderState(colorRS);
-    }
-
-    private void setupTexturedQuad() {
-        // Built-in shader that provides position, texcoord and normal
-        VertexShader genericV = SceneManager.getDefaultVS();
-        // Built-in shader that displays a texture
-        FragmentShader textureF = SceneManager.getTextureFS();
-        // We want to use transparency based on the alpha channel of the texture
-        ProgramStore alphaBlend = ProgramStore.BLEND_ALPHA_DEPTH_TEST(mRS);
-        RenderState texRS = new RenderState(genericV, textureF, alphaBlend, null);
-
-        // Draw a textured quad
-        Renderable quad = mScene.appendNewRenderable();
-        quad.setMesh(mSimpleMesh);
-        // Make a transform to position the quad
-        CompoundTransform t = mScene.appendNewCompoundTransform();
-        t.addTranslate("position", new Float3(2, 2, 0));
-        quad.setTransform(t);
-        // Our fragment shader has a constant texture input called "color"
-        // This will assign an icon from drawables to that input
-        quad.appendSourceParams(new TextureParam("color", new Texture2D(R.drawable.icon)));
-        quad.setRenderState(texRS);
-    }
-
-    private FragmentShader createLambertShader() {
-        // Describe what constant inputs our shader wants
-        Element.Builder b = new Element.Builder(mRS);
-        b.add(Element.F32_4(mRS), "cameraPos");
-
-        // Create a shader from a text file in resources
-        FragmentShader.Builder fb = new FragmentShader.Builder(mRS);
-        // Tell the shader what constants we want
-        fb.setShaderConst(new Type.Builder(mRS, b.create()).setX(1).create());
-        // Shader code location
-        fb.setShader(mRes, R.raw.diffuse);
-        // We want a texture called diffuse on our shader
-        fb.addTexture(TextureType.TEXTURE_2D, "diffuse");
-        FragmentShader shader = fb.create();
-        mScene.appendShader(shader);
-        return shader;
-    }
-
-    private void setupShadedGeometry() {
-        // Built-in shader that provides position, texcoord and normal
-        VertexShader genericV = SceneManager.getDefaultVS();
-        // Custom shader
-        FragmentShader diffuseF = createLambertShader();
-        RenderState diffuseRS = new RenderState(genericV, diffuseF, null, null);
-
-        // Draw a sphere
-        Renderable sphere = mScene.appendNewRenderable();
-        // Use the sphere geometry loaded earlier
-        sphere.setMesh(mSphereMesh);
-        // Make a transform to position the sphere
-        CompoundTransform t = mScene.appendNewCompoundTransform();
-        t.addTranslate("position", new Float3(-1, 2, 3));
-        t.addScale("scale", new Float3(1.4f, 1.4f, 1.4f));
-        sphere.setTransform(t);
-        // Tell the renderable which texture to use when we draw
-        // This will mean a texture param in the shader called "diffuse"
-        // will be assigned a texture called red.jpg
-        sphere.appendSourceParams(new TextureParam("diffuse", new Texture2D("", "red.jpg")));
-        sphere.setRenderState(diffuseRS);
-
-        // Draw a cube
-        Renderable cube = mScene.appendNewRenderable();
-        cube.setMesh(mCubeMesh);
-        t = mScene.appendNewCompoundTransform();
-        t.addTranslate("position", new Float3(-2, -2.1f, 0));
-        t.addRotate("rotateX", new Float3(1, 0, 0), 30);
-        t.addRotate("rotateY", new Float3(0, 1, 0), 30);
-        t.addScale("scale", new Float3(2, 2, 2));
-        cube.setTransform(t);
-        cube.appendSourceParams(new TextureParam("diffuse", new Texture2D("", "orange.jpg")));
-        cube.setRenderState(diffuseRS);
-    }
-
-    private void setupCamera() {
-        Camera camera = mScene.appendNewCamera();
-        camera.setFar(200);
-        camera.setNear(0.1f);
-        camera.setFOV(60);
-        CompoundTransform cameraTransform = mScene.appendNewCompoundTransform();
-        cameraTransform.addTranslate("camera", new Float3(0, 0, 10));
-        camera.setTransform(cameraTransform);
-    }
-
-    private void setupRenderPass() {
-        RenderPass mainPass = mScene.appendNewRenderPass();
-        mainPass.setClearColor(new Float4(1.0f, 1.0f, 1.0f, 1.0f));
-        mainPass.setShouldClearColor(true);
-        mainPass.setClearDepth(1.0f);
-        mainPass.setShouldClearDepth(true);
-        mainPass.setCamera(mScene.getCameras().get(0));
-        ArrayList<RenderableBase> allRender = mScene.getRenderables();
-        for (RenderableBase renderable : allRender) {
-            mainPass.appendRenderable((Renderable)renderable);
-        }
-    }
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/SimpleAppView.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/SimpleAppView.java
deleted file mode 100644
index 2112181..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/SimpleAppView.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testapp;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-import android.renderscript.RenderScriptGL;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.util.Log;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-
-public class SimpleAppView extends RSSurfaceView {
-
-    public SimpleAppView(Context context) {
-        super(context);
-    }
-
-    private RenderScriptGL mRS;
-    SimpleAppRS mRender;
-
-    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
-        super.surfaceChanged(holder, format, w, h);
-        if (mRS == null) {
-            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            sc.setDepth(16, 24);
-            sc.setSamples(1, 2, 1);
-            mRS = createRenderScriptGL(sc);
-            mRS.setSurface(holder, w, h);
-            mRender = new SimpleAppRS();
-            mRender.init(mRS, getResources(), w, h);
-        }
-    }
-
-    @Override
-    protected void onDetachedFromWindow() {
-        if (mRS != null) {
-            mRender = null;
-            mRS = null;
-            destroyRenderScriptGL();
-        }
-    }
-}
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestApp.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestApp.java
deleted file mode 100644
index 385a7ab..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestApp.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testapp;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
-import android.app.Activity;
-import android.content.res.Configuration;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.provider.Settings.System;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.Window;
-import android.widget.Button;
-import android.widget.ListView;
-import android.view.MenuInflater;
-import android.view.Window;
-import android.net.Uri;
-
-import java.lang.Runtime;
-
-public class TestApp extends Activity {
-
-    private TestAppView mView;
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        // Create our Preview view and set it as the content of our
-        // Activity
-        mView = new TestAppView(this);
-        setContentView(mView);
-    }
-
-    @Override
-    protected void onResume() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
-        super.onResume();
-        mView.resume();
-    }
-
-    @Override
-    protected void onPause() {
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
-        super.onPause();
-        mView.pause();
-    }
-
-    @Override
-    public boolean onCreateOptionsMenu(Menu menu) {
-        MenuInflater inflater = getMenuInflater();
-        inflater.inflate(R.menu.loader_menu, menu);
-        return true;
-    }
-
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        // Handle item selection
-        switch (item.getItemId()) {
-        case R.id.load_model:
-            loadModel();
-            return true;
-        case R.id.use_blur:
-            mView.mRender.toggleBlur();
-            return true;
-        default:
-            return super.onOptionsItemSelected(item);
-        }
-    }
-
-    private static final int FIND_DAE_MODEL = 10;
-    public void onActivityResult(int requestCode, int resultCode, Intent data) {
-        if (resultCode == RESULT_OK) {
-            if (requestCode == FIND_DAE_MODEL) {
-                Uri selectedImageUri = data.getData();
-                Log.e("Selected Path: ", selectedImageUri.getPath());
-                mView.mRender.loadModel(selectedImageUri.getPath());
-            }
-        }
-    }
-
-    public void loadModel() {
-        Intent intent = new Intent();
-        intent.setAction(Intent.ACTION_PICK);
-        intent.setClassName("com.android.testapp",
-                            "com.android.testapp.FileSelector");
-        startActivityForResult(intent, FIND_DAE_MODEL);
-    }
-
-}
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppLoadingScreen.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppLoadingScreen.java
deleted file mode 100644
index 5bd8f0b..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppLoadingScreen.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testapp;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Vector;
-
-import com.android.scenegraph.SceneManager;
-
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.os.AsyncTask;
-import android.renderscript.*;
-import android.renderscript.Allocation.MipmapControl;
-import android.renderscript.Element.Builder;
-import android.renderscript.Font.Style;
-import android.renderscript.Program.TextureType;
-import android.renderscript.ProgramStore.DepthFunc;
-import android.util.Log;
-
-// This is where the scenegraph and the rendered objects are initialized and used
-public class TestAppLoadingScreen {
-
-    private static String TAG = "TestAppLoadingScreen";
-
-    private Resources mRes;
-    private RenderScriptGL mRS;
-    private ScriptC_test_app mScript;
-
-    public TestAppLoadingScreen(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-        // Shows the loading screen with some text
-        renderLoading();
-        // Adds a little 3D bugdroid model to the laoding screen asynchronously.
-        new LoadingScreenLoaderTask().execute();
-    }
-
-    public void showLoadingScreen(boolean show) {
-        if (show) {
-            mRS.bindRootScript(mScript);
-        } else {
-            mRS.bindRootScript(SceneManager.getInstance().getRenderLoop());
-        }
-    }
-
-    // The loading screen has some elements that shouldn't be loaded on the UI thread
-    private class LoadingScreenLoaderTask extends AsyncTask<String, Void, Boolean> {
-        Allocation robotTex;
-        Mesh robotMesh;
-        protected Boolean doInBackground(String... names) {
-            long start = System.currentTimeMillis();
-            robotTex = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
-                                                           MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                                                           Allocation.USAGE_GRAPHICS_TEXTURE);
-
-            FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
-            FileA3D.IndexEntry entry = model.getIndexEntry(0);
-            if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
-                robotMesh = entry.getMesh();
-            }
-
-            mScript.set_gPFSBackground(ProgramStore.BLEND_NONE_DEPTH_TEST(mRS));
-
-            ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
-            b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
-                         ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
-            ProgramFragment pfDefault = b.create();
-            pfDefault.bindSampler(Sampler.CLAMP_LINEAR(mRS), 0);
-            mScript.set_gPFBackground(pfDefault);
-
-            ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
-            ProgramVertexFixedFunction pvDefault = pvb.create();
-            ProgramVertexFixedFunction.Constants va = new ProgramVertexFixedFunction.Constants(mRS);
-            ((ProgramVertexFixedFunction)pvDefault).bindConstants(va);
-            mScript.set_gPVBackground(pvDefault);
-
-            long end = System.currentTimeMillis();
-            Log.v("TIMER", "Loading load time: " + (end - start));
-            return new Boolean(true);
-        }
-
-        protected void onPostExecute(Boolean result) {
-            mScript.set_gRobotTex(robotTex);
-            mScript.set_gRobotMesh(robotMesh);
-        }
-    }
-
-    // Creates a simple script to show a loding screen until everything is initialized
-    // Could also be used to do some custom renderscript work before handing things over
-    // to the scenegraph
-    void renderLoading() {
-        mScript = new ScriptC_test_app(mRS, mRes, R.raw.test_app);
-        mRS.bindRootScript(mScript);
-    }
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppRS.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppRS.java
deleted file mode 100644
index 3aa80f4..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppRS.java
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Copyright (C) 2011-2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testapp;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Vector;
-
-import com.android.scenegraph.*;
-import com.android.scenegraph.SceneManager.SceneLoadedCallback;
-
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.os.AsyncTask;
-import android.renderscript.*;
-import android.renderscript.Program.TextureType;
-import android.util.Log;
-
-// This is where the scenegraph and the rendered objects are initialized and used
-public class TestAppRS {
-
-    private static String modelName = "orientation_test.dae";
-    private static String TAG = "TestAppRS";
-    private static String mFilePath = "";
-
-    int mWidth;
-    int mHeight;
-
-    boolean mUseBlur;
-
-    TestAppLoadingScreen mLoadingScreen;
-
-    // Used to asynchronously load scene elements like meshes and transform hierarchies
-    SceneLoadedCallback mLoadedCallback = new SceneLoadedCallback() {
-        public void run() {
-            prepareToRender(mLoadedScene);
-        }
-    };
-
-    // Top level class that initializes all the elements needed to use the scene graph
-    SceneManager mSceneManager;
-
-    // Used to move the camera around in the 3D world
-    TouchHandler mTouchHandler;
-
-    private Resources mRes;
-    private RenderScriptGL mRS;
-
-    // Shaders
-    private FragmentShader mPaintF;
-    private FragmentShader mLightsF;
-    private FragmentShader mLightsDiffF;
-    private FragmentShader mAluminumF;
-    private FragmentShader mPlasticF;
-    private FragmentShader mDiffuseF;
-    private FragmentShader mTextureF;
-    private VertexShader mGenericV;
-
-    Scene mActiveScene;
-
-    // This is a part of the test app, it's used to tests multiple render passes and is toggled
-    // on and off in the menu, off by default
-    void toggleBlur() {
-        mUseBlur = !mUseBlur;
-
-        mActiveScene.clearRenderPasses();
-        initRenderPasses();
-        mActiveScene.initRenderPassRS(mRS, mSceneManager);
-
-        // This is just a hardcoded object in the scene that gets turned on and off for the demo
-        // to make things look a bit better. This could be deleted in the cleanup
-        Renderable plane = (Renderable)mActiveScene.getRenderableByName("pPlaneShape1");
-        if (plane != null) {
-            plane.setVisible(!mUseBlur);
-        }
-    }
-
-    public void init(RenderScriptGL rs, Resources res, int width, int height) {
-        mUseBlur = false;
-        mRS = rs;
-        mRes = res;
-        mWidth = width;
-        mHeight = height;
-
-        mTouchHandler = new TouchHandler();
-
-        mSceneManager = SceneManager.getInstance();
-        // Initializes all the RS specific scenegraph elements
-        mSceneManager.initRS(mRS, mRes, mWidth, mHeight);
-
-        mLoadingScreen = new TestAppLoadingScreen(mRS, mRes);
-
-        // Initi renderscript stuff specific to the app. This will need to be abstracted out later.
-        FullscreenBlur.createRenderTargets(mRS, mWidth, mHeight);
-        initPaintShaders();
-
-        // Load a scene to render
-        mSceneManager.loadModel(mFilePath + modelName, mLoadedCallback);
-    }
-
-    // When a new model file is selected from the UI, this function gets called to init everything
-    void loadModel(String path) {
-        mLoadingScreen.showLoadingScreen(true);
-        mActiveScene.destroyRS();
-        mSceneManager.loadModel(path, mLoadedCallback);
-    }
-
-    public void onActionDown(float x, float y) {
-        mTouchHandler.onActionDown(x, y);
-    }
-
-    public void onActionScale(float scale) {
-        mTouchHandler.onActionScale(scale);
-    }
-
-    public void onActionMove(float x, float y) {
-        mTouchHandler.onActionMove(x, y);
-    }
-
-    FragmentShader createFromResource(int id, boolean addCubemap, Type constType) {
-        FragmentShader.Builder fb = new FragmentShader.Builder(mRS);
-        fb.setShaderConst(constType);
-        fb.setShader(mRes, id);
-        fb.addTexture(TextureType.TEXTURE_2D, "diffuse");
-        if (addCubemap) {
-            fb.addShaderTexture(TextureType.TEXTURE_CUBE, "reflection");
-        }
-        FragmentShader pf = fb.create();
-        pf.getProgram().bindSampler(Sampler.WRAP_LINEAR_MIP_LINEAR(mRS), 0);
-        if (addCubemap) {
-            pf.getProgram().bindSampler(Sampler.CLAMP_LINEAR_MIP_LINEAR(mRS), 1);
-        }
-        return pf;
-    }
-
-    private void initPaintShaders() {
-        mGenericV = SceneManager.getDefaultVS();
-
-        ScriptField_CameraParams camParams = new ScriptField_CameraParams(mRS, 1);
-        Type camParamType = camParams.getAllocation().getType();
-        ScriptField_LightParams lightParams = new ScriptField_LightParams(mRS, 1);
-
-        mPaintF = createFromResource(R.raw.paintf, true, camParamType);
-        // Assign a reflection map
-        TextureCube envCube = new TextureCube("sdcard/scenegraph/", "cube_env.png");
-        mPaintF.appendSourceParams(new TextureParam("reflection", envCube));
-
-        mAluminumF = createFromResource(R.raw.metal, true, camParamType);
-        TextureCube diffCube = new TextureCube("sdcard/scenegraph/", "cube_spec.png");
-        mAluminumF.appendSourceParams(new TextureParam("reflection", diffCube));
-
-        mPlasticF = createFromResource(R.raw.plastic, false, camParamType);
-        mDiffuseF = createFromResource(R.raw.diffuse, false, camParamType);
-        mTextureF = SceneManager.getTextureFS();
-
-        FragmentShader.Builder fb = new FragmentShader.Builder(mRS);
-        fb.setObjectConst(lightParams.getAllocation().getType());
-        fb.setShader(mRes, R.raw.plastic_lights);
-        mLightsF = fb.create();
-
-        fb = new FragmentShader.Builder(mRS);
-        fb.setObjectConst(lightParams.getAllocation().getType());
-        fb.setShader(mRes, R.raw.diffuse_lights);
-        mLightsDiffF = fb.create();
-
-        FullscreenBlur.initShaders(mRes, mRS);
-    }
-
-    void initRenderPasses() {
-        ArrayList<RenderableBase> allDraw = mActiveScene.getRenderables();
-        int numDraw = allDraw.size();
-
-        if (mUseBlur) {
-            FullscreenBlur.addBlurPasses(mActiveScene, mRS, mTouchHandler.getCamera());
-        }
-
-        RenderPass mainPass = new RenderPass();
-        mainPass.setClearColor(new Float4(1.0f, 1.0f, 1.0f, 1.0f));
-        mainPass.setShouldClearColor(true);
-        mainPass.setClearDepth(1.0f);
-        mainPass.setShouldClearDepth(true);
-        mainPass.setCamera(mTouchHandler.getCamera());
-        for (int i = 0; i < numDraw; i ++) {
-            mainPass.appendRenderable((Renderable)allDraw.get(i));
-        }
-        mActiveScene.appendRenderPass(mainPass);
-
-        if (mUseBlur) {
-            FullscreenBlur.addCompositePass(mActiveScene, mRS, mTouchHandler.getCamera());
-        }
-    }
-
-    private void addShadersToScene() {
-        mActiveScene.appendShader(mPaintF);
-        mActiveScene.appendShader(mLightsF);
-        mActiveScene.appendShader(mLightsDiffF);
-        mActiveScene.appendShader(mAluminumF);
-        mActiveScene.appendShader(mPlasticF);
-        mActiveScene.appendShader(mDiffuseF);
-        mActiveScene.appendShader(mTextureF);
-    }
-
-    public void prepareToRender(Scene s) {
-        mSceneManager.setActiveScene(s);
-        mActiveScene = s;
-        mTouchHandler.init(mActiveScene);
-        addShadersToScene();
-        RenderState plastic = new RenderState(mGenericV, mPlasticF, null, null);
-        RenderState diffuse = new RenderState(mGenericV, mDiffuseF, null, null);
-        RenderState paint = new RenderState(mGenericV, mPaintF, null, null);
-        RenderState aluminum = new RenderState(mGenericV, mAluminumF, null, null);
-        RenderState lights = new RenderState(mGenericV, mLightsF, null, null);
-        RenderState diff_lights = new RenderState(mGenericV, mLightsDiffF, null, null);
-        RenderState diff_lights_no_cull = new RenderState(mGenericV, mLightsDiffF, null,
-                                                          ProgramRaster.CULL_NONE(mRS));
-        RenderState glassTransp = new RenderState(mGenericV, mPaintF,
-                                                  ProgramStore.BLEND_ALPHA_DEPTH_TEST(mRS), null);
-        RenderState texState = new RenderState(mGenericV, mTextureF, null, null);
-
-        initRenderPasses();
-
-        mActiveScene.assignRenderState(plastic);
-
-        mActiveScene.assignRenderStateToMaterial(diffuse, "lambert2$");
-
-        mActiveScene.assignRenderStateToMaterial(paint, "^Paint");
-        mActiveScene.assignRenderStateToMaterial(paint, "^Carbon");
-        mActiveScene.assignRenderStateToMaterial(paint, "^Glass");
-        mActiveScene.assignRenderStateToMaterial(paint, "^MainGlass");
-
-        mActiveScene.assignRenderStateToMaterial(aluminum, "^Metal");
-        mActiveScene.assignRenderStateToMaterial(aluminum, "^Brake");
-
-        mActiveScene.assignRenderStateToMaterial(glassTransp, "^GlassLight");
-
-        mActiveScene.assignRenderStateToMaterial(lights, "^LightBlinn");
-        mActiveScene.assignRenderStateToMaterial(diff_lights, "^LightLambert");
-        mActiveScene.assignRenderStateToMaterial(diff_lights_no_cull, "^LightLambertNoCull");
-        mActiveScene.assignRenderStateToMaterial(texState, "^TextureOnly");
-
-        Renderable plane = (Renderable)mActiveScene.getRenderableByName("pPlaneShape1");
-        if (plane != null) {
-            plane.setRenderState(texState);
-            plane.setVisible(!mUseBlur);
-        }
-
-        long start = System.currentTimeMillis();
-        mActiveScene.initRS();
-        long end = System.currentTimeMillis();
-        Log.v("TIMER", "Scene init time: " + (end - start));
-
-        mLoadingScreen.showLoadingScreen(false);
-    }
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppView.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppView.java
deleted file mode 100644
index 33ca1b8..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppView.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testapp;
-
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-import android.renderscript.RenderScriptGL;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.Handler;
-import android.os.Message;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-import android.view.ScaleGestureDetector;
-
-public class TestAppView extends RSSurfaceView {
-
-    public TestAppView(Context context) {
-        super(context);
-        mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
-    }
-
-    private RenderScriptGL mRS;
-    TestAppRS mRender;
-
-    private ScaleGestureDetector mScaleDetector;
-    private static final int INVALID_POINTER_ID = -1;
-    private int mActivePointerId = INVALID_POINTER_ID;
-
-    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
-        super.surfaceChanged(holder, format, w, h);
-        if (mRS == null) {
-            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            sc.setDepth(16, 24);
-            sc.setSamples(1, 2, 1);
-            mRS = createRenderScriptGL(sc);
-            mRS.setSurface(holder, w, h);
-            mRender = new TestAppRS();
-            mRender.init(mRS, getResources(), w, h);
-        }
-    }
-
-    @Override
-    protected void onDetachedFromWindow() {
-        if (mRS != null) {
-            mRender = null;
-            mRS = null;
-            destroyRenderScriptGL();
-        }
-    }
-
-    @Override
-    public boolean onKeyDown(int keyCode, KeyEvent event)
-    {
-        // break point at here
-        // this method doesn't work when 'extends View' include 'extends ScrollView'.
-        return super.onKeyDown(keyCode, event);
-    }
-
-
-    @Override
-    public boolean onTouchEvent(MotionEvent ev) {
-        mScaleDetector.onTouchEvent(ev);
-
-        boolean ret = false;
-        float x = ev.getX();
-        float y = ev.getY();
-
-        final int action = ev.getAction();
-
-        switch (action & MotionEvent.ACTION_MASK) {
-        case MotionEvent.ACTION_DOWN: {
-            mRender.onActionDown(x, y);
-            mActivePointerId = ev.getPointerId(0);
-            ret = true;
-            break;
-        }
-        case MotionEvent.ACTION_MOVE: {
-            if (!mScaleDetector.isInProgress()) {
-                mRender.onActionMove(x, y);
-            }
-            mRender.onActionDown(x, y);
-            ret = true;
-            break;
-        }
-
-        case MotionEvent.ACTION_UP: {
-            mActivePointerId = INVALID_POINTER_ID;
-            break;
-        }
-
-        case MotionEvent.ACTION_CANCEL: {
-            mActivePointerId = INVALID_POINTER_ID;
-            break;
-        }
-
-        case MotionEvent.ACTION_POINTER_UP: {
-            final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
-                    >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
-            final int pointerId = ev.getPointerId(pointerIndex);
-            if (pointerId == mActivePointerId) {
-                // This was our active pointer going up. Choose a new
-                // active pointer and adjust accordingly.
-                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
-                x = ev.getX(newPointerIndex);
-                y = ev.getY(newPointerIndex);
-                mRender.onActionDown(x, y);
-                mActivePointerId = ev.getPointerId(newPointerIndex);
-            }
-            break;
-        }
-        }
-
-        return ret;
-    }
-
-    private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
-        @Override
-        public boolean onScale(ScaleGestureDetector detector) {
-            mRender.onActionScale(detector.getScaleFactor());
-            return true;
-        }
-    }
-}
-
-
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TouchHandler.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TouchHandler.java
deleted file mode 100644
index d0f9797..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TouchHandler.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testapp;
-
-import android.util.Log;
-import android.renderscript.Float3;
-import com.android.scenegraph.*;
-import com.android.scenegraph.CompoundTransform.RotateComponent;
-import com.android.scenegraph.CompoundTransform.TranslateComponent;
-
-public class TouchHandler {
-    private static String TAG = "TouchHandler";
-
-    float mLastX;
-    float mLastY;
-
-    float mRotateXValue;
-    float mRotateYValue;
-    Float3 mDistValue;
-    Float3 mPosValue;
-
-    CompoundTransform mCameraRig;
-    RotateComponent mRotateX;
-    RotateComponent mRotateY;
-    TranslateComponent mDist;
-    TranslateComponent mPosition;
-    Camera mCamera;
-
-    public void init(Scene scene) {
-        // Some initial values for camera position
-        mRotateXValue = -20;
-        mRotateYValue = 0;
-        mDistValue = new Float3(0, 0, 45);
-        mPosValue = new Float3(0, 4, 0);
-
-        // Make a camera transform we can manipulate
-        mCameraRig = scene.appendNewCompoundTransform();
-        mCameraRig.setName("CameraRig");
-
-        mPosition = mCameraRig.addTranslate("Position", mPosValue);
-        mRotateY  = mCameraRig.addRotate("RotateY", new Float3(0, 1, 0), mRotateYValue);
-        mRotateX  = mCameraRig.addRotate("RotateX", new Float3(1, 0, 0), mRotateXValue);
-        mDist     = mCameraRig.addTranslate("Distance", mDistValue);
-
-        mCamera = scene.appendNewCamera();
-        mCamera.setTransform(mCameraRig);
-    }
-
-    public Camera getCamera() {
-        return mCamera;
-    }
-
-    public void onActionDown(float x, float y) {
-        mLastX = x;
-        mLastY = y;
-    }
-
-    public void onActionScale(float scale) {
-        if (mDist == null) {
-            return;
-        }
-        mDistValue.z *= 1.0f / scale;
-        mDistValue.z = Math.max(10.0f, Math.min(mDistValue.z, 150.0f));
-        mDist.setValue(mDistValue);
-    }
-
-    public void onActionMove(float x, float y) {
-        if (mRotateX == null) {
-            return;
-        }
-
-        float dx = mLastX - x;
-        float dy = mLastY - y;
-
-        if (Math.abs(dy) <= 2.0f) {
-            dy = 0.0f;
-        }
-        if (Math.abs(dx) <= 2.0f) {
-            dx = 0.0f;
-        }
-
-        mRotateYValue += dx * 0.25f;
-        mRotateYValue %= 360.0f;
-
-        mRotateXValue  += dy * 0.25f;
-        mRotateXValue  = Math.max(mRotateXValue , -80.0f);
-        mRotateXValue  = Math.min(mRotateXValue , 0.0f);
-
-        mRotateX.setAngle(mRotateXValue);
-        mRotateY.setAngle(mRotateYValue);
-
-        mLastX = x;
-        mLastY = y;
-    }
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rs
deleted file mode 100644
index d94da52..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rs
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.testapp)
-
-#include "rs_graphics.rsh"
-#include "test_app.rsh"
-
-// Making sure these get reflected
-FBlurOffsets *blurExport;
-VShaderInputs *iExport;
-FShaderParams *fConst;
-FShaderLightParams *fConts2;
-VSParams *vConst2;
-VObjectParams *vConst3;
-
-rs_program_vertex gPVBackground;
-rs_program_fragment gPFBackground;
-
-rs_allocation gRobotTex;
-rs_mesh gRobotMesh;
-
-rs_program_store gPFSBackground;
-
-float gRotate;
-
-void init() {
-    gRotate = 0.0f;
-}
-
-static float gRotateY = 120.0f;
-static float gZoom = 50.0f;
-static void displayLoading() {
-    if (rsIsObject(gRobotTex) && rsIsObject(gRobotMesh)) {
-        rsgBindProgramVertex(gPVBackground);
-        rs_matrix4x4 proj;
-        float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
-        rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f);
-        rsgProgramVertexLoadProjectionMatrix(&proj);
-
-        rsgBindProgramFragment(gPFBackground);
-        rsgBindProgramStore(gPFSBackground);
-        rsgBindTexture(gPFBackground, 0, gRobotTex);
-
-        rs_matrix4x4 matrix;
-        rsMatrixLoadIdentity(&matrix);
-        // Position our models on the screen
-        gRotateY += rsGetDt()*100;
-        rsMatrixTranslate(&matrix, 0, 0, -gZoom);
-        rsMatrixRotate(&matrix, 20.0f, 1.0f, 0.0f, 0.0f);
-        rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
-        rsMatrixScale(&matrix, 0.2f, 0.2f, 0.2f);
-        rsgProgramVertexLoadModelMatrix(&matrix);
-        rsgDrawMesh(gRobotMesh);
-    }
-
-    uint width = rsgGetWidth();
-    uint height = rsgGetHeight();
-    int left = 0, right = 0, top = 0, bottom = 0;
-    const char* text = "Initializing...";
-    rsgMeasureText(text, &left, &right, &top, &bottom);
-    int centeredPos = width / 2 - (right - left) / 2;
-    rsgDrawText(text, centeredPos, height / 2 + height / 10);
-}
-
-int root(void) {
-    rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgClearDepth(1.0f);
-    displayLoading();
-    return 30;
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rsh
deleted file mode 100644
index 5fbcbb2..0000000
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rsh
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright (C) 2012 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.testapp)
-
-// Helpers
-typedef struct ViewProjParams {
-    rs_matrix4x4 viewProj;
-} VSParams;
-
-typedef struct ModelParams {
-    rs_matrix4x4 model;
-} VObjectParams;
-
-typedef struct CameraParams {
-    float4 cameraPos;
-} FShaderParams;
-
-typedef struct LightParams {
-    float4 lightPos_0;
-    float4 lightColor_0;
-    float4 lightPos_1;
-    float4 lightColor_1;
-    float4 cameraPos;
-    float4 diffuse;
-} FShaderLightParams;
-
-typedef struct BlurOffsets {
-    float blurOffset0;
-    float blurOffset1;
-    float blurOffset2;
-    float blurOffset3;
-} FBlurOffsets;
-
-typedef struct VertexShaderInputs {
-    float4 position;
-    float3 normal;
-    float2 texture0;
-} VShaderInputs;
diff --git a/tests/RenderScriptTests/ShadersTest/Android.mk b/tests/RenderScriptTests/ShadersTest/Android.mk
deleted file mode 100644
index fb6356e..0000000
--- a/tests/RenderScriptTests/ShadersTest/Android.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Copyright (C) 2011 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
-
-LOCAL_SDK_VERSION := 17
-
-LOCAL_PACKAGE_NAME := ShadersTest
-
-include $(BUILD_PACKAGE)
diff --git a/tests/RenderScriptTests/ShadersTest/AndroidManifest.xml b/tests/RenderScriptTests/ShadersTest/AndroidManifest.xml
deleted file mode 100644
index 871200d..0000000
--- a/tests/RenderScriptTests/ShadersTest/AndroidManifest.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-  
-          http://www.apache.org/licenses/LICENSE-2.0
-  
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.android.shaderstest">
-
-    <uses-permission android:name="android.permission.INTERNET" />
-    
-    <application android:label="_ShadersTest">
-        <activity android:name="ShadersTest"
-                  android:label="_ShadersTest"
-                  android:theme="@android:style/Theme.Black.NoTitleBar">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-    </application>
-</manifest>
diff --git a/tests/RenderScriptTests/ShadersTest/res/drawable-nodpi/robot.png b/tests/RenderScriptTests/ShadersTest/res/drawable-nodpi/robot.png
deleted file mode 100644
index f7353fd..0000000
--- a/tests/RenderScriptTests/ShadersTest/res/drawable-nodpi/robot.png
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/ShadersTest/res/raw/depth_fs.glsl b/tests/RenderScriptTests/ShadersTest/res/raw/depth_fs.glsl
deleted file mode 100644
index 096843b..0000000
--- a/tests/RenderScriptTests/ShadersTest/res/raw/depth_fs.glsl
+++ /dev/null
@@ -1,13 +0,0 @@
-void main() {
-    // Non-linear depth value
-    float z = gl_FragCoord.z;
-    // Near and far planes from the projection
-    // In practice, these values can be used to tweak
-    // the focus range
-    float n = UNI_near;
-    float f = UNI_far;
-    // Linear depth value
-    z = (2.0 * n) / (f + n - z * (f - n));
-
-    gl_FragColor = vec4(z, z, z, 1.0);
-}
diff --git a/tests/RenderScriptTests/ShadersTest/res/raw/robot.a3d b/tests/RenderScriptTests/ShadersTest/res/raw/robot.a3d
deleted file mode 100644
index f48895c..0000000
--- a/tests/RenderScriptTests/ShadersTest/res/raw/robot.a3d
+++ /dev/null
Binary files differ
diff --git a/tests/RenderScriptTests/ShadersTest/res/raw/vignette_fs.glsl b/tests/RenderScriptTests/ShadersTest/res/raw/vignette_fs.glsl
deleted file mode 100644
index 2dc1ea3..0000000
--- a/tests/RenderScriptTests/ShadersTest/res/raw/vignette_fs.glsl
+++ /dev/null
@@ -1,31 +0,0 @@
-#define CRT_MASK
-
-varying vec2 varTex0;
-
-void main() {
-    lowp vec4 color = texture2D(UNI_Tex0, varTex0);
-    
-    vec2 powers = pow(abs((gl_FragCoord.xy / vec2(UNI_width, UNI_height)) - 0.5), vec2(2.0));
-    float gradient = smoothstep(UNI_size - UNI_feather, UNI_size + UNI_feather,
-            powers.x + powers.y);
-
-    color = vec4(mix(color.rgb, vec3(0.0), gradient), 1.0);
-
-#ifdef CRT_MASK
-    float vShift = gl_FragCoord.y;
-    if (mod(gl_FragCoord.x, 6.0) >= 3.0) {
-        vShift += 2.0;
-    }
-
-    lowp vec3 r = vec3(0.95, 0.0, 0.2);
-    lowp vec3 g = vec3(0.2, 0.95, 0.0);
-    lowp vec3 b = vec3(0.0, 0.2, 0.95);
-    int channel = int(floor(mod(gl_FragCoord.x, 3.0)));
-    lowp vec4 crt = vec4(r[channel], g[channel], b[channel], 1.0);
-    crt *= clamp(floor(mod(vShift, 4.0)), 0.0, 1.0);
-    
-    color = (crt * color * 1.25) + 0.05;
-#endif
-
-    gl_FragColor = color;
-}
diff --git a/tests/RenderScriptTests/ShadersTest/src/com/android/shaderstest/ShadersTest.java b/tests/RenderScriptTests/ShadersTest/src/com/android/shaderstest/ShadersTest.java
deleted file mode 100644
index 6803fbb..0000000
--- a/tests/RenderScriptTests/ShadersTest/src/com/android/shaderstest/ShadersTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.shaderstest;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-@SuppressWarnings({"UnusedDeclaration"})
-public class ShadersTest extends Activity {
-
-    private ShadersTestView mView;
-
-    @Override
-    public void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        mView = new ShadersTestView(this);
-        setContentView(mView);
-    }
-
-    @Override
-    protected void onResume() {
-        super.onResume();
-        mView.resume();
-    }
-
-    @Override
-    protected void onPause() {
-        super.onPause();
-        mView.pause();
-    }
-}
diff --git a/tests/RenderScriptTests/ShadersTest/src/com/android/shaderstest/ShadersTestRS.java b/tests/RenderScriptTests/ShadersTest/src/com/android/shaderstest/ShadersTestRS.java
deleted file mode 100644
index dad97e2..0000000
--- a/tests/RenderScriptTests/ShadersTest/src/com/android/shaderstest/ShadersTestRS.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.shaderstest;
-
-import android.content.res.Resources;
-import android.renderscript.Allocation;
-import android.renderscript.Element;
-import android.renderscript.Element.DataKind;
-import android.renderscript.Element.DataType;
-import android.renderscript.FileA3D;
-import android.renderscript.Mesh;
-import android.renderscript.Program;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramFragmentFixedFunction;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramStore.DepthFunc;
-import android.renderscript.ProgramVertex;
-import android.renderscript.ProgramVertexFixedFunction;
-import android.renderscript.RSRuntimeException;
-import android.renderscript.RenderScriptGL;
-import android.renderscript.Sampler;
-import android.renderscript.Type.Builder;
-
-@SuppressWarnings({"FieldCanBeLocal"})
-public class ShadersTestRS {
-    public ShadersTestRS() {
-    }
-
-    public void init(RenderScriptGL rs, Resources res) {
-        mRS = rs;
-        mRes = res;
-        initRS();
-    }
-
-    public void surfaceChanged() {
-        initBuffers(mRS.getWidth(), mRS.getHeight());
-    }
-
-    private Resources mRes;
-    private RenderScriptGL mRS;
-    private Sampler mLinearClamp;
-    private Sampler mNearestClamp;
-    private ProgramStore mPSBackground;
-    private ProgramFragment mPFBackground;
-    private ProgramVertex mPVBackground;
-    private ProgramVertexFixedFunction.Constants mPVA;
-
-    private ProgramFragment mPFVignette;
-    private ScriptField_VignetteConstants_s mFSVignetteConst;
-
-    private Allocation mMeshTexture;
-    private Allocation mScreen;
-    private Allocation mScreenDepth;
-
-    private ScriptField_MeshInfo mMeshes;
-    private ScriptC_shaderstest mScript;
-
-
-    public void onActionDown(float x, float y) {
-        mScript.invoke_onActionDown(x, y);
-    }
-
-    public void onActionScale(float scale) {
-        mScript.invoke_onActionScale(scale);
-    }
-
-    public void onActionMove(float x, float y) {
-        mScript.invoke_onActionMove(x, y);
-    }
-
-    private void initPFS() {
-        ProgramStore.Builder b = new ProgramStore.Builder(mRS);
-
-        b.setDepthFunc(DepthFunc.LESS);
-        b.setDitherEnabled(false);
-        b.setDepthMaskEnabled(true);
-        mPSBackground = b.create();
-
-        mScript.set_gPFSBackground(mPSBackground);
-    }
-
-    private void initPF() {
-        mLinearClamp = Sampler.CLAMP_LINEAR(mRS);
-        mScript.set_gLinear(mLinearClamp);
-
-        mNearestClamp = Sampler.CLAMP_NEAREST(mRS);
-        mScript.set_gNearest(mNearestClamp);
-
-        ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
-        b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
-                     ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
-        mPFBackground = b.create();
-        mPFBackground.bindSampler(mLinearClamp, 0);
-        mScript.set_gPFBackground(mPFBackground);
-
-        mFSVignetteConst = new ScriptField_VignetteConstants_s(mRS, 1);
-        mScript.bind_gFSVignetteConstants(mFSVignetteConst);
-
-        ProgramFragment.Builder fs;
-
-        fs = new ProgramFragment.Builder(mRS);
-        fs.setShader(mRes, R.raw.vignette_fs);
-        fs.addConstant(mFSVignetteConst.getAllocation().getType());
-        fs.addTexture(Program.TextureType.TEXTURE_2D);
-        mPFVignette = fs.create();
-        mPFVignette.bindConstants(mFSVignetteConst.getAllocation(), 0);
-        mScript.set_gPFVignette(mPFVignette);
-    }
-
-    private void initPV() {
-        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
-        mPVBackground = pvb.create();
-
-        mPVA = new ProgramVertexFixedFunction.Constants(mRS);
-        ((ProgramVertexFixedFunction) mPVBackground).bindConstants(mPVA);
-
-        mScript.set_gPVBackground(mPVBackground);
-    }
-
-    private void loadImage() {
-        mMeshTexture = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
-                Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
-                Allocation.USAGE_GRAPHICS_TEXTURE);
-        mScript.set_gTMesh(mMeshTexture);
-    }
-
-    private void initMeshes(FileA3D model) {
-        int numEntries = model.getIndexEntryCount();
-        int numMeshes = 0;
-        for (int i = 0; i < numEntries; i ++) {
-            FileA3D.IndexEntry entry = model.getIndexEntry(i);
-            if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
-                numMeshes ++;
-            }
-        }
-
-        if (numMeshes > 0) {
-            mMeshes = new ScriptField_MeshInfo(mRS, numMeshes);
-
-            for (int i = 0; i < numEntries; i ++) {
-                FileA3D.IndexEntry entry = model.getIndexEntry(i);
-                if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
-                    Mesh mesh = entry.getMesh();
-                    mMeshes.set_mMesh(i, mesh, false);
-                    mMeshes.set_mNumIndexSets(i, mesh.getPrimitiveCount(), false);
-                }
-            }
-            mMeshes.copyAll();
-        } else {
-            throw new RSRuntimeException("No valid meshes in file");
-        }
-
-        mScript.bind_gMeshes(mMeshes);
-        mScript.invoke_updateMeshInfo();
-    }
-
-    private void initRS() {
-        mScript = new ScriptC_shaderstest(mRS, mRes, R.raw.shaderstest);
-
-        initPFS();
-        initPF();
-        initPV();
-
-        loadImage();
-
-        initBuffers(1, 1);
-
-        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
-        initMeshes(model);
-
-        mRS.bindRootScript(mScript);
-    }
-
-    private void initBuffers(int width, int height) {
-        Builder b;
-        b = new Builder(mRS, Element.RGBA_8888(mRS));
-        b.setX(width).setY(height);
-        mScreen = Allocation.createTyped(mRS, b.create(),
-                Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_GRAPHICS_RENDER_TARGET);
-        mScript.set_gScreen(mScreen);
-
-        b = new Builder(mRS, Element.createPixel(mRS, DataType.UNSIGNED_16, DataKind.PIXEL_DEPTH));
-        b.setX(width).setY(height);
-        mScreenDepth = Allocation.createTyped(mRS, b.create(),
-                Allocation.USAGE_GRAPHICS_RENDER_TARGET);
-        mScript.set_gScreenDepth(mScreenDepth);
-    }
-}
diff --git a/tests/RenderScriptTests/ShadersTest/src/com/android/shaderstest/ShadersTestView.java b/tests/RenderScriptTests/ShadersTest/src/com/android/shaderstest/ShadersTestView.java
deleted file mode 100644
index e0a540f..0000000
--- a/tests/RenderScriptTests/ShadersTest/src/com/android/shaderstest/ShadersTestView.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.shaderstest;
-
-import android.content.Context;
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScriptGL;
-import android.view.MotionEvent;
-import android.view.ScaleGestureDetector;
-import android.view.SurfaceHolder;
-
-public class ShadersTestView extends RSSurfaceView {
-
-    private RenderScriptGL mRS;
-    private ShadersTestRS mRender;
-
-    private ScaleGestureDetector mScaleDetector;
-
-    private static final int INVALID_POINTER_ID = -1;
-    private int mActivePointerId = INVALID_POINTER_ID;
-
-    public ShadersTestView(Context context) {
-        super(context);
-        ensureRenderScript();
-        mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
-    }
-
-    private void ensureRenderScript() {
-        if (mRS == null) {
-            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            sc.setDepth(16, 24);
-            mRS = createRenderScriptGL(sc);
-            mRender = new ShadersTestRS();
-            mRender.init(mRS, getResources());
-        }
-    }
-
-    @Override
-    protected void onAttachedToWindow() {
-        super.onAttachedToWindow();
-        ensureRenderScript();
-    }
-
-    @Override
-    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
-        super.surfaceChanged(holder, format, w, h);
-        mRender.surfaceChanged();
-    }
-
-    @Override
-    protected void onDetachedFromWindow() {
-        mRender = null;
-        if (mRS != null) {
-            mRS = null;
-            destroyRenderScriptGL();
-        }
-    }
-
-    @Override
-    public boolean onTouchEvent(MotionEvent ev) {
-        mScaleDetector.onTouchEvent(ev);
-
-        boolean ret = false;
-        float x = ev.getX();
-        float y = ev.getY();
-
-        final int action = ev.getAction();
-
-        switch (action & MotionEvent.ACTION_MASK) {
-        case MotionEvent.ACTION_DOWN: {
-            mRender.onActionDown(x, y);
-            mActivePointerId = ev.getPointerId(0);
-            ret = true;
-            break;
-        }
-        case MotionEvent.ACTION_MOVE: {
-            if (!mScaleDetector.isInProgress()) {
-                mRender.onActionMove(x, y);
-            }
-            mRender.onActionDown(x, y);
-            ret = true;
-            break;
-        }
-
-        case MotionEvent.ACTION_UP: {
-            mActivePointerId = INVALID_POINTER_ID;
-            break;
-        }
-
-        case MotionEvent.ACTION_CANCEL: {
-            mActivePointerId = INVALID_POINTER_ID;
-            break;
-        }
-
-        case MotionEvent.ACTION_POINTER_UP: {
-            final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
-                    >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
-            final int pointerId = ev.getPointerId(pointerIndex);
-            if (pointerId == mActivePointerId) {
-                // This was our active pointer going up. Choose a new
-                // active pointer and adjust accordingly.
-                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
-                x = ev.getX(newPointerIndex);
-                y = ev.getY(newPointerIndex);
-                mRender.onActionDown(x, y);
-                mActivePointerId = ev.getPointerId(newPointerIndex);
-            }
-            break;
-        }
-        }
-
-        return ret;
-    }
-
-    private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
-        @Override
-        public boolean onScale(ScaleGestureDetector detector) {
-            mRender.onActionScale(detector.getScaleFactor());
-            return true;
-        }
-    }
-}
-
-
diff --git a/tests/RenderScriptTests/ShadersTest/src/com/android/shaderstest/shaderstest.rs b/tests/RenderScriptTests/ShadersTest/src/com/android/shaderstest/shaderstest.rs
deleted file mode 100644
index 735f6b9..0000000
--- a/tests/RenderScriptTests/ShadersTest/src/com/android/shaderstest/shaderstest.rs
+++ /dev/null
@@ -1,200 +0,0 @@
-// Copyright (C) 2011 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.shaderstest)
-
-#include "rs_graphics.rsh"
-
-rs_program_vertex gPVBackground;
-rs_program_fragment gPFBackground;
-
-typedef struct VignetteConstants_s {
-    float size;
-    float feather;
-    float width;
-    float height;
-} VignetteConstants;
-VignetteConstants *gFSVignetteConstants;
-rs_program_fragment gPFVignette;
-
-rs_allocation gTMesh;
-
-rs_sampler gLinear;
-rs_sampler gNearest;
-
-rs_program_store gPFSBackground;
-
-rs_allocation gScreenDepth;
-rs_allocation gScreen;
-
-typedef struct MeshInfo {
-    rs_mesh mMesh;
-    int mNumIndexSets;
-    float3 bBoxMin;
-    float3 bBoxMax;
-} MeshInfo_t;
-MeshInfo_t *gMeshes;
-
-static float3 gLookAt;
-
-static float gRotateX;
-static float gRotateY;
-static float gZoom;
-
-static float gLastX;
-static float gLastY;
-
-static float3 toFloat3(float x, float y, float z) {
-    float3 f;
-    f.x = x;
-    f.y = y;
-    f.z = z;
-    return f;
-}
-
-void onActionDown(float x, float y) {
-    gLastX = x;
-    gLastY = y;
-}
-
-void onActionScale(float scale) {
-
-    gZoom *= 1.0f / scale;
-    gZoom = max(0.1f, min(gZoom, 500.0f));
-}
-
-void onActionMove(float x, float y) {
-    float dx = gLastX - x;
-    float dy = gLastY - y;
-
-    if (fabs(dy) <= 2.0f) {
-        dy = 0.0f;
-    }
-    if (fabs(dx) <= 2.0f) {
-        dx = 0.0f;
-    }
-
-    gRotateY -= dx;
-    if (gRotateY > 360) {
-        gRotateY -= 360;
-    }
-    if (gRotateY < 0) {
-        gRotateY += 360;
-    }
-
-    gRotateX -= dy;
-    gRotateX = min(gRotateX, 80.0f);
-    gRotateX = max(gRotateX, -80.0f);
-
-    gLastX = x;
-    gLastY = y;
-}
-
-void init() {
-    gRotateX = 0.0f;
-    gRotateY = 0.0f;
-    gZoom = 50.0f;
-    gLookAt = 0.0f;
-}
-
-void updateMeshInfo() {
-    rs_allocation allMeshes = rsGetAllocation(gMeshes);
-    int size = rsAllocationGetDimX(allMeshes);
-    gLookAt = 0.0f;
-    float minX, minY, minZ, maxX, maxY, maxZ;
-    for (int i = 0; i < size; i++) {
-        MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
-        rsgMeshComputeBoundingBox(info->mMesh,
-                                  &minX, &minY, &minZ,
-                                  &maxX, &maxY, &maxZ);
-        info->bBoxMin = toFloat3(minX, minY, minZ);
-        info->bBoxMax = toFloat3(maxX, maxY, maxZ);
-        gLookAt += (info->bBoxMin + info->bBoxMax)*0.5f;
-    }
-    gLookAt = gLookAt / (float)size;
-}
-
-static void renderAllMeshes() {
-    rs_allocation allMeshes = rsGetAllocation(gMeshes);
-    int size = rsAllocationGetDimX(allMeshes);
-    gLookAt = 0.0f;
-    for (int i = 0; i < size; i++) {
-        MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
-        rsgDrawMesh(info->mMesh);
-    }
-}
-
-static void renderOffscreen() {
-    rsgBindProgramVertex(gPVBackground);
-    rs_matrix4x4 proj;
-    float aspect = (float) rsAllocationGetDimX(gScreen) / (float) rsAllocationGetDimY(gScreen);
-    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 1000.0f);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-
-    rsgBindProgramFragment(gPFBackground);
-    rsgBindTexture(gPFBackground, 0, gTMesh);
-
-    rs_matrix4x4 matrix;
-
-    rsMatrixLoadIdentity(&matrix);
-    rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
-    rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
-    rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-
-    renderAllMeshes();
-}
-
-static void drawOffscreenResult(int posX, int posY, float width, float height) {
-    // display the result d
-    rs_matrix4x4 proj, matrix;
-    rsMatrixLoadOrtho(&proj, 0, width, height, 0, -500, 500);
-    rsgProgramVertexLoadProjectionMatrix(&proj);
-    rsMatrixLoadIdentity(&matrix);
-    rsgProgramVertexLoadModelMatrix(&matrix);
-    float startX = posX, startY = posY;
-    rsgDrawQuadTexCoords(startX, startY, 0, 0, 1,
-                         startX, startY + height, 0, 0, 0,
-                         startX + width, startY + height, 0, 1, 0,
-                         startX + width, startY, 0, 1, 1);
-}
-
-int root(void) {
-    gFSVignetteConstants->size = 0.58f * 0.58f;
-    gFSVignetteConstants->feather = 0.2f;
-    gFSVignetteConstants->width = (float) rsAllocationGetDimX(gScreen);
-    gFSVignetteConstants->height = (float) rsAllocationGetDimY(gScreen);
-
-    rsgBindProgramStore(gPFSBackground);
-
-    // Render scene to fullscreenbuffer
-    rsgBindColorTarget(gScreen, 0);
-    rsgBindDepthTarget(gScreenDepth);
-    rsgClearDepth(1.0f);
-    rsgClearColor(1.0f, 1.0f, 1.0f, 0.0f);
-    renderOffscreen();
-
-    // Render on screen
-    rsgClearAllRenderTargets();
-    rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
-    rsgClearDepth(1.0f);
-
-    rsgBindProgramFragment(gPFVignette);
-    rsgBindTexture(gPFVignette, 0, gScreen);
-    drawOffscreenResult(0, 0, rsgGetWidth(), rsgGetHeight());
-
-    return 0;
-}
diff --git a/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java b/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java
index 3c2659f..b78fd49 100644
--- a/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java
+++ b/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java
@@ -93,7 +93,7 @@
 
         try {
             mWm.addAppToken(0, null, 0, 0, 0, false, false, 0, 0, false, false, null,
-                    Configuration.EMPTY, false);
+                    Configuration.EMPTY, false, false);
             fail("IWindowManager.addAppToken did not throw SecurityException as"
                     + " expected");
         } catch (SecurityException e) {
diff --git a/tools/aapt/Images.cpp b/tools/aapt/Images.cpp
index e4738f5..5ad3379 100644
--- a/tools/aapt/Images.cpp
+++ b/tools/aapt/Images.cpp
@@ -1095,13 +1095,6 @@
     analyze_image(imageName, imageInfo, grayscaleTolerance, rgbPalette, alphaPalette,
                   &paletteEntries, &hasTransparency, &color_type, outRows);
 
-    // If the image is a 9-patch, we need to preserve it as a ARGB file to make
-    // sure the pixels will not be pre-dithered/clamped until we decide they are
-    if (imageInfo.is9Patch && (color_type == PNG_COLOR_TYPE_RGB ||
-            color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_PALETTE)) {
-        color_type = PNG_COLOR_TYPE_RGB_ALPHA;
-    }
-
     if (kIsDebug) {
         switch (color_type) {
         case PNG_COLOR_TYPE_PALETTE:
@@ -1180,18 +1173,11 @@
         }
 
         for (int i = 0; i < chunk_count; i++) {
-            unknowns[i].location = PNG_HAVE_PLTE;
+            unknowns[i].location = PNG_HAVE_IHDR;
         }
         png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_ALWAYS,
                                     chunk_names, chunk_count);
         png_set_unknown_chunks(write_ptr, write_info, unknowns, chunk_count);
-#if PNG_LIBPNG_VER < 10600
-        /* Deal with unknown chunk location bug in 1.5.x and earlier */
-        png_set_unknown_chunk_location(write_ptr, write_info, 0, PNG_HAVE_PLTE);
-        if (imageInfo.haveLayoutBounds) {
-            png_set_unknown_chunk_location(write_ptr, write_info, 1, PNG_HAVE_PLTE);
-        }
-#endif
     }
 
 
diff --git a/tools/aapt2/Android.mk b/tools/aapt2/Android.mk
index 0f83980..a4f4ba9 100644
--- a/tools/aapt2/Android.mk
+++ b/tools/aapt2/Android.mk
@@ -27,6 +27,8 @@
 sources := \
 	compile/IdAssigner.cpp \
 	compile/Png.cpp \
+	compile/PseudolocaleGenerator.cpp \
+	compile/Pseudolocalizer.cpp \
 	compile/XmlIdCollector.cpp \
 	flatten/Archive.cpp \
 	flatten/TableFlattener.cpp \
@@ -66,6 +68,8 @@
 
 testSources := \
 	compile/IdAssigner_test.cpp \
+	compile/PseudolocaleGenerator_test.cpp \
+	compile/Pseudolocalizer_test.cpp \
 	compile/XmlIdCollector_test.cpp \
 	flatten/FileExportWriter_test.cpp \
 	flatten/TableFlattener_test.cpp \
diff --git a/tools/aapt2/Debug.cpp b/tools/aapt2/Debug.cpp
index d864f66..5fce2c1 100644
--- a/tools/aapt2/Debug.cpp
+++ b/tools/aapt2/Debug.cpp
@@ -52,13 +52,17 @@
     void visit(Style* style) override {
         std::cout << "(style)";
         if (style->parent) {
+            const Reference& parentRef = style->parent.value();
             std::cout << " parent=";
-            if (style->parent.value().name) {
-                std::cout << style->parent.value().name.value() << " ";
+            if (parentRef.name) {
+                if (parentRef.privateReference) {
+                    std::cout << "*";
+                }
+                std::cout << parentRef.name.value() << " ";
             }
 
-            if (style->parent.value().id) {
-                std::cout << style->parent.value().id.value();
+            if (parentRef.id) {
+                std::cout << parentRef.id.value();
             }
         }
 
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp
index d4c536f..e1f9642 100644
--- a/tools/aapt2/ResourceParser.cpp
+++ b/tools/aapt2/ResourceParser.cpp
@@ -19,9 +19,12 @@
 #include "ResourceUtils.h"
 #include "ResourceValues.h"
 #include "ValueVisitor.h"
+#include "util/Comparators.h"
+#include "util/ImmutableMap.h"
 #include "util/Util.h"
 #include "xml/XmlPullParser.h"
 
+#include <functional>
 #include <sstream>
 
 namespace aapt {
@@ -35,6 +38,111 @@
     return ns.empty() && (name == u"skip" || name == u"eat-comment");
 }
 
+static uint32_t parseFormatType(const StringPiece16& piece) {
+    if (piece == u"reference")      return android::ResTable_map::TYPE_REFERENCE;
+    else if (piece == u"string")    return android::ResTable_map::TYPE_STRING;
+    else if (piece == u"integer")   return android::ResTable_map::TYPE_INTEGER;
+    else if (piece == u"boolean")   return android::ResTable_map::TYPE_BOOLEAN;
+    else if (piece == u"color")     return android::ResTable_map::TYPE_COLOR;
+    else if (piece == u"float")     return android::ResTable_map::TYPE_FLOAT;
+    else if (piece == u"dimension") return android::ResTable_map::TYPE_DIMENSION;
+    else if (piece == u"fraction")  return android::ResTable_map::TYPE_FRACTION;
+    else if (piece == u"enum")      return android::ResTable_map::TYPE_ENUM;
+    else if (piece == u"flags")     return android::ResTable_map::TYPE_FLAGS;
+    return 0;
+}
+
+static uint32_t parseFormatAttribute(const StringPiece16& str) {
+    uint32_t mask = 0;
+    for (StringPiece16 part : util::tokenize(str, u'|')) {
+        StringPiece16 trimmedPart = util::trimWhitespace(part);
+        uint32_t type = parseFormatType(trimmedPart);
+        if (type == 0) {
+            return 0;
+        }
+        mask |= type;
+    }
+    return mask;
+}
+
+/**
+ * A parsed resource ready to be added to the ResourceTable.
+ */
+struct ParsedResource {
+    ResourceName name;
+    Source source;
+    ResourceId id;
+    Maybe<SymbolState> symbolState;
+    std::u16string comment;
+    std::unique_ptr<Value> value;
+    std::list<ParsedResource> childResources;
+};
+
+bool ResourceParser::shouldStripResource(const ResourceNameRef& name,
+                                         const Maybe<std::u16string>& product) const {
+    if (product) {
+        for (const std::u16string& productToMatch : mOptions.products) {
+            if (product.value() == productToMatch) {
+                // We specified a product, and it is in the list, so don't strip.
+                return false;
+            }
+        }
+    }
+
+    // Nothing matched, try 'default'. Default only matches if we didn't already use another
+    // product variant.
+    if (!product || product.value() == u"default") {
+        if (Maybe<ResourceTable::SearchResult> result = mTable->findResource(name)) {
+            const ResourceEntry* entry = result.value().entry;
+            auto iter = std::lower_bound(entry->values.begin(), entry->values.end(), mConfig,
+                                         cmp::lessThanConfig);
+            if (iter != entry->values.end() && iter->config == mConfig && !iter->value->isWeak()) {
+                // We have a value for this config already, and it is not weak,
+                // so filter out this default.
+                return true;
+            }
+        }
+        return false;
+    }
+    return true;
+}
+
+// Recursively adds resources to the ResourceTable.
+static bool addResourcesToTable(ResourceTable* table, const ConfigDescription& config,
+                                IDiagnostics* diag, ParsedResource* res) {
+    if (res->symbolState) {
+        Symbol symbol;
+        symbol.state = res->symbolState.value();
+        symbol.source = res->source;
+        symbol.comment = res->comment;
+        if (!table->setSymbolState(res->name, res->id, symbol, diag)) {
+            return false;
+        }
+    }
+
+    if (res->value) {
+        // Attach the comment, source and config to the value.
+        res->value->setComment(std::move(res->comment));
+        res->value->setSource(std::move(res->source));
+
+        if (!table->addResource(res->name, res->id, config, std::move(res->value), diag)) {
+            return false;
+        }
+    }
+
+    bool error = false;
+    for (ParsedResource& child : res->childResources) {
+        error |= !addResourcesToTable(table, config, diag, &child);
+    }
+    return !error;
+}
+
+// Convenient aliases for more readable function calls.
+enum {
+    kAllowRawString = true,
+    kNoRawString = false
+};
+
 ResourceParser::ResourceParser(IDiagnostics* diag, ResourceTable* table, const Source& source,
                                const ConfigDescription& config,
                                const ResourceParserOptions& options) :
@@ -146,69 +254,6 @@
     return !error;
 }
 
-static bool shouldStripResource(const xml::XmlPullParser* parser,
-                                const Maybe<std::u16string> productToMatch) {
-    assert(parser->getEvent() == xml::XmlPullParser::Event::kStartElement);
-
-    if (Maybe<StringPiece16> maybeProduct = xml::findNonEmptyAttribute(parser, u"product")) {
-        if (!productToMatch) {
-            if (maybeProduct.value() != u"default" && maybeProduct.value() != u"phone") {
-                // We didn't specify a product and this is not a default product, so skip.
-                return true;
-            }
-        } else {
-            if (productToMatch && maybeProduct.value() != productToMatch.value()) {
-                // We specified a product, but they don't match.
-                return true;
-            }
-        }
-    }
-    return false;
-}
-
-/**
- * A parsed resource ready to be added to the ResourceTable.
- */
-struct ParsedResource {
-    ResourceName name;
-    Source source;
-    ResourceId id;
-    Maybe<SymbolState> symbolState;
-    std::u16string comment;
-    std::unique_ptr<Value> value;
-    std::list<ParsedResource> childResources;
-};
-
-// Recursively adds resources to the ResourceTable.
-static bool addResourcesToTable(ResourceTable* table, const ConfigDescription& config,
-                                IDiagnostics* diag, ParsedResource* res) {
-    if (res->symbolState) {
-        Symbol symbol;
-        symbol.state = res->symbolState.value();
-        symbol.source = res->source;
-        symbol.comment = res->comment;
-        if (!table->setSymbolState(res->name, res->id, symbol, diag)) {
-            return false;
-        }
-    }
-
-    if (res->value) {
-        // Attach the comment, source and config to the value.
-        res->value->setComment(std::move(res->comment));
-        res->value->setSource(std::move(res->source));
-
-        if (!table->addResource(res->name, res->id, config, std::move(res->value), diag)) {
-            return false;
-        }
-    }
-
-    bool error = false;
-    for (ParsedResource& child : res->childResources) {
-        error |= !addResourcesToTable(table, config, diag, &child);
-    }
-    return !error;
-}
-
 bool ResourceParser::parseResources(xml::XmlPullParser* parser) {
     std::set<ResourceName> strippedResources;
 
@@ -244,118 +289,28 @@
             continue;
         }
 
-        if (elementName == u"item") {
-            // Items simply have their type encoded in the type attribute.
-            if (Maybe<StringPiece16> maybeType = xml::findNonEmptyAttribute(parser, u"type")) {
-                elementName = maybeType.value().toString();
-            } else {
-                mDiag->error(DiagMessage(mSource.withLine(parser->getLineNumber()))
-                             << "<item> must have a 'type' attribute");
-                error = true;
-                continue;
-            }
-        }
-
         ParsedResource parsedResource;
         parsedResource.source = mSource.withLine(parser->getLineNumber());
         parsedResource.comment = std::move(comment);
 
-        if (Maybe<StringPiece16> maybeName = xml::findNonEmptyAttribute(parser, u"name")) {
-            parsedResource.name.entry = maybeName.value().toString();
+        // Extract the product name if it exists.
+        Maybe<std::u16string> product;
+        if (Maybe<StringPiece16> maybeProduct = xml::findNonEmptyAttribute(parser, u"product")) {
+            product = maybeProduct.value().toString();
+        }
 
-        } else if (elementName != u"public-group") {
-            mDiag->error(DiagMessage(mSource.withLine(parser->getLineNumber()))
-                         << "<" << elementName << "> tag must have a 'name' attribute");
+        // Parse the resource regardless of product.
+        if (!parseResource(parser, &parsedResource)) {
             error = true;
             continue;
         }
 
-        // Check if we should skip this product.
-        const bool stripResource = shouldStripResource(parser, mOptions.product);
-
-        bool result = true;
-        if (elementName == u"id") {
-            parsedResource.name.type = ResourceType::kId;
-            parsedResource.value = util::make_unique<Id>();
-        } else if (elementName == u"string") {
-            parsedResource.name.type = ResourceType::kString;
-            result = parseString(parser, &parsedResource);
-        } else if (elementName == u"color") {
-            parsedResource.name.type = ResourceType::kColor;
-            result = parseColor(parser, &parsedResource);
-        } else if (elementName == u"drawable") {
-            parsedResource.name.type = ResourceType::kDrawable;
-            result = parseColor(parser, &parsedResource);
-        } else if (elementName == u"bool") {
-            parsedResource.name.type = ResourceType::kBool;
-            result = parsePrimitive(parser, &parsedResource);
-        } else if (elementName == u"integer") {
-            parsedResource.name.type = ResourceType::kInteger;
-            result = parsePrimitive(parser, &parsedResource);
-        } else if (elementName == u"dimen") {
-            parsedResource.name.type = ResourceType::kDimen;
-            result = parsePrimitive(parser, &parsedResource);
-        } else if (elementName == u"fraction") {
-            parsedResource.name.type = ResourceType::kFraction;
-            result = parsePrimitive(parser, &parsedResource);
-        } else if (elementName == u"style") {
-            parsedResource.name.type = ResourceType::kStyle;
-            result = parseStyle(parser, &parsedResource);
-        } else if (elementName == u"plurals") {
-            parsedResource.name.type = ResourceType::kPlurals;
-            result = parsePlural(parser, &parsedResource);
-        } else if (elementName == u"array") {
-            parsedResource.name.type = ResourceType::kArray;
-            result = parseArray(parser, &parsedResource, android::ResTable_map::TYPE_ANY);
-        } else if (elementName == u"string-array") {
-            parsedResource.name.type = ResourceType::kArray;
-            result = parseArray(parser, &parsedResource, android::ResTable_map::TYPE_STRING);
-        } else if (elementName == u"integer-array") {
-            parsedResource.name.type = ResourceType::kArray;
-            result = parseArray(parser, &parsedResource, android::ResTable_map::TYPE_INTEGER);
-        } else if (elementName == u"declare-styleable") {
-            parsedResource.name.type = ResourceType::kStyleable;
-            result = parseDeclareStyleable(parser, &parsedResource);
-        } else if (elementName == u"attr") {
-            parsedResource.name.type = ResourceType::kAttr;
-            result = parseAttr(parser, &parsedResource);
-        } else if (elementName == u"public") {
-            result = parsePublic(parser, &parsedResource);
-        } else if (elementName == u"java-symbol" || elementName == u"symbol") {
-            result = parseSymbol(parser, &parsedResource);
-        } else if (elementName == u"public-group") {
-            result = parsePublicGroup(parser, &parsedResource);
-        } else if (elementName == u"add-resource") {
-            result = parseAddResource(parser, &parsedResource);
-        } else {
-            // Try parsing the elementName (or type) as a resource. These shall only be
-            // resources like 'layout' or 'xml' and they can only be references.
-            if (const ResourceType* type = parseResourceType(elementName)) {
-                parsedResource.name.type = *type;
-                parsedResource.value = parseXml(parser, android::ResTable_map::TYPE_REFERENCE,
-                                                false);
-                if (!parsedResource.value) {
-                    mDiag->error(DiagMessage(parsedResource.source) << "invalid value for type '"
-                                 << *type << "'. Expected a reference");
-                    result = false;
-                }
-            } else {
-                mDiag->warn(DiagMessage(mSource.withLine(parser->getLineNumber()))
-                            << "unknown resource type '" << elementName << "'");
-            }
-        }
-
-        if (result) {
-            // We successfully parsed the resource.
-
-            if (stripResource) {
-                // Record that we stripped out this resource name.
-                // We will check that at least one variant of this resource was included.
-                strippedResources.insert(parsedResource.name);
-            } else {
-                error |= !addResourcesToTable(mTable, mConfig, mDiag, &parsedResource);
-            }
-        } else {
+        // We successfully parsed the resource. Check if we should include it or strip it.
+        if (shouldStripResource(parsedResource.name, product)) {
+            // Record that we stripped out this resource name.
+            // We will check that at least one variant of this resource was included.
+            strippedResources.insert(parsedResource.name);
+        } else if (!addResourcesToTable(mTable, mConfig, mDiag, &parsedResource)) {
             error = true;
         }
     }
@@ -373,10 +328,173 @@
     return !error;
 }
 
-enum {
-    kAllowRawString = true,
-    kNoRawString = false
-};
+
+bool ResourceParser::parseResource(xml::XmlPullParser* parser, ParsedResource* outResource) {
+    struct ItemTypeFormat {
+        ResourceType type;
+        uint32_t format;
+    };
+
+    using BagParseFunc = std::function<bool(ResourceParser*, xml::XmlPullParser*, ParsedResource*)>;
+
+    static const auto elToItemMap = ImmutableMap<std::u16string, ItemTypeFormat>::createPreSorted({
+            { u"bool",      { ResourceType::kBool, android::ResTable_map::TYPE_BOOLEAN } },
+            { u"color",     { ResourceType::kColor, android::ResTable_map::TYPE_COLOR } },
+            { u"dimen",     { ResourceType::kDimen, android::ResTable_map::TYPE_FLOAT
+                                                    | android::ResTable_map::TYPE_FRACTION
+                                                    | android::ResTable_map::TYPE_DIMENSION } },
+            { u"drawable",  { ResourceType::kDrawable, android::ResTable_map::TYPE_COLOR } },
+            { u"fraction",  { ResourceType::kFraction, android::ResTable_map::TYPE_FLOAT
+                                                       | android::ResTable_map::TYPE_FRACTION
+                                                       | android::ResTable_map::TYPE_DIMENSION } },
+            { u"integer",   { ResourceType::kInteger, android::ResTable_map::TYPE_INTEGER } },
+            { u"string",    { ResourceType::kString, android::ResTable_map::TYPE_STRING } },
+    });
+
+    static const auto elToBagMap = ImmutableMap<std::u16string, BagParseFunc>::createPreSorted({
+            { u"add-resource",      std::mem_fn(&ResourceParser::parseAddResource) },
+            { u"array",             std::mem_fn(&ResourceParser::parseArray) },
+            { u"attr",              std::mem_fn(&ResourceParser::parseAttr) },
+            { u"declare-styleable", std::mem_fn(&ResourceParser::parseDeclareStyleable) },
+            { u"integer-array",     std::mem_fn(&ResourceParser::parseIntegerArray) },
+            { u"java-symbol",       std::mem_fn(&ResourceParser::parseSymbol) },
+            { u"plurals",           std::mem_fn(&ResourceParser::parsePlural) },
+            { u"public",            std::mem_fn(&ResourceParser::parsePublic) },
+            { u"public-group",      std::mem_fn(&ResourceParser::parsePublicGroup) },
+            { u"string-array",      std::mem_fn(&ResourceParser::parseStringArray) },
+            { u"style",             std::mem_fn(&ResourceParser::parseStyle) },
+            { u"symbol",            std::mem_fn(&ResourceParser::parseSymbol) },
+    });
+
+    std::u16string resourceType = parser->getElementName();
+
+    // The value format accepted for this resource.
+    uint32_t resourceFormat = 0u;
+
+    if (resourceType == u"item") {
+        // Items have their type encoded in the type attribute.
+        if (Maybe<StringPiece16> maybeType = xml::findNonEmptyAttribute(parser, u"type")) {
+            resourceType = maybeType.value().toString();
+        } else {
+            mDiag->error(DiagMessage(mSource.withLine(parser->getLineNumber()))
+                         << "<item> must have a 'type' attribute");
+            return false;
+        }
+
+        if (Maybe<StringPiece16> maybeFormat = xml::findNonEmptyAttribute(parser, u"format")) {
+            // An explicit format for this resource was specified. The resource will retain
+            // its type in its name, but the accepted value for this type is overridden.
+            resourceFormat = parseFormatType(maybeFormat.value());
+            if (!resourceFormat) {
+                mDiag->error(DiagMessage(outResource->source)
+                             << "'" << maybeFormat.value() << "' is an invalid format");
+                return false;
+            }
+        }
+    }
+
+    // Get the name of the resource. This will be checked later, because not all
+    // XML elements require a name.
+    Maybe<StringPiece16> maybeName = xml::findNonEmptyAttribute(parser, u"name");
+
+    if (resourceType == u"id") {
+        if (!maybeName) {
+            mDiag->error(DiagMessage(outResource->source)
+                         << "<" << parser->getElementName() << "> missing 'name' attribute");
+            return false;
+        }
+
+        outResource->name.type = ResourceType::kId;
+        outResource->name.entry = maybeName.value().toString();
+        outResource->value = util::make_unique<Id>();
+        return true;
+    }
+
+    const auto itemIter = elToItemMap.find(resourceType);
+    if (itemIter != elToItemMap.end()) {
+        // This is an item, record its type and format and start parsing.
+
+        if (!maybeName) {
+            mDiag->error(DiagMessage(outResource->source)
+                         << "<" << parser->getElementName() << "> missing 'name' attribute");
+            return false;
+        }
+
+        outResource->name.type = itemIter->second.type;
+        outResource->name.entry = maybeName.value().toString();
+
+        // Only use the implicit format for this type if it wasn't overridden.
+        if (!resourceFormat) {
+            resourceFormat = itemIter->second.format;
+        }
+
+        if (!parseItem(parser, outResource, resourceFormat)) {
+            return false;
+        }
+        return true;
+    }
+
+    // This might be a bag or something.
+    const auto bagIter = elToBagMap.find(resourceType);
+    if (bagIter != elToBagMap.end()) {
+        // Ensure we have a name (unless this is a <public-group>).
+        if (resourceType != u"public-group") {
+            if (!maybeName) {
+                mDiag->error(DiagMessage(outResource->source)
+                             << "<" << parser->getElementName() << "> missing 'name' attribute");
+                return false;
+            }
+
+            outResource->name.entry = maybeName.value().toString();
+        }
+
+        // Call the associated parse method. The type will be filled in by the
+        // parse func.
+        if (!bagIter->second(this, parser, outResource)) {
+            return false;
+        }
+        return true;
+    }
+
+    // Try parsing the elementName (or type) as a resource. These shall only be
+    // resources like 'layout' or 'xml' and they can only be references.
+    const ResourceType* parsedType = parseResourceType(resourceType);
+    if (parsedType) {
+        if (!maybeName) {
+            mDiag->error(DiagMessage(outResource->source)
+                         << "<" << parser->getElementName() << "> missing 'name' attribute");
+            return false;
+        }
+
+        outResource->name.type = *parsedType;
+        outResource->name.entry = maybeName.value().toString();
+        outResource->value = parseXml(parser, android::ResTable_map::TYPE_REFERENCE, kNoRawString);
+        if (!outResource->value) {
+            mDiag->error(DiagMessage(outResource->source)
+                         << "invalid value for type '" << *parsedType << "'. Expected a reference");
+            return false;
+        }
+        return true;
+    }
+
+    mDiag->warn(DiagMessage(outResource->source)
+                << "unknown resource type '" << parser->getElementName() << "'");
+    return false;
+}
+
+bool ResourceParser::parseItem(xml::XmlPullParser* parser, ParsedResource* outResource,
+                               const uint32_t format) {
+    if (format == android::ResTable_map::TYPE_STRING) {
+        return parseString(parser, outResource);
+    }
+
+    outResource->value = parseXml(parser, format, kNoRawString);
+    if (!outResource->value) {
+        mDiag->error(DiagMessage(outResource->source) << "invalid " << outResource->name.type);
+        return false;
+    }
+    return true;
+}
 
 /**
  * Reads the entire XML subtree and attempts to parse it as some Item,
@@ -431,17 +549,15 @@
         return util::make_unique<RawString>(
                 mTable->stringPool.makeRef(rawValue, StringPool::Context{ 1, mConfig }));
     }
-
     return {};
 }
 
 bool ResourceParser::parseString(xml::XmlPullParser* parser, ParsedResource* outResource) {
-    const Source source = mSource.withLine(parser->getLineNumber());
-
     bool formatted = true;
     if (Maybe<StringPiece16> formattedAttr = xml::findAttribute(parser, u"formatted")) {
         if (!ResourceUtils::tryParseBool(formattedAttr.value(), &formatted)) {
-            mDiag->error(DiagMessage(source) << "invalid value for 'formatted'. Must be a boolean");
+            mDiag->error(DiagMessage(outResource->source)
+                         << "invalid value for 'formatted'. Must be a boolean");
             return false;
         }
     }
@@ -449,7 +565,7 @@
     bool translateable = mOptions.translatable;
     if (Maybe<StringPiece16> translateableAttr = xml::findAttribute(parser, u"translatable")) {
         if (!ResourceUtils::tryParseBool(translateableAttr.value(), &translateable)) {
-            mDiag->error(DiagMessage(source)
+            mDiag->error(DiagMessage(outResource->source)
                          << "invalid value for 'translatable'. Must be a boolean");
             return false;
         }
@@ -457,81 +573,39 @@
 
     outResource->value = parseXml(parser, android::ResTable_map::TYPE_STRING, kNoRawString);
     if (!outResource->value) {
-        mDiag->error(DiagMessage(source) << "not a valid string");
+        mDiag->error(DiagMessage(outResource->source) << "not a valid string");
         return false;
     }
 
-    if (formatted && translateable) {
-        if (String* stringValue = valueCast<String>(outResource->value.get())) {
+    if (String* stringValue = valueCast<String>(outResource->value.get())) {
+        stringValue->setTranslateable(translateable);
+
+        if (formatted && translateable) {
             if (!util::verifyJavaStringFormat(*stringValue->value)) {
-                mDiag->error(DiagMessage(source)
+                mDiag->error(DiagMessage(outResource->source)
                              << "multiple substitutions specified in non-positional format; "
                                 "did you mean to add the formatted=\"false\" attribute?");
                 return false;
             }
         }
-    }
-    return true;
-}
 
-bool ResourceParser::parseColor(xml::XmlPullParser* parser, ParsedResource* outResource) {
-    const Source source = mSource.withLine(parser->getLineNumber());
-
-    outResource->value = parseXml(parser, android::ResTable_map::TYPE_COLOR, kNoRawString);
-    if (!outResource->value) {
-        mDiag->error(DiagMessage(source) << "invalid color");
-        return false;
-    }
-    return true;
-}
-
-bool ResourceParser::parsePrimitive(xml::XmlPullParser* parser, ParsedResource* outResource) {
-    const Source source = mSource.withLine(parser->getLineNumber());
-
-    uint32_t typeMask = 0;
-    switch (outResource->name.type) {
-    case ResourceType::kInteger:
-        typeMask |= android::ResTable_map::TYPE_INTEGER;
-        break;
-
-    case ResourceType::kFraction:
-        // fallthrough
-    case ResourceType::kDimen:
-        typeMask |= android::ResTable_map::TYPE_DIMENSION
-                  | android::ResTable_map::TYPE_FLOAT
-                  | android::ResTable_map::TYPE_FRACTION;
-        break;
-
-    case ResourceType::kBool:
-        typeMask |= android::ResTable_map::TYPE_BOOLEAN;
-        break;
-
-    default:
-        assert(false);
-        break;
-    }
-
-    outResource->value = parseXml(parser, typeMask, kNoRawString);
-    if (!outResource->value) {
-        mDiag->error(DiagMessage(source) << "invalid " << outResource->name.type);
-        return false;
+    } else if (StyledString* stringValue = valueCast<StyledString>(outResource->value.get())) {
+        stringValue->setTranslateable(translateable);
     }
     return true;
 }
 
 bool ResourceParser::parsePublic(xml::XmlPullParser* parser, ParsedResource* outResource) {
-    const Source source = mSource.withLine(parser->getLineNumber());
-
     Maybe<StringPiece16> maybeType = xml::findNonEmptyAttribute(parser, u"type");
     if (!maybeType) {
-        mDiag->error(DiagMessage(source) << "<public> must have a 'type' attribute");
+        mDiag->error(DiagMessage(outResource->source) << "<public> must have a 'type' attribute");
         return false;
     }
 
     const ResourceType* parsedType = parseResourceType(maybeType.value());
     if (!parsedType) {
-        mDiag->error(DiagMessage(source) << "invalid resource type '" << maybeType.value()
-                     << "' in <public>");
+        mDiag->error(DiagMessage(outResource->source)
+                     << "invalid resource type '" << maybeType.value() << "' in <public>");
         return false;
     }
 
@@ -543,8 +617,8 @@
                                                      maybeId.value().size(), &val);
         ResourceId resourceId(val.data);
         if (!result || !resourceId.isValid()) {
-            mDiag->error(DiagMessage(source) << "invalid resource ID '" << maybeId.value()
-                         << "' in <public>");
+            mDiag->error(DiagMessage(outResource->source)
+                         << "invalid resource ID '" << maybeId.value() << "' in <public>");
             return false;
         }
         outResource->id = resourceId;
@@ -560,24 +634,24 @@
 }
 
 bool ResourceParser::parsePublicGroup(xml::XmlPullParser* parser, ParsedResource* outResource) {
-    const Source source = mSource.withLine(parser->getLineNumber());
-
     Maybe<StringPiece16> maybeType = xml::findNonEmptyAttribute(parser, u"type");
     if (!maybeType) {
-        mDiag->error(DiagMessage(source) << "<public-group> must have a 'type' attribute");
+        mDiag->error(DiagMessage(outResource->source)
+                     << "<public-group> must have a 'type' attribute");
         return false;
     }
 
     const ResourceType* parsedType = parseResourceType(maybeType.value());
     if (!parsedType) {
-        mDiag->error(DiagMessage(source) << "invalid resource type '" << maybeType.value()
-                     << "' in <public-group>");
+        mDiag->error(DiagMessage(outResource->source)
+                     << "invalid resource type '" << maybeType.value() << "' in <public-group>");
         return false;
     }
 
     Maybe<StringPiece16> maybeId = xml::findNonEmptyAttribute(parser, u"first-id");
     if (!maybeId) {
-        mDiag->error(DiagMessage(source) << "<public-group> must have a 'first-id' attribute");
+        mDiag->error(DiagMessage(outResource->source)
+                     << "<public-group> must have a 'first-id' attribute");
         return false;
     }
 
@@ -586,8 +660,8 @@
                                                  maybeId.value().size(), &val);
     ResourceId nextId(val.data);
     if (!result || !nextId.isValid()) {
-        mDiag->error(DiagMessage(source) << "invalid resource ID '" << maybeId.value()
-                     << "' in <public-group>");
+        mDiag->error(DiagMessage(outResource->source)
+                     << "invalid resource ID '" << maybeId.value() << "' in <public-group>");
         return false;
     }
 
@@ -646,18 +720,17 @@
 }
 
 bool ResourceParser::parseSymbolImpl(xml::XmlPullParser* parser, ParsedResource* outResource) {
-    const Source source = mSource.withLine(parser->getLineNumber());
-
     Maybe<StringPiece16> maybeType = xml::findNonEmptyAttribute(parser, u"type");
     if (!maybeType) {
-        mDiag->error(DiagMessage(source) << "<" << parser->getElementName() << "> must have a "
-                     "'type' attribute");
+        mDiag->error(DiagMessage(outResource->source)
+                     << "<" << parser->getElementName() << "> must have a 'type' attribute");
         return false;
     }
 
     const ResourceType* parsedType = parseResourceType(maybeType.value());
     if (!parsedType) {
-        mDiag->error(DiagMessage(source) << "invalid resource type '" << maybeType.value()
+        mDiag->error(DiagMessage(outResource->source)
+                     << "invalid resource type '" << maybeType.value()
                      << "' in <" << parser->getElementName() << ">");
         return false;
     }
@@ -682,40 +755,15 @@
     return false;
 }
 
-static uint32_t parseFormatType(const StringPiece16& piece) {
-    if (piece == u"reference")      return android::ResTable_map::TYPE_REFERENCE;
-    else if (piece == u"string")    return android::ResTable_map::TYPE_STRING;
-    else if (piece == u"integer")   return android::ResTable_map::TYPE_INTEGER;
-    else if (piece == u"boolean")   return android::ResTable_map::TYPE_BOOLEAN;
-    else if (piece == u"color")     return android::ResTable_map::TYPE_COLOR;
-    else if (piece == u"float")     return android::ResTable_map::TYPE_FLOAT;
-    else if (piece == u"dimension") return android::ResTable_map::TYPE_DIMENSION;
-    else if (piece == u"fraction")  return android::ResTable_map::TYPE_FRACTION;
-    else if (piece == u"enum")      return android::ResTable_map::TYPE_ENUM;
-    else if (piece == u"flags")     return android::ResTable_map::TYPE_FLAGS;
-    return 0;
-}
-
-static uint32_t parseFormatAttribute(const StringPiece16& str) {
-    uint32_t mask = 0;
-    for (StringPiece16 part : util::tokenize(str, u'|')) {
-        StringPiece16 trimmedPart = util::trimWhitespace(part);
-        uint32_t type = parseFormatType(trimmedPart);
-        if (type == 0) {
-            return 0;
-        }
-        mask |= type;
-    }
-    return mask;
-}
 
 bool ResourceParser::parseAttr(xml::XmlPullParser* parser, ParsedResource* outResource) {
-    outResource->source = mSource.withLine(parser->getLineNumber());
     return parseAttrImpl(parser, outResource, false);
 }
 
 bool ResourceParser::parseAttrImpl(xml::XmlPullParser* parser, ParsedResource* outResource,
                                    bool weak) {
+    outResource->name.type = ResourceType::kAttr;
+
     uint32_t typeMask = 0;
 
     Maybe<StringPiece16> maybeFormat = xml::findAttribute(parser, u"format");
@@ -949,7 +997,8 @@
 }
 
 bool ResourceParser::parseStyle(xml::XmlPullParser* parser, ParsedResource* outResource) {
-    const Source source = mSource.withLine(parser->getLineNumber());
+    outResource->name.type = ResourceType::kStyle;
+
     std::unique_ptr<Style> style = util::make_unique<Style>();
 
     Maybe<StringPiece16> maybeParent = xml::findAttribute(parser, u"parent");
@@ -959,7 +1008,7 @@
             std::string errStr;
             style->parent = ResourceUtils::parseStyleParentReference(maybeParent.value(), &errStr);
             if (!style->parent) {
-                mDiag->error(DiagMessage(source) << errStr);
+                mDiag->error(DiagMessage(outResource->source) << errStr);
                 return false;
             }
 
@@ -1007,9 +1056,22 @@
     return true;
 }
 
-bool ResourceParser::parseArray(xml::XmlPullParser* parser, ParsedResource* outResource,
-                                uint32_t typeMask) {
-    const Source source = mSource.withLine(parser->getLineNumber());
+bool ResourceParser::parseArray(xml::XmlPullParser* parser, ParsedResource* outResource) {
+    return parseArrayImpl(parser, outResource, android::ResTable_map::TYPE_ANY);
+}
+
+bool ResourceParser::parseIntegerArray(xml::XmlPullParser* parser, ParsedResource* outResource) {
+    return parseArrayImpl(parser, outResource, android::ResTable_map::TYPE_INTEGER);
+}
+
+bool ResourceParser::parseStringArray(xml::XmlPullParser* parser, ParsedResource* outResource) {
+    return parseArrayImpl(parser, outResource, android::ResTable_map::TYPE_STRING);
+}
+
+bool ResourceParser::parseArrayImpl(xml::XmlPullParser* parser, ParsedResource* outResource,
+                                    const uint32_t typeMask) {
+    outResource->name.type = ResourceType::kArray;
+
     std::unique_ptr<Array> array = util::make_unique<Array>();
 
     bool error = false;
@@ -1049,7 +1111,8 @@
 }
 
 bool ResourceParser::parsePlural(xml::XmlPullParser* parser, ParsedResource* outResource) {
-    const Source source = mSource.withLine(parser->getLineNumber());
+    outResource->name.type = ResourceType::kPlurals;
+
     std::unique_ptr<Plural> plural = util::make_unique<Plural>();
 
     bool error = false;
@@ -1123,12 +1186,13 @@
 }
 
 bool ResourceParser::parseDeclareStyleable(xml::XmlPullParser* parser, ParsedResource* outResource) {
-    const Source source = mSource.withLine(parser->getLineNumber());
-    std::unique_ptr<Styleable> styleable = util::make_unique<Styleable>();
+    outResource->name.type = ResourceType::kStyleable;
 
     // Declare-styleable is kPrivate by default, because it technically only exists in R.java.
     outResource->symbolState = SymbolState::kPublic;
 
+    std::unique_ptr<Styleable> styleable = util::make_unique<Styleable>();
+
     std::u16string comment;
     bool error = false;
     const size_t depth = parser->getDepth();
diff --git a/tools/aapt2/ResourceParser.h b/tools/aapt2/ResourceParser.h
index 04db577..9ad749e 100644
--- a/tools/aapt2/ResourceParser.h
+++ b/tools/aapt2/ResourceParser.h
@@ -34,11 +34,11 @@
 
 struct ResourceParserOptions {
     /**
-     * Optional product name by which to filter resources.
+     * Optional product names by which to filter resources.
      * This is like a preprocessor definition in that we strip out resources
      * that don't match before we compile them.
      */
-    Maybe<std::u16string> product;
+    std::vector<std::u16string> products;
 
     /**
      * Whether the default setting for this parser is to allow translation.
@@ -78,9 +78,11 @@
                                    const bool allowRawValue);
 
     bool parseResources(xml::XmlPullParser* parser);
+    bool parseResource(xml::XmlPullParser* parser, ParsedResource* outResource);
+
+    bool parseItem(xml::XmlPullParser* parser, ParsedResource* outResource, uint32_t format);
     bool parseString(xml::XmlPullParser* parser, ParsedResource* outResource);
-    bool parseColor(xml::XmlPullParser* parser, ParsedResource* outResource);
-    bool parsePrimitive(xml::XmlPullParser* parser, ParsedResource* outResource);
+
     bool parsePublic(xml::XmlPullParser* parser, ParsedResource* outResource);
     bool parsePublicGroup(xml::XmlPullParser* parser, ParsedResource* outResource);
     bool parseSymbolImpl(xml::XmlPullParser* parser, ParsedResource* outResource);
@@ -93,9 +95,15 @@
     bool parseStyle(xml::XmlPullParser* parser, ParsedResource* outResource);
     bool parseStyleItem(xml::XmlPullParser* parser, Style* style);
     bool parseDeclareStyleable(xml::XmlPullParser* parser, ParsedResource* outResource);
-    bool parseArray(xml::XmlPullParser* parser, ParsedResource* outResource, uint32_t typeMask);
+    bool parseArray(xml::XmlPullParser* parser, ParsedResource* outResource);
+    bool parseIntegerArray(xml::XmlPullParser* parser, ParsedResource* outResource);
+    bool parseStringArray(xml::XmlPullParser* parser, ParsedResource* outResource);
+    bool parseArrayImpl(xml::XmlPullParser* parser, ParsedResource* outResource, uint32_t typeMask);
     bool parsePlural(xml::XmlPullParser* parser, ParsedResource* outResource);
 
+    bool shouldStripResource(const ResourceNameRef& name,
+                             const Maybe<std::u16string>& product) const;
+
     IDiagnostics* mDiag;
     ResourceTable* mTable;
     Source mSource;
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp
index 84f67c6..8d10ba1 100644
--- a/tools/aapt2/ResourceParser_test.cpp
+++ b/tools/aapt2/ResourceParser_test.cpp
@@ -48,11 +48,11 @@
     }
 
     ::testing::AssertionResult testParse(const StringPiece& str,
-                                         Maybe<std::u16string> product = {}) {
+                                         std::initializer_list<std::u16string> products = {}) {
         std::stringstream input(kXmlPreamble);
         input << "<resources>\n" << str << "\n</resources>" << std::endl;
         ResourceParserOptions parserOptions;
-        parserOptions.product = product;
+        parserOptions.products = products;
         ResourceParser parser(mContext->getDiagnostics(), &mTable, Source{ "test" }, {},
                               parserOptions);
         xml::XmlPullParser xmlParser(input);
@@ -215,7 +215,7 @@
     ASSERT_TRUE(testParse(input));
 
     Attribute* flagAttr = test::getValue<Attribute>(&mTable, u"@attr/foo");
-    ASSERT_NE(flagAttr, nullptr);
+    ASSERT_NE(nullptr, flagAttr);
     EXPECT_EQ(flagAttr->typeMask, android::ResTable_map::TYPE_FLAGS);
     ASSERT_EQ(flagAttr->symbols.size(), 3u);
 
@@ -233,7 +233,7 @@
 
     std::unique_ptr<BinaryPrimitive> flagValue = ResourceUtils::tryParseFlagSymbol(flagAttr,
                                                                                    u"baz|bat");
-    ASSERT_NE(flagValue, nullptr);
+    ASSERT_NE(nullptr, flagValue);
     EXPECT_EQ(flagValue->value.data, 1u | 2u);
 }
 
@@ -255,7 +255,7 @@
     ASSERT_TRUE(testParse(input));
 
     Style* style = test::getValue<Style>(&mTable, u"@style/foo");
-    ASSERT_NE(style, nullptr);
+    ASSERT_NE(nullptr, style);
     AAPT_ASSERT_TRUE(style->parent);
     AAPT_ASSERT_TRUE(style->parent.value().name);
     EXPECT_EQ(test::parseNameOrDie(u"@style/fu"), style->parent.value().name.value());
@@ -276,7 +276,7 @@
     ASSERT_TRUE(testParse(input));
 
     Style* style = test::getValue<Style>(&mTable, u"@style/foo");
-    ASSERT_NE(style, nullptr);
+    ASSERT_NE(nullptr, style);
     AAPT_ASSERT_TRUE(style->parent);
     AAPT_ASSERT_TRUE(style->parent.value().name);
     EXPECT_EQ(test::parseNameOrDie(u"@com.app:style/Theme"), style->parent.value().name.value());
@@ -288,7 +288,7 @@
     ASSERT_TRUE(testParse(input));
 
     Style* style = test::getValue<Style>(&mTable, u"@style/foo");
-    ASSERT_NE(style, nullptr);
+    ASSERT_NE(nullptr, style);
     AAPT_ASSERT_TRUE(style->parent);
     AAPT_ASSERT_TRUE(style->parent.value().name);
     EXPECT_EQ(test::parseNameOrDie(u"@android:style/Theme"), style->parent.value().name.value());
@@ -302,7 +302,7 @@
     ASSERT_TRUE(testParse(input));
 
     Style* style = test::getValue<Style>(&mTable, u"@style/foo");
-    ASSERT_NE(style, nullptr);
+    ASSERT_NE(nullptr, style);
     ASSERT_EQ(1u, style->entries.size());
     EXPECT_EQ(test::parseNameOrDie(u"@android:attr/bar"), style->entries[0].key.name.value());
 }
@@ -312,7 +312,7 @@
     ASSERT_TRUE(testParse(input));
 
     Style* style = test::getValue<Style>(&mTable, u"@style/foo.bar");
-    ASSERT_NE(style, nullptr);
+    ASSERT_NE(nullptr, style);
     AAPT_ASSERT_TRUE(style->parent);
     AAPT_ASSERT_TRUE(style->parent.value().name);
     EXPECT_EQ(style->parent.value().name.value(), test::parseNameOrDie(u"@style/foo"));
@@ -324,11 +324,21 @@
     ASSERT_TRUE(testParse(input));
 
     Style* style = test::getValue<Style>(&mTable, u"@style/foo.bar");
-    ASSERT_NE(style, nullptr);
+    ASSERT_NE(nullptr, style);
     AAPT_EXPECT_FALSE(style->parent);
     EXPECT_FALSE(style->parentInferred);
 }
 
+TEST_F(ResourceParserTest, ParseStyleWithPrivateParentReference) {
+    std::string input = R"EOF(<style name="foo" parent="*android:style/bar" />)EOF";
+    ASSERT_TRUE(testParse(input));
+
+    Style* style = test::getValue<Style>(&mTable, u"@style/foo");
+    ASSERT_NE(nullptr, style);
+    AAPT_ASSERT_TRUE(style->parent);
+    EXPECT_TRUE(style->parent.value().privateReference);
+}
+
 TEST_F(ResourceParserTest, ParseAutoGeneratedIdReference) {
     std::string input = "<string name=\"foo\">@+id/bar</string>";
     ASSERT_TRUE(testParse(input));
@@ -504,11 +514,15 @@
 }
 
 TEST_F(ResourceParserTest, FilterProductsThatDontMatch) {
-    std::string input = "<string name=\"foo\" product=\"phone\">hi</string>\n"
-                        "<string name=\"foo\" product=\"no-sdcard\">ho</string>\n"
-                        "<string name=\"bar\" product=\"\">wee</string>\n"
-                        "<string name=\"baz\">woo</string>\n";
-    ASSERT_TRUE(testParse(input, std::u16string(u"no-sdcard")));
+    std::string input = R"EOF(
+        <string name="foo" product="phone">hi</string>
+        <string name="foo" product="no-sdcard">ho</string>
+        <string name="bar" product="">wee</string>
+        <string name="baz">woo</string>
+        <string name="bit" product="phablet">hoot</string>
+        <string name="bot" product="default">yes</string>
+    )EOF";
+    ASSERT_TRUE(testParse(input, { std::u16string(u"no-sdcard"), std::u16string(u"phablet") }));
 
     String* fooStr = test::getValue<String>(&mTable, u"@string/foo");
     ASSERT_NE(nullptr, fooStr);
@@ -516,11 +530,25 @@
 
     EXPECT_NE(nullptr, test::getValue<String>(&mTable, u"@string/bar"));
     EXPECT_NE(nullptr, test::getValue<String>(&mTable, u"@string/baz"));
+    EXPECT_NE(nullptr, test::getValue<String>(&mTable, u"@string/bit"));
+    EXPECT_NE(nullptr, test::getValue<String>(&mTable, u"@string/bot"));
+}
+
+TEST_F(ResourceParserTest, FilterProductsThatBothMatchInOrder) {
+    std::string input = R"EOF(
+        <string name="foo" product="phone">phone</string>
+        <string name="foo" product="default">default</string>
+    )EOF";
+    ASSERT_TRUE(testParse(input, { std::u16string(u"phone") }));
+
+    String* foo = test::getValue<String>(&mTable, u"@string/foo");
+    ASSERT_NE(nullptr, foo);
+    EXPECT_EQ(std::u16string(u"phone"), *foo->value);
 }
 
 TEST_F(ResourceParserTest, FailWhenProductFilterStripsOutAllVersionsOfResource) {
     std::string input = "<string name=\"foo\" product=\"tablet\">hello</string>\n";
-    ASSERT_FALSE(testParse(input, std::u16string(u"phone")));
+    ASSERT_FALSE(testParse(input, { std::u16string(u"phone") }));
 }
 
 TEST_F(ResourceParserTest, AutoIncrementIdsInPublicGroup) {
@@ -575,4 +603,14 @@
     EXPECT_EQ(SymbolState::kUndefined, entry->symbolStatus.state);
 }
 
+TEST_F(ResourceParserTest, ParseItemElementWithFormat) {
+    std::string input = R"EOF(<item name="foo" type="integer" format="float">0.3</item>)EOF";
+    ASSERT_TRUE(testParse(input));
+
+    BinaryPrimitive* val = test::getValue<BinaryPrimitive>(&mTable, u"@integer/foo");
+    ASSERT_NE(nullptr, val);
+
+    EXPECT_EQ(uint32_t(android::Res_value::TYPE_FLOAT), val->value.dataType);
+}
+
 } // namespace aapt
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp
index 36c3e70..1dc123e 100644
--- a/tools/aapt2/ResourceUtils.cpp
+++ b/tools/aapt2/ResourceUtils.cpp
@@ -176,10 +176,10 @@
 /*
  * Style parent's are a bit different. We accept the following formats:
  *
- * @[package:]style/<entry>
- * ?[package:]style/<entry>
- * <package>:[style/]<entry>
- * [package:style/]<entry>
+ * @[[*]package:]style/<entry>
+ * ?[[*]package:]style/<entry>
+ * <[*]package>:[style/]<entry>
+ * [[*]package:style/]<entry>
  */
 Maybe<Reference> parseStyleParentReference(const StringPiece16& str, std::string* outError) {
     if (str.empty()) {
@@ -195,10 +195,11 @@
     if (name.data()[0] == u'@' || name.data()[0] == u'?') {
         hasLeadingIdentifiers = true;
         name = name.substr(1, name.size() - 1);
-        if (name.data()[0] == u'*') {
-            privateRef = true;
-            name = name.substr(1, name.size() - 1);
-        }
+    }
+
+    if (name.data()[0] == u'*') {
+        privateRef = true;
+        name = name.substr(1, name.size() - 1);
     }
 
     ResourceNameRef ref;
diff --git a/tools/aapt2/ResourceUtils_test.cpp b/tools/aapt2/ResourceUtils_test.cpp
index 4bbfc32..88efa67 100644
--- a/tools/aapt2/ResourceUtils_test.cpp
+++ b/tools/aapt2/ResourceUtils_test.cpp
@@ -157,6 +157,11 @@
     ref = ResourceUtils::parseStyleParentReference(u"foo", &errStr);
     AAPT_ASSERT_TRUE(ref);
     EXPECT_EQ(ref.value().name.value(), kStyleFooName);
+
+    ref = ResourceUtils::parseStyleParentReference(u"*android:style/foo", &errStr);
+    AAPT_ASSERT_TRUE(ref);
+    EXPECT_EQ(ref.value().name.value(), kAndroidStyleFooName);
+    EXPECT_TRUE(ref.value().privateReference);
 }
 
 } // namespace aapt
diff --git a/tools/aapt2/ResourceValues.cpp b/tools/aapt2/ResourceValues.cpp
index 04c375f..b93e6d8 100644
--- a/tools/aapt2/ResourceValues.cpp
+++ b/tools/aapt2/ResourceValues.cpp
@@ -36,10 +36,6 @@
     visitor->visit(static_cast<Derived*>(this));
 }
 
-bool Value::isWeak() const {
-    return false;
-}
-
 RawString::RawString(const StringPool::Ref& ref) : value(ref) {
 }
 
@@ -101,10 +97,6 @@
     }
 }
 
-bool Id::isWeak() const {
-    return true;
-}
-
 bool Id::flatten(android::Res_value* out) const {
     out->dataType = android::Res_value::TYPE_INT_BOOLEAN;
     out->data = util::hostToDevice32(0);
@@ -119,7 +111,15 @@
     *out << "(id)";
 }
 
-String::String(const StringPool::Ref& ref) : value(ref) {
+String::String(const StringPool::Ref& ref) : value(ref), mTranslateable(true) {
+}
+
+void String::setTranslateable(bool val) {
+    mTranslateable = val;
+}
+
+bool String::isTranslateable() const {
+    return mTranslateable;
 }
 
 bool String::flatten(android::Res_value* outValue) const {
@@ -144,7 +144,15 @@
     *out << "(string) \"" << *value << "\"";
 }
 
-StyledString::StyledString(const StringPool::StyleRef& ref) : value(ref) {
+StyledString::StyledString(const StringPool::StyleRef& ref) : value(ref), mTranslateable(true) {
+}
+
+void StyledString::setTranslateable(bool val) {
+    mTranslateable = val;
+}
+
+bool StyledString::isTranslateable() const {
+    return mTranslateable;
 }
 
 bool StyledString::flatten(android::Res_value* outValue) const {
@@ -238,13 +246,10 @@
 }
 
 Attribute::Attribute(bool w, uint32_t t) :
-        weak(w), typeMask(t),
+        typeMask(t),
         minInt(std::numeric_limits<int32_t>::min()),
         maxInt(std::numeric_limits<int32_t>::max()) {
-}
-
-bool Attribute::isWeak() const {
-    return weak;
+    mWeak = w;
 }
 
 Attribute* Attribute::clone(StringPool* /*newPool*/) const {
@@ -359,7 +364,7 @@
             << "]";
     }
 
-    if (weak) {
+    if (isWeak()) {
         *out << " [weak]";
     }
 }
@@ -457,6 +462,9 @@
 void Style::print(std::ostream* out) const {
     *out << "(style) ";
     if (parent && parent.value().name) {
+        if (parent.value().privateReference) {
+            *out << "*";
+        }
         *out << parent.value().name.value();
     }
     *out << " ["
diff --git a/tools/aapt2/ResourceValues.h b/tools/aapt2/ResourceValues.h
index a038282..8e317db 100644
--- a/tools/aapt2/ResourceValues.h
+++ b/tools/aapt2/ResourceValues.h
@@ -43,9 +43,15 @@
 
     /**
      * Whether this value is weak and can be overridden without
-     * warning or error. Default for base class is false.
+     * warning or error. Default is false.
      */
-    virtual bool isWeak() const;
+    bool isWeak() const {
+        return mWeak;
+    }
+
+    void setWeak(bool val) {
+        mWeak = val;
+    }
 
     /**
      * Returns the source where this value was defined.
@@ -95,6 +101,7 @@
 protected:
     Source mSource;
     std::u16string mComment;
+    bool mWeak = false;
 };
 
 /**
@@ -159,7 +166,7 @@
  * An ID resource. Has no real value, just a place holder.
  */
 struct Id : public BaseItem<Id> {
-    bool isWeak() const override;
+    Id() { mWeak = true; }
     bool flatten(android::Res_value* out) const override;
     Id* clone(StringPool* newPool) const override;
     void print(std::ostream* out) const override;
@@ -185,9 +192,17 @@
 
     String(const StringPool::Ref& ref);
 
+    // Whether the string is marked as translateable. This does not persist when flattened.
+    // It is only used during compilation phase.
+    void setTranslateable(bool val);
+    bool isTranslateable() const;
+
     bool flatten(android::Res_value* outValue) const override;
     String* clone(StringPool* newPool) const override;
     void print(std::ostream* out) const override;
+
+private:
+    bool mTranslateable;
 };
 
 struct StyledString : public BaseItem<StyledString> {
@@ -195,9 +210,17 @@
 
     StyledString(const StringPool::StyleRef& ref);
 
+    // Whether the string is marked as translateable. This does not persist when flattened.
+    // It is only used during compilation phase.
+    void setTranslateable(bool val);
+    bool isTranslateable() const;
+
     bool flatten(android::Res_value* outValue) const override;
     StyledString* clone(StringPool* newPool) const override;
     void print(std::ostream* out) const override;
+
+private:
+    bool mTranslateable;
 };
 
 struct FileReference : public BaseItem<FileReference> {
@@ -232,7 +255,6 @@
         uint32_t value;
     };
 
-	bool weak;
     uint32_t typeMask;
     int32_t minInt;
     int32_t maxInt;
@@ -240,7 +262,6 @@
 
     Attribute(bool w, uint32_t t = 0u);
 
-    bool isWeak() const override;
     Attribute* clone(StringPool* newPool) const override;
     void printMask(std::ostream* out) const;
     void print(std::ostream* out) const override;
diff --git a/tools/aapt2/compile/Compile.cpp b/tools/aapt2/compile/Compile.cpp
index 90e35d5..b3b0f65 100644
--- a/tools/aapt2/compile/Compile.cpp
+++ b/tools/aapt2/compile/Compile.cpp
@@ -21,6 +21,7 @@
 #include "ResourceTable.h"
 #include "compile/IdAssigner.h"
 #include "compile/Png.h"
+#include "compile/PseudolocaleGenerator.h"
 #include "compile/XmlIdCollector.h"
 #include "flatten/Archive.h"
 #include "flatten/FileExportWriter.h"
@@ -104,7 +105,8 @@
 struct CompileOptions {
     std::string outputPath;
     Maybe<std::string> resDir;
-    Maybe<std::u16string> product;
+    std::vector<std::u16string> products;
+    bool pseudolocalize = false;
     bool verbose = false;
 };
 
@@ -189,7 +191,7 @@
         xml::XmlPullParser xmlParser(fin);
 
         ResourceParserOptions parserOptions;
-        parserOptions.product = options.product;
+        parserOptions.products = options.products;
 
         // If the filename includes donottranslate, then the default translatable is false.
         parserOptions.translatable = pathData.name.find(u"donottranslate") == std::string::npos;
@@ -203,6 +205,16 @@
         fin.close();
     }
 
+    if (options.pseudolocalize) {
+        // Generate pseudo-localized strings (en-XA and ar-XB).
+        // These are created as weak symbols, and are only generated from default configuration
+        // strings and plurals.
+        PseudolocaleGenerator pseudolocaleGenerator;
+        if (!pseudolocaleGenerator.consume(context, &table)) {
+            return false;
+        }
+    }
+
     // Ensure we have the compilation package at least.
     table.createPackage(context->getCompilationPackage());
 
@@ -418,18 +430,23 @@
 int compile(const std::vector<StringPiece>& args) {
     CompileOptions options;
 
-    Maybe<std::string> product;
+    Maybe<std::string> productList;
     Flags flags = Flags()
             .requiredFlag("-o", "Output path", &options.outputPath)
-            .optionalFlag("--product", "Product type to compile", &product)
+            .optionalFlag("--product", "Comma separated list of product types to compile",
+                          &productList)
             .optionalFlag("--dir", "Directory to scan for resources", &options.resDir)
+            .optionalSwitch("--pseudo-localize", "Generate resources for pseudo-locales "
+                            "(en-XA and ar-XB)", &options.pseudolocalize)
             .optionalSwitch("-v", "Enables verbose logging", &options.verbose);
     if (!flags.parse("aapt2 compile", args, &std::cerr)) {
         return 1;
     }
 
-    if (product) {
-        options.product = util::utf8ToUtf16(product.value());
+    if (productList) {
+        for (StringPiece part : util::tokenize<char>(productList.value(), ',')) {
+            options.products.push_back(util::utf8ToUtf16(part));
+        }
     }
 
     CompileContext context;
diff --git a/tools/aapt2/compile/PseudolocaleGenerator.cpp b/tools/aapt2/compile/PseudolocaleGenerator.cpp
new file mode 100644
index 0000000..2963d13
--- /dev/null
+++ b/tools/aapt2/compile/PseudolocaleGenerator.cpp
@@ -0,0 +1,261 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ResourceTable.h"
+#include "ResourceValues.h"
+#include "ValueVisitor.h"
+#include "compile/PseudolocaleGenerator.h"
+#include "compile/Pseudolocalizer.h"
+#include "util/Comparators.h"
+
+namespace aapt {
+
+std::unique_ptr<StyledString> pseudolocalizeStyledString(StyledString* string,
+                                                         Pseudolocalizer::Method method,
+                                                         StringPool* pool) {
+    Pseudolocalizer localizer(method);
+
+    const StringPiece16 originalText = *string->value->str;
+
+    StyleString localized;
+
+    // Copy the spans. We will update their offsets when we localize.
+    localized.spans.reserve(string->value->spans.size());
+    for (const StringPool::Span& span : string->value->spans) {
+        localized.spans.push_back(Span{ *span.name, span.firstChar, span.lastChar });
+    }
+
+    // The ranges are all represented with a single value. This is the start of one range and
+    // end of another.
+    struct Range {
+        size_t start;
+
+        // Once the new string is localized, these are the pointers to the spans to adjust.
+        // Since this struct represents the start of one range and end of another, we have
+        // the two pointers respectively.
+        uint32_t* updateStart;
+        uint32_t* updateEnd;
+    };
+
+    auto cmp = [](const Range& r, size_t index) -> bool {
+        return r.start < index;
+    };
+
+    // Construct the ranges. The ranges are represented like so: [0, 2, 5, 7]
+    // The ranges are the spaces in between. In this example, with a total string length of 9,
+    // the vector represents: (0,1], (2,4], (5,6], (7,9]
+    //
+    std::vector<Range> ranges;
+    ranges.push_back(Range{ 0 });
+    ranges.push_back(Range{ originalText.size() - 1 });
+    for (size_t i = 0; i < string->value->spans.size(); i++) {
+        const StringPool::Span& span = string->value->spans[i];
+
+        // Insert or update the Range marker for the start of this span.
+        auto iter = std::lower_bound(ranges.begin(), ranges.end(), span.firstChar, cmp);
+        if (iter != ranges.end() && iter->start == span.firstChar) {
+            iter->updateStart = &localized.spans[i].firstChar;
+        } else {
+            ranges.insert(iter,
+                          Range{ span.firstChar, &localized.spans[i].firstChar, nullptr });
+        }
+
+        // Insert or update the Range marker for the end of this span.
+        iter = std::lower_bound(ranges.begin(), ranges.end(), span.lastChar, cmp);
+        if (iter != ranges.end() && iter->start == span.lastChar) {
+            iter->updateEnd = &localized.spans[i].lastChar;
+        } else {
+            ranges.insert(iter,
+                          Range{ span.lastChar, nullptr, &localized.spans[i].lastChar });
+        }
+    }
+
+    localized.str += localizer.start();
+
+    // Iterate over the ranges and localize each section.
+    for (size_t i = 0; i < ranges.size(); i++) {
+        const size_t start = ranges[i].start;
+        size_t len = originalText.size() - start;
+        if (i + 1 < ranges.size()) {
+            len = ranges[i + 1].start - start;
+        }
+
+        if (ranges[i].updateStart) {
+            *ranges[i].updateStart = localized.str.size();
+        }
+
+        if (ranges[i].updateEnd) {
+            *ranges[i].updateEnd = localized.str.size();
+        }
+
+        localized.str += localizer.text(originalText.substr(start, len));
+    }
+
+    localized.str += localizer.end();
+
+    std::unique_ptr<StyledString> localizedString = util::make_unique<StyledString>(
+            pool->makeRef(localized));
+    localizedString->setSource(string->getSource());
+    return localizedString;
+}
+
+namespace {
+
+struct Visitor : public RawValueVisitor {
+    StringPool* mPool;
+    Pseudolocalizer::Method mMethod;
+    Pseudolocalizer mLocalizer;
+
+    // Either value or item will be populated upon visiting the value.
+    std::unique_ptr<Value> mValue;
+    std::unique_ptr<Item> mItem;
+
+    Visitor(StringPool* pool, Pseudolocalizer::Method method) :
+            mPool(pool), mMethod(method), mLocalizer(method) {
+    }
+
+    void visit(Array* array) override {
+        std::unique_ptr<Array> localized = util::make_unique<Array>();
+        localized->items.resize(array->items.size());
+        for (size_t i = 0; i < array->items.size(); i++) {
+            Visitor subVisitor(mPool, mMethod);
+            array->items[i]->accept(&subVisitor);
+            if (subVisitor.mItem) {
+                localized->items[i] = std::move(subVisitor.mItem);
+            } else {
+                localized->items[i] = std::unique_ptr<Item>(array->items[i]->clone(mPool));
+            }
+        }
+        localized->setSource(array->getSource());
+        localized->setWeak(true);
+        mValue = std::move(localized);
+    }
+
+    void visit(Plural* plural) override {
+        std::unique_ptr<Plural> localized = util::make_unique<Plural>();
+        for (size_t i = 0; i < plural->values.size(); i++) {
+            Visitor subVisitor(mPool, mMethod);
+            if (plural->values[i]) {
+                plural->values[i]->accept(&subVisitor);
+                if (subVisitor.mValue) {
+                    localized->values[i] = std::move(subVisitor.mItem);
+                } else {
+                    localized->values[i] = std::unique_ptr<Item>(plural->values[i]->clone(mPool));
+                }
+            }
+        }
+        localized->setSource(plural->getSource());
+        localized->setWeak(true);
+        mValue = std::move(localized);
+    }
+
+    void visit(String* string) override {
+        if (!string->isTranslateable()) {
+            return;
+        }
+
+        std::u16string result = mLocalizer.start() + mLocalizer.text(*string->value) +
+                mLocalizer.end();
+        std::unique_ptr<String> localized = util::make_unique<String>(mPool->makeRef(result));
+        localized->setSource(string->getSource());
+        localized->setWeak(true);
+        mItem = std::move(localized);
+    }
+
+    void visit(StyledString* string) override {
+        if (!string->isTranslateable()) {
+            return;
+        }
+
+        mItem = pseudolocalizeStyledString(string, mMethod, mPool);
+        mItem->setWeak(true);
+    }
+};
+
+ConfigDescription modifyConfigForPseudoLocale(const ConfigDescription& base,
+                                              Pseudolocalizer::Method m) {
+    ConfigDescription modified = base;
+    switch (m) {
+    case Pseudolocalizer::Method::kAccent:
+        modified.language[0] = 'e';
+        modified.language[1] = 'n';
+        modified.country[0] = 'X';
+        modified.country[1] = 'A';
+        break;
+
+    case Pseudolocalizer::Method::kBidi:
+        modified.language[0] = 'a';
+        modified.language[1] = 'r';
+        modified.country[0] = 'X';
+        modified.country[1] = 'B';
+        break;
+    default:
+        break;
+    }
+    return modified;
+}
+
+void pseudolocalizeIfNeeded(std::vector<ResourceConfigValue>* configValues,
+                            Pseudolocalizer::Method method, StringPool* pool, Value* value) {
+    Visitor visitor(pool, method);
+    value->accept(&visitor);
+
+    std::unique_ptr<Value> localizedValue;
+    if (visitor.mValue) {
+        localizedValue = std::move(visitor.mValue);
+    } else if (visitor.mItem) {
+        localizedValue = std::move(visitor.mItem);
+    }
+
+    if (localizedValue) {
+        ConfigDescription pseudolocalizedConfig = modifyConfigForPseudoLocale(ConfigDescription{},
+                                                                              method);
+        auto iter = std::lower_bound(configValues->begin(), configValues->end(),
+                                     pseudolocalizedConfig, cmp::lessThanConfig);
+        if (iter == configValues->end() || iter->config != pseudolocalizedConfig) {
+            // The pseudolocalized config doesn't exist, add it.
+            configValues->insert(iter, ResourceConfigValue{ pseudolocalizedConfig,
+                                                            std::move(localizedValue) });
+        }
+    }
+}
+
+} // namespace
+
+bool PseudolocaleGenerator::consume(IAaptContext* context, ResourceTable* table) {
+    for (auto& package : table->packages) {
+        for (auto& type : package->types) {
+            for (auto& entry : type->entries) {
+                auto iter = std::lower_bound(entry->values.begin(), entry->values.end(),
+                                             ConfigDescription{}, cmp::lessThanConfig);
+                if (iter != entry->values.end() && iter->config == ConfigDescription{}) {
+                    // Only pseudolocalize the default configuration.
+
+                    // The iterator will be invalidated, so grab a pointer to the value.
+                    Value* originalValue = iter->value.get();
+
+                    pseudolocalizeIfNeeded(&entry->values, Pseudolocalizer::Method::kAccent,
+                                           &table->stringPool, originalValue);
+                    pseudolocalizeIfNeeded(&entry->values, Pseudolocalizer::Method::kBidi,
+                                           &table->stringPool, originalValue);
+                }
+            }
+        }
+    }
+    return true;
+}
+
+} // namespace aapt
diff --git a/tools/aapt2/compile/PseudolocaleGenerator.h b/tools/aapt2/compile/PseudolocaleGenerator.h
new file mode 100644
index 0000000..4fbc516
--- /dev/null
+++ b/tools/aapt2/compile/PseudolocaleGenerator.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AAPT_COMPILE_PSEUDOLOCALEGENERATOR_H
+#define AAPT_COMPILE_PSEUDOLOCALEGENERATOR_H
+
+#include "StringPool.h"
+#include "compile/Pseudolocalizer.h"
+#include "process/IResourceTableConsumer.h"
+
+namespace aapt {
+
+std::unique_ptr<StyledString> pseudolocalizeStyledString(StyledString* string,
+                                                         Pseudolocalizer::Method method,
+                                                         StringPool* pool);
+
+struct PseudolocaleGenerator : public IResourceTableConsumer {
+    bool consume(IAaptContext* context, ResourceTable* table) override;
+};
+
+} // namespace aapt
+
+#endif /* AAPT_COMPILE_PSEUDOLOCALEGENERATOR_H */
diff --git a/tools/aapt2/compile/PseudolocaleGenerator_test.cpp b/tools/aapt2/compile/PseudolocaleGenerator_test.cpp
new file mode 100644
index 0000000..4cb6ea2
--- /dev/null
+++ b/tools/aapt2/compile/PseudolocaleGenerator_test.cpp
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "compile/PseudolocaleGenerator.h"
+#include "test/Builders.h"
+#include "test/Common.h"
+#include "test/Context.h"
+#include "util/Util.h"
+
+#include <androidfw/ResourceTypes.h>
+#include <gtest/gtest.h>
+
+namespace aapt {
+
+TEST(PseudolocaleGeneratorTest, PseudolocalizeStyledString) {
+    StringPool pool;
+    StyleString originalStyle;
+    originalStyle.str = u"Hello world!";
+    originalStyle.spans = { Span{ u"b", 2, 3 }, Span{ u"b", 6, 7 }, Span{ u"i", 1, 10 } };
+
+    std::unique_ptr<StyledString> newString = pseudolocalizeStyledString(
+            util::make_unique<StyledString>(pool.makeRef(originalStyle)).get(),
+            Pseudolocalizer::Method::kNone, &pool);
+
+    EXPECT_EQ(originalStyle.str, *newString->value->str);
+    ASSERT_EQ(originalStyle.spans.size(), newString->value->spans.size());
+
+    EXPECT_EQ(2u, newString->value->spans[0].firstChar);
+    EXPECT_EQ(3u, newString->value->spans[0].lastChar);
+    EXPECT_EQ(std::u16string(u"b"), *newString->value->spans[0].name);
+
+    EXPECT_EQ(6u, newString->value->spans[1].firstChar);
+    EXPECT_EQ(7u, newString->value->spans[1].lastChar);
+    EXPECT_EQ(std::u16string(u"b"), *newString->value->spans[1].name);
+
+    EXPECT_EQ(1u, newString->value->spans[2].firstChar);
+    EXPECT_EQ(10u, newString->value->spans[2].lastChar);
+    EXPECT_EQ(std::u16string(u"i"), *newString->value->spans[2].name);
+
+    originalStyle.spans.push_back(Span{ u"em", 0, 11u });
+
+    newString = pseudolocalizeStyledString(
+            util::make_unique<StyledString>(pool.makeRef(originalStyle)).get(),
+            Pseudolocalizer::Method::kAccent, &pool);
+
+    EXPECT_EQ(std::u16string(u"[Ĥéļļö ŵöŕļð¡ one two]"), *newString->value->str);
+    ASSERT_EQ(originalStyle.spans.size(), newString->value->spans.size());
+
+    EXPECT_EQ(3u, newString->value->spans[0].firstChar);
+    EXPECT_EQ(4u, newString->value->spans[0].lastChar);
+
+    EXPECT_EQ(7u, newString->value->spans[1].firstChar);
+    EXPECT_EQ(8u, newString->value->spans[1].lastChar);
+
+    EXPECT_EQ(2u, newString->value->spans[2].firstChar);
+    EXPECT_EQ(11u, newString->value->spans[2].lastChar);
+
+    EXPECT_EQ(1u, newString->value->spans[3].firstChar);
+    EXPECT_EQ(12u, newString->value->spans[3].lastChar);
+}
+
+TEST(PseudolocaleGeneratorTest, PseudolocalizeOnlyDefaultConfigs) {
+    std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
+            .addString(u"@android:string/one", u"one")
+            .addString(u"@android:string/two", ResourceId{}, test::parseConfigOrDie("en"), u"two")
+            .addString(u"@android:string/three", u"three")
+            .addString(u"@android:string/three", ResourceId{}, test::parseConfigOrDie("en-rXA"),
+                       u"three")
+            .addString(u"@android:string/four", u"four")
+            .build();
+
+    String* val = test::getValue<String>(table.get(), u"@android:string/four");
+    val->setTranslateable(false);
+
+    std::unique_ptr<IAaptContext> context = test::ContextBuilder().build();
+    PseudolocaleGenerator generator;
+    ASSERT_TRUE(generator.consume(context.get(), table.get()));
+
+    // Normal pseudolocalization should take place.
+    ASSERT_NE(nullptr, test::getValueForConfig<String>(table.get(), u"@android:string/one",
+                                                       test::parseConfigOrDie("en-rXA")));
+    ASSERT_NE(nullptr, test::getValueForConfig<String>(table.get(), u"@android:string/one",
+                                                       test::parseConfigOrDie("ar-rXB")));
+
+    // No default config for android:string/two, so no pseudlocales should exist.
+    ASSERT_EQ(nullptr, test::getValueForConfig<String>(table.get(), u"@android:string/two",
+                                                       test::parseConfigOrDie("en-rXA")));
+    ASSERT_EQ(nullptr, test::getValueForConfig<String>(table.get(), u"@android:string/two",
+                                                       test::parseConfigOrDie("ar-rXB")));
+
+
+    // Check that we didn't override manual pseudolocalization.
+    val = test::getValueForConfig<String>(table.get(), u"@android:string/three",
+                                          test::parseConfigOrDie("en-rXA"));
+    ASSERT_NE(nullptr, val);
+    EXPECT_EQ(std::u16string(u"three"), *val->value);
+
+    ASSERT_NE(nullptr, test::getValueForConfig<String>(table.get(), u"@android:string/three",
+                                                       test::parseConfigOrDie("ar-rXB")));
+
+    // Check that four's translateable marker was honored.
+    ASSERT_EQ(nullptr, test::getValueForConfig<String>(table.get(), u"@android:string/four",
+                                                       test::parseConfigOrDie("en-rXA")));
+    ASSERT_EQ(nullptr, test::getValueForConfig<String>(table.get(), u"@android:string/four",
+                                                       test::parseConfigOrDie("ar-rXB")));
+
+}
+
+} // namespace aapt
+
diff --git a/tools/aapt2/compile/Pseudolocalizer.cpp b/tools/aapt2/compile/Pseudolocalizer.cpp
new file mode 100644
index 0000000..eae52d7
--- /dev/null
+++ b/tools/aapt2/compile/Pseudolocalizer.cpp
@@ -0,0 +1,394 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "compile/Pseudolocalizer.h"
+#include "util/Util.h"
+
+namespace aapt {
+
+// String basis to generate expansion
+static const std::u16string k_expansion_string = u"one two three "
+        "four five six seven eight nine ten eleven twelve thirteen "
+        "fourteen fiveteen sixteen seventeen nineteen twenty";
+
+// Special unicode characters to override directionality of the words
+static const std::u16string k_rlm = u"\u200f";
+static const std::u16string k_rlo = u"\u202e";
+static const std::u16string k_pdf = u"\u202c";
+
+// Placeholder marks
+static const std::u16string k_placeholder_open = u"\u00bb";
+static const std::u16string k_placeholder_close = u"\u00ab";
+
+static const char16_t k_arg_start = u'{';
+static const char16_t k_arg_end = u'}';
+
+class PseudoMethodNone : public PseudoMethodImpl {
+public:
+    std::u16string text(const StringPiece16& text) override { return text.toString(); }
+    std::u16string placeholder(const StringPiece16& text) override { return text.toString(); }
+};
+
+class PseudoMethodBidi : public PseudoMethodImpl {
+public:
+    std::u16string text(const StringPiece16& text) override;
+    std::u16string placeholder(const StringPiece16& text) override;
+};
+
+class PseudoMethodAccent : public PseudoMethodImpl {
+public:
+    PseudoMethodAccent() : mDepth(0), mWordCount(0), mLength(0) {}
+    std::u16string start() override;
+    std::u16string end() override;
+    std::u16string text(const StringPiece16& text) override;
+    std::u16string placeholder(const StringPiece16& text) override;
+private:
+    size_t mDepth;
+    size_t mWordCount;
+    size_t mLength;
+};
+
+Pseudolocalizer::Pseudolocalizer(Method method) : mLastDepth(0) {
+    setMethod(method);
+}
+
+void Pseudolocalizer::setMethod(Method method) {
+    switch (method) {
+    case Method::kNone:
+        mImpl = util::make_unique<PseudoMethodNone>();
+        break;
+    case Method::kAccent:
+        mImpl = util::make_unique<PseudoMethodAccent>();
+        break;
+    case Method::kBidi:
+        mImpl = util::make_unique<PseudoMethodBidi>();
+        break;
+    }
+}
+
+std::u16string Pseudolocalizer::text(const StringPiece16& text) {
+    std::u16string out;
+    size_t depth = mLastDepth;
+    size_t lastpos, pos;
+    const size_t length = text.size();
+    const char16_t* str = text.data();
+    bool escaped = false;
+    for (lastpos = pos = 0; pos < length; pos++) {
+        char16_t c = str[pos];
+        if (escaped) {
+            escaped = false;
+            continue;
+        }
+        if (c == '\'') {
+            escaped = true;
+            continue;
+        }
+
+        if (c == k_arg_start) {
+            depth++;
+        } else if (c == k_arg_end && depth) {
+            depth--;
+        }
+
+        if (mLastDepth != depth || pos == length - 1) {
+            bool pseudo = ((mLastDepth % 2) == 0);
+            size_t nextpos = pos;
+            if (!pseudo || depth == mLastDepth) {
+                nextpos++;
+            }
+            size_t size = nextpos - lastpos;
+            if (size) {
+                std::u16string chunk = text.substr(lastpos, size).toString();
+                if (pseudo) {
+                    chunk = mImpl->text(chunk);
+                } else if (str[lastpos] == k_arg_start && str[nextpos - 1] == k_arg_end) {
+                    chunk = mImpl->placeholder(chunk);
+                }
+                out.append(chunk);
+            }
+            if (pseudo && depth < mLastDepth) { // End of message
+                out.append(mImpl->end());
+            } else if (!pseudo && depth > mLastDepth) { // Start of message
+                out.append(mImpl->start());
+            }
+            lastpos = nextpos;
+            mLastDepth = depth;
+        }
+    }
+    return out;
+}
+
+static const char16_t* pseudolocalizeChar(const char16_t c) {
+    switch (c) {
+        case 'a':   return u"\u00e5";
+        case 'b':   return u"\u0253";
+        case 'c':   return u"\u00e7";
+        case 'd':   return u"\u00f0";
+        case 'e':   return u"\u00e9";
+        case 'f':   return u"\u0192";
+        case 'g':   return u"\u011d";
+        case 'h':   return u"\u0125";
+        case 'i':   return u"\u00ee";
+        case 'j':   return u"\u0135";
+        case 'k':   return u"\u0137";
+        case 'l':   return u"\u013c";
+        case 'm':   return u"\u1e3f";
+        case 'n':   return u"\u00f1";
+        case 'o':   return u"\u00f6";
+        case 'p':   return u"\u00fe";
+        case 'q':   return u"\u0051";
+        case 'r':   return u"\u0155";
+        case 's':   return u"\u0161";
+        case 't':   return u"\u0163";
+        case 'u':   return u"\u00fb";
+        case 'v':   return u"\u0056";
+        case 'w':   return u"\u0175";
+        case 'x':   return u"\u0445";
+        case 'y':   return u"\u00fd";
+        case 'z':   return u"\u017e";
+        case 'A':   return u"\u00c5";
+        case 'B':   return u"\u03b2";
+        case 'C':   return u"\u00c7";
+        case 'D':   return u"\u00d0";
+        case 'E':   return u"\u00c9";
+        case 'G':   return u"\u011c";
+        case 'H':   return u"\u0124";
+        case 'I':   return u"\u00ce";
+        case 'J':   return u"\u0134";
+        case 'K':   return u"\u0136";
+        case 'L':   return u"\u013b";
+        case 'M':   return u"\u1e3e";
+        case 'N':   return u"\u00d1";
+        case 'O':   return u"\u00d6";
+        case 'P':   return u"\u00de";
+        case 'Q':   return u"\u0071";
+        case 'R':   return u"\u0154";
+        case 'S':   return u"\u0160";
+        case 'T':   return u"\u0162";
+        case 'U':   return u"\u00db";
+        case 'V':   return u"\u03bd";
+        case 'W':   return u"\u0174";
+        case 'X':   return u"\u00d7";
+        case 'Y':   return u"\u00dd";
+        case 'Z':   return u"\u017d";
+        case '!':   return u"\u00a1";
+        case '?':   return u"\u00bf";
+        case '$':   return u"\u20ac";
+        default:    return NULL;
+    }
+}
+
+static bool isPossibleNormalPlaceholderEnd(const char16_t c) {
+    switch (c) {
+        case 's': return true;
+        case 'S': return true;
+        case 'c': return true;
+        case 'C': return true;
+        case 'd': return true;
+        case 'o': return true;
+        case 'x': return true;
+        case 'X': return true;
+        case 'f': return true;
+        case 'e': return true;
+        case 'E': return true;
+        case 'g': return true;
+        case 'G': return true;
+        case 'a': return true;
+        case 'A': return true;
+        case 'b': return true;
+        case 'B': return true;
+        case 'h': return true;
+        case 'H': return true;
+        case '%': return true;
+        case 'n': return true;
+        default:  return false;
+    }
+}
+
+static std::u16string pseudoGenerateExpansion(const unsigned int length) {
+    std::u16string result = k_expansion_string;
+    const char16_t* s = result.data();
+    if (result.size() < length) {
+        result += u" ";
+        result += pseudoGenerateExpansion(length - result.size());
+    } else {
+        int ext = 0;
+        // Should contain only whole words, so looking for a space
+        for (unsigned int i = length + 1; i < result.size(); ++i) {
+            ++ext;
+            if (s[i] == ' ') {
+                break;
+            }
+        }
+        result = result.substr(0, length + ext);
+    }
+    return result;
+}
+
+std::u16string PseudoMethodAccent::start() {
+    std::u16string result;
+    if (mDepth == 0) {
+        result = u"[";
+    }
+    mWordCount = mLength = 0;
+    mDepth++;
+    return result;
+}
+
+std::u16string PseudoMethodAccent::end() {
+    std::u16string result;
+    if (mLength) {
+        result += u" ";
+        result += pseudoGenerateExpansion(mWordCount > 3 ? mLength : mLength / 2);
+    }
+    mWordCount = mLength = 0;
+    mDepth--;
+    if (mDepth == 0) {
+        result += u"]";
+    }
+    return result;
+}
+
+/**
+ * Converts characters so they look like they've been localized.
+ *
+ * Note: This leaves placeholder syntax untouched.
+ */
+std::u16string PseudoMethodAccent::text(const StringPiece16& source)
+{
+    const char16_t* s = source.data();
+    std::u16string result;
+    const size_t I = source.size();
+    bool lastspace = true;
+    for (size_t i = 0; i < I; i++) {
+        char16_t c = s[i];
+        if (c == '%') {
+            // Placeholder syntax, no need to pseudolocalize
+            std::u16string chunk;
+            bool end = false;
+            chunk.append(&c, 1);
+            while (!end && i < I) {
+                ++i;
+                c = s[i];
+                chunk.append(&c, 1);
+                if (isPossibleNormalPlaceholderEnd(c)) {
+                    end = true;
+                } else if (c == 't') {
+                    ++i;
+                    c = s[i];
+                    chunk.append(&c, 1);
+                    end = true;
+                }
+            }
+            // Treat chunk as a placeholder unless it ends with %.
+            result += ((c == '%') ? chunk : placeholder(chunk));
+        } else if (c == '<' || c == '&') {
+            // html syntax, no need to pseudolocalize
+            bool tag_closed = false;
+            while (!tag_closed && i < I) {
+                if (c == '&') {
+                    std::u16string escapeText;
+                    escapeText.append(&c, 1);
+                    bool end = false;
+                    size_t htmlCodePos = i;
+                    while (!end && htmlCodePos < I) {
+                        ++htmlCodePos;
+                        c = s[htmlCodePos];
+                        escapeText.append(&c, 1);
+                        // Valid html code
+                        if (c == ';') {
+                            end = true;
+                            i = htmlCodePos;
+                        }
+                        // Wrong html code
+                        else if (!((c == '#' ||
+                                 (c >= 'a' && c <= 'z') ||
+                                 (c >= 'A' && c <= 'Z') ||
+                                 (c >= '0' && c <= '9')))) {
+                            end = true;
+                        }
+                    }
+                    result += escapeText;
+                    if (escapeText != u"&lt;") {
+                        tag_closed = true;
+                    }
+                    continue;
+                }
+                if (c == '>') {
+                    tag_closed = true;
+                    result.append(&c, 1);
+                    continue;
+                }
+                result.append(&c, 1);
+                i++;
+                c = s[i];
+            }
+        } else {
+            // This is a pure text that should be pseudolocalized
+            const char16_t* p = pseudolocalizeChar(c);
+            if (p != nullptr) {
+                result += p;
+            } else {
+                bool space = util::isspace16(c);
+                if (lastspace && !space) {
+                    mWordCount++;
+                }
+                lastspace = space;
+                result.append(&c, 1);
+            }
+            // Count only pseudolocalizable chars and delimiters
+            mLength++;
+        }
+    }
+    return result;
+}
+
+std::u16string PseudoMethodAccent::placeholder(const StringPiece16& source) {
+    // Surround a placeholder with brackets
+    return k_placeholder_open + source.toString() + k_placeholder_close;
+}
+
+std::u16string PseudoMethodBidi::text(const StringPiece16& source) {
+    const char16_t* s = source.data();
+    std::u16string result;
+    bool lastspace = true;
+    bool space = true;
+    for (size_t i = 0; i < source.size(); i++) {
+        char16_t c = s[i];
+        space = util::isspace16(c);
+        if (lastspace && !space) {
+            // Word start
+            result += k_rlm + k_rlo;
+        } else if (!lastspace && space) {
+            // Word end
+            result += k_pdf + k_rlm;
+        }
+        lastspace = space;
+        result.append(&c, 1);
+    }
+    if (!lastspace) {
+        // End of last word
+        result += k_pdf + k_rlm;
+    }
+    return result;
+}
+
+std::u16string PseudoMethodBidi::placeholder(const StringPiece16& source) {
+    // Surround a placeholder with directionality change sequence
+    return k_rlm + k_rlo + source.toString() + k_pdf + k_rlm;
+}
+
+} // namespace aapt
diff --git a/tools/aapt2/compile/Pseudolocalizer.h b/tools/aapt2/compile/Pseudolocalizer.h
new file mode 100644
index 0000000..8818c17
--- /dev/null
+++ b/tools/aapt2/compile/Pseudolocalizer.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AAPT_COMPILE_PSEUDOLOCALIZE_H
+#define AAPT_COMPILE_PSEUDOLOCALIZE_H
+
+#include "ResourceValues.h"
+#include "StringPool.h"
+#include "util/StringPiece.h"
+
+#include <android-base/macros.h>
+#include <memory>
+
+namespace aapt {
+
+class PseudoMethodImpl {
+public:
+    virtual ~PseudoMethodImpl() {}
+    virtual std::u16string start() { return {}; }
+    virtual std::u16string end() { return {}; }
+    virtual std::u16string text(const StringPiece16& text) = 0;
+    virtual std::u16string placeholder(const StringPiece16& text) = 0;
+};
+
+class Pseudolocalizer {
+public:
+    enum class Method {
+        kNone,
+        kAccent,
+        kBidi,
+    };
+
+    Pseudolocalizer(Method method);
+    void setMethod(Method method);
+    std::u16string start() { return mImpl->start(); }
+    std::u16string end() { return mImpl->end(); }
+    std::u16string text(const StringPiece16& text);
+private:
+    std::unique_ptr<PseudoMethodImpl> mImpl;
+    size_t mLastDepth;
+};
+
+} // namespace aapt
+
+#endif /* AAPT_COMPILE_PSEUDOLOCALIZE_H */
diff --git a/tools/aapt2/compile/Pseudolocalizer_test.cpp b/tools/aapt2/compile/Pseudolocalizer_test.cpp
new file mode 100644
index 0000000..b0bc2c1
--- /dev/null
+++ b/tools/aapt2/compile/Pseudolocalizer_test.cpp
@@ -0,0 +1,227 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "compile/Pseudolocalizer.h"
+#include "util/Util.h"
+
+#include <androidfw/ResourceTypes.h>
+#include <gtest/gtest.h>
+
+namespace aapt {
+
+// In this context, 'Axis' represents a particular field in the configuration,
+// such as language or density.
+
+static ::testing::AssertionResult simpleHelper(const char* input, const char* expected,
+                                               Pseudolocalizer::Method method) {
+    Pseudolocalizer pseudo(method);
+    std::string result = util::utf16ToUtf8(
+            pseudo.start() + pseudo.text(util::utf8ToUtf16(input)) + pseudo.end());
+    if (StringPiece(expected) != result) {
+        return ::testing::AssertionFailure() << expected << " != " << result;
+    }
+    return ::testing::AssertionSuccess();
+}
+
+static ::testing::AssertionResult compoundHelper(const char* in1, const char* in2, const char *in3,
+                                                 const char* expected,
+                                                 Pseudolocalizer::Method method) {
+    Pseudolocalizer pseudo(method);
+    std::string result = util::utf16ToUtf8(pseudo.start() +
+                                           pseudo.text(util::utf8ToUtf16(in1)) +
+                                           pseudo.text(util::utf8ToUtf16(in2)) +
+                                           pseudo.text(util::utf8ToUtf16(in3)) +
+                                           pseudo.end());
+    if (StringPiece(expected) != result) {
+        return ::testing::AssertionFailure() << expected << " != " << result;
+    }
+    return ::testing::AssertionSuccess();
+}
+
+TEST(PseudolocalizerTest, NoPseudolocalization) {
+    EXPECT_TRUE(simpleHelper("", "", Pseudolocalizer::Method::kNone));
+    EXPECT_TRUE(simpleHelper("Hello, world", "Hello, world", Pseudolocalizer::Method::kNone));
+
+    EXPECT_TRUE(compoundHelper("Hello,", " world", "",
+                               "Hello, world", Pseudolocalizer::Method::kNone));
+}
+
+TEST(PseudolocalizerTest, PlaintextAccent) {
+    EXPECT_TRUE(simpleHelper("", "[]", Pseudolocalizer::Method::kAccent));
+    EXPECT_TRUE(simpleHelper("Hello, world",
+                             "[Ĥéļļö, ŵöŕļð one two]", Pseudolocalizer::Method::kAccent));
+
+    EXPECT_TRUE(simpleHelper("Hello, %1d",
+                             "[Ĥéļļö, »%1d« one two]", Pseudolocalizer::Method::kAccent));
+
+    EXPECT_TRUE(simpleHelper("Battery %1d%%",
+                             "[βåţţéŕý »%1d«%% one two]", Pseudolocalizer::Method::kAccent));
+
+    EXPECT_TRUE(compoundHelper("", "", "", "[]", Pseudolocalizer::Method::kAccent));
+    EXPECT_TRUE(compoundHelper("Hello,", " world", "",
+                               "[Ĥéļļö, ŵöŕļð one two]", Pseudolocalizer::Method::kAccent));
+}
+
+TEST(PseudolocalizerTest, PlaintextBidi) {
+    EXPECT_TRUE(simpleHelper("", "", Pseudolocalizer::Method::kBidi));
+    EXPECT_TRUE(simpleHelper("word",
+                             "\xe2\x80\x8f\xE2\x80\xaeword\xE2\x80\xac\xe2\x80\x8f",
+                             Pseudolocalizer::Method::kBidi));
+    EXPECT_TRUE(simpleHelper("  word  ",
+                             "  \xe2\x80\x8f\xE2\x80\xaeword\xE2\x80\xac\xe2\x80\x8f  ",
+                             Pseudolocalizer::Method::kBidi));
+    EXPECT_TRUE(simpleHelper("  word  ",
+                             "  \xe2\x80\x8f\xE2\x80\xaeword\xE2\x80\xac\xe2\x80\x8f  ",
+                             Pseudolocalizer::Method::kBidi));
+    EXPECT_TRUE(simpleHelper("hello\n  world\n",
+                             "\xe2\x80\x8f\xE2\x80\xaehello\xE2\x80\xac\xe2\x80\x8f\n" \
+                                     "  \xe2\x80\x8f\xE2\x80\xaeworld\xE2\x80\xac\xe2\x80\x8f\n",
+                             Pseudolocalizer::Method::kBidi));
+    EXPECT_TRUE(compoundHelper("hello", "\n ", " world\n",
+                               "\xe2\x80\x8f\xE2\x80\xaehello\xE2\x80\xac\xe2\x80\x8f\n" \
+                                       "  \xe2\x80\x8f\xE2\x80\xaeworld\xE2\x80\xac\xe2\x80\x8f\n",
+                               Pseudolocalizer::Method::kBidi));
+}
+
+TEST(PseudolocalizerTest, SimpleICU) {
+    // Single-fragment messages
+    EXPECT_TRUE(simpleHelper("{placeholder}", "[»{placeholder}«]",
+                             Pseudolocalizer::Method::kAccent));
+    EXPECT_TRUE(simpleHelper("{USER} is offline",
+                             "[»{USER}« îš öƒƒļîñé one two]", Pseudolocalizer::Method::kAccent));
+    EXPECT_TRUE(simpleHelper("Copy from {path1} to {path2}",
+                             "[Çöþý ƒŕöḿ »{path1}« ţö »{path2}« one two three]",
+                             Pseudolocalizer::Method::kAccent));
+    EXPECT_TRUE(simpleHelper("Today is {1,date} {1,time}",
+                             "[Ţöðåý îš »{1,date}« »{1,time}« one two]",
+                             Pseudolocalizer::Method::kAccent));
+
+    // Multi-fragment messages
+    EXPECT_TRUE(compoundHelper("{USER}", " ", "is offline",
+                               "[»{USER}« îš öƒƒļîñé one two]",
+                               Pseudolocalizer::Method::kAccent));
+    EXPECT_TRUE(compoundHelper("Copy from ", "{path1}", " to {path2}",
+                               "[Çöþý ƒŕöḿ »{path1}« ţö »{path2}« one two three]",
+                               Pseudolocalizer::Method::kAccent));
+}
+
+TEST(PseudolocalizerTest, ICUBidi) {
+    // Single-fragment messages
+    EXPECT_TRUE(simpleHelper("{placeholder}",
+                             "\xe2\x80\x8f\xE2\x80\xae{placeholder}\xE2\x80\xac\xe2\x80\x8f",
+                             Pseudolocalizer::Method::kBidi));
+    EXPECT_TRUE(simpleHelper(
+            "{COUNT, plural, one {one} other {other}}",
+            "{COUNT, plural, " \
+                    "one {\xe2\x80\x8f\xE2\x80\xaeone\xE2\x80\xac\xe2\x80\x8f} " \
+                    "other {\xe2\x80\x8f\xE2\x80\xaeother\xE2\x80\xac\xe2\x80\x8f}}",
+            Pseudolocalizer::Method::kBidi));
+}
+
+TEST(PseudolocalizerTest, Escaping) {
+    // Single-fragment messages
+    EXPECT_TRUE(simpleHelper("'{USER'} is offline",
+                             "['{ÛŠÉŔ'} îš öƒƒļîñé one two three]",
+                             Pseudolocalizer::Method::kAccent));
+
+    // Multi-fragment messages
+    EXPECT_TRUE(compoundHelper("'{USER}", " ", "''is offline",
+                               "['{ÛŠÉŔ} ''îš öƒƒļîñé one two three]",
+                               Pseudolocalizer::Method::kAccent));
+}
+
+TEST(PseudolocalizerTest, PluralsAndSelects) {
+    EXPECT_TRUE(simpleHelper(
+            "{COUNT, plural, one {Delete a file} other {Delete {COUNT} files}}",
+            "[{COUNT, plural, one {Ðéļéţé å ƒîļé one two} " \
+                     "other {Ðéļéţé »{COUNT}« ƒîļéš one two}}]",
+            Pseudolocalizer::Method::kAccent));
+
+    EXPECT_TRUE(simpleHelper(
+            "Distance is {COUNT, plural, one {# mile} other {# miles}}",
+            "[Ðîšţåñçé îš {COUNT, plural, one {# ḿîļé one two} " \
+                                 "other {# ḿîļéš one two}}]",
+            Pseudolocalizer::Method::kAccent));
+
+    EXPECT_TRUE(simpleHelper(
+            "{1, select, female {{1} added you} " \
+                    "male {{1} added you} other {{1} added you}}",
+            "[{1, select, female {»{1}« åððéð ýöû one two} " \
+                    "male {»{1}« åððéð ýöû one two} other {»{1}« åððéð ýöû one two}}]",
+            Pseudolocalizer::Method::kAccent));
+
+    EXPECT_TRUE(compoundHelper(
+            "{COUNT, plural, one {Delete a file} " \
+                    "other {Delete ", "{COUNT}", " files}}",
+            "[{COUNT, plural, one {Ðéļéţé å ƒîļé one two} " \
+                    "other {Ðéļéţé »{COUNT}« ƒîļéš one two}}]",
+            Pseudolocalizer::Method::kAccent));
+}
+
+TEST(PseudolocalizerTest, NestedICU) {
+    EXPECT_TRUE(simpleHelper(
+            "{person, select, " \
+                "female {" \
+                    "{num_circles, plural," \
+                        "=0{{person} didn't add you to any of her circles.}" \
+                        "=1{{person} added you to one of her circles.}" \
+                        "other{{person} added you to her # circles.}}}" \
+                "male {" \
+                    "{num_circles, plural," \
+                        "=0{{person} didn't add you to any of his circles.}" \
+                        "=1{{person} added you to one of his circles.}" \
+                        "other{{person} added you to his # circles.}}}" \
+                "other {" \
+                    "{num_circles, plural," \
+                        "=0{{person} didn't add you to any of their circles.}" \
+                        "=1{{person} added you to one of their circles.}" \
+                        "other{{person} added you to their # circles.}}}}",
+            "[{person, select, " \
+                "female {" \
+                    "{num_circles, plural," \
+                        "=0{»{person}« ðîðñ'ţ åðð ýöû ţö åñý öƒ ĥéŕ çîŕçļéš." \
+                            " one two three four five}" \
+                        "=1{»{person}« åððéð ýöû ţö öñé öƒ ĥéŕ çîŕçļéš." \
+                            " one two three four}" \
+                        "other{»{person}« åððéð ýöû ţö ĥéŕ # çîŕçļéš." \
+                            " one two three four}}}" \
+                "male {" \
+                    "{num_circles, plural," \
+                        "=0{»{person}« ðîðñ'ţ åðð ýöû ţö åñý öƒ ĥîš çîŕçļéš." \
+                            " one two three four five}" \
+                        "=1{»{person}« åððéð ýöû ţö öñé öƒ ĥîš çîŕçļéš." \
+                            " one two three four}" \
+                        "other{»{person}« åððéð ýöû ţö ĥîš # çîŕçļéš." \
+                            " one two three four}}}" \
+                "other {{num_circles, plural," \
+                    "=0{»{person}« ðîðñ'ţ åðð ýöû ţö åñý öƒ ţĥéîŕ çîŕçļéš." \
+                        " one two three four five}" \
+                    "=1{»{person}« åððéð ýöû ţö öñé öƒ ţĥéîŕ çîŕçļéš." \
+                        " one two three four}" \
+                    "other{»{person}« åððéð ýöû ţö ţĥéîŕ # çîŕçļéš." \
+                        " one two three four}}}}]",
+            Pseudolocalizer::Method::kAccent));
+}
+
+TEST(PseudolocalizerTest, RedefineMethod) {
+    Pseudolocalizer pseudo(Pseudolocalizer::Method::kAccent);
+    std::u16string result = pseudo.text(u"Hello, ");
+    pseudo.setMethod(Pseudolocalizer::Method::kNone);
+    result += pseudo.text(u"world!");
+    ASSERT_EQ(StringPiece("Ĥéļļö, world!"), util::utf16ToUtf8(result));
+}
+
+} // namespace aapt
diff --git a/tools/aapt2/flatten/TableFlattener.cpp b/tools/aapt2/flatten/TableFlattener.cpp
index a2f53e1..26d7c2c 100644
--- a/tools/aapt2/flatten/TableFlattener.cpp
+++ b/tools/aapt2/flatten/TableFlattener.cpp
@@ -113,8 +113,7 @@
     bool mUseExtendedChunks;
 
     size_t mEntryCount = 0;
-    Maybe<uint32_t> mParentIdent;
-    Maybe<ResourceNameRef> mParentName;
+    const Reference* mParent = nullptr;
 
     MapFlattenVisitor(SymbolWriter* symbols, FlatEntry* entry, BigBuffer* buffer,
                       StringPool* sourcePool, StringPool* commentPool,
@@ -227,13 +226,8 @@
 
     void visit(Style* style) override {
         if (style->parent) {
-            bool privateRef = style->parent.value().privateReference && mUseExtendedChunks;
-            if (!style->parent.value().id || privateRef) {
-                assert(style->parent.value().name && "reference must have a name");
-                mParentName = style->parent.value().name;
-            } else {
-                mParentIdent = style->parent.value().id.value().id;
-            }
+            // Parents are treated a bit differently, so record the existence and move on.
+            mParent = &style->parent.value();
         }
 
         // Sort the style.
@@ -427,11 +421,16 @@
                                       mOptions.useExtendedChunks);
             entry->value->accept(&visitor);
             outEntry->count = util::hostToDevice32(visitor.mEntryCount);
-            if (visitor.mParentName) {
-                mSymbols->addSymbol(visitor.mParentName.value(),
-                                    beforeEntry + offsetof(ResTable_entry_ext, parent));
-            } else if (visitor.mParentIdent) {
-                outEntry->parent.ident = util::hostToDevice32(visitor.mParentIdent.value());
+            if (visitor.mParent) {
+                const bool forceSymbol = visitor.mParent->privateReference &&
+                        mOptions.useExtendedChunks;
+                if (!visitor.mParent->id || forceSymbol) {
+                    assert(visitor.mParent->name && "reference must have a name");
+                    mSymbols->addSymbol(*visitor.mParent,
+                                        beforeEntry + offsetof(ResTable_entry_ext, parent));
+                } else {
+                    outEntry->parent.ident = util::hostToDevice32(visitor.mParent->id.value().id);
+                }
             }
         }
         return true;
diff --git a/tools/aapt2/java/ProguardRules.cpp b/tools/aapt2/java/ProguardRules.cpp
index c096854..c610bb0 100644
--- a/tools/aapt2/java/ProguardRules.cpp
+++ b/tools/aapt2/java/ProguardRules.cpp
@@ -227,14 +227,14 @@
 bool writeKeepSet(std::ostream* out, const KeepSet& keepSet) {
     for (const auto& entry : keepSet.mKeepSet) {
         for (const Source& source : entry.second) {
-            *out << "// Referenced at " << source << "\n";
+            *out << "# Referenced at " << source << "\n";
         }
         *out << "-keep class " << entry.first << " { <init>(...); }\n" << std::endl;
     }
 
     for (const auto& entry : keepSet.mKeepMethodSet) {
         for (const Source& source : entry.second) {
-            *out << "// Referenced at " << source << "\n";
+            *out << "# Referenced at " << source << "\n";
         }
         *out << "-keepclassmembers class * { *** " << entry.first << "(...); }\n" << std::endl;
     }
diff --git a/tools/aapt2/test/Builders.h b/tools/aapt2/test/Builders.h
index f8e3d03..93a11b9 100644
--- a/tools/aapt2/test/Builders.h
+++ b/tools/aapt2/test/Builders.h
@@ -68,6 +68,12 @@
         return addValue(name, id, util::make_unique<String>(mTable->stringPool.makeRef(str)));
     }
 
+    ResourceTableBuilder& addString(const StringPiece16& name, const ResourceId id,
+                                    const ConfigDescription& config, const StringPiece16& str) {
+        return addValue(name, id, config,
+                        util::make_unique<String>(mTable->stringPool.makeRef(str)));
+    }
+
     ResourceTableBuilder& addFileReference(const StringPiece16& name, const StringPiece16& path) {
         return addFileReference(name, {}, path);
     }
diff --git a/tools/aapt2/unflatten/BinaryResourceParser.cpp b/tools/aapt2/unflatten/BinaryResourceParser.cpp
index 21e476f..6b7a63cf 100644
--- a/tools/aapt2/unflatten/BinaryResourceParser.cpp
+++ b/tools/aapt2/unflatten/BinaryResourceParser.cpp
@@ -585,6 +585,13 @@
                 source.path = path.toString();
             }
             source.line = util::deviceToHost32(sourceBlock->line);
+
+            if (Style* style = valueCast<Style>(resourceValue.get())) {
+                // The parent's source is the same as the resource itself, set it here.
+                if (style->parent) {
+                    style->parent.value().setSource(source);
+                }
+            }
         }
 
         StringPiece16 comment = util::getString(mSourcePool,
diff --git a/tools/aapt2/util/ImmutableMap.h b/tools/aapt2/util/ImmutableMap.h
new file mode 100644
index 0000000..b1f9e9d
--- /dev/null
+++ b/tools/aapt2/util/ImmutableMap.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AAPT_UTIL_IMMUTABLEMAP_H
+#define AAPT_UTIL_IMMUTABLEMAP_H
+
+#include "util/TypeTraits.h"
+
+#include <utility>
+#include <vector>
+
+namespace aapt {
+
+template <typename TKey, typename TValue>
+class ImmutableMap {
+    static_assert(is_comparable<TKey, TKey>::value, "key is not comparable");
+
+private:
+    std::vector<std::pair<TKey, TValue>> mData;
+
+    explicit ImmutableMap(std::vector<std::pair<TKey, TValue>> data) : mData(std::move(data)) {
+    }
+
+public:
+    using const_iterator = typename decltype(mData)::const_iterator;
+
+    ImmutableMap(ImmutableMap&&) = default;
+    ImmutableMap& operator=(ImmutableMap&&) = default;
+
+    ImmutableMap(const ImmutableMap&) = delete;
+    ImmutableMap& operator=(const ImmutableMap&) = delete;
+
+    static ImmutableMap<TKey, TValue> createPreSorted(
+            std::initializer_list<std::pair<TKey, TValue>> list) {
+        return ImmutableMap(std::vector<std::pair<TKey, TValue>>(list.begin(), list.end()));
+    }
+
+    static ImmutableMap<TKey, TValue> createAndSort(
+            std::initializer_list<std::pair<TKey, TValue>> list) {
+        std::vector<std::pair<TKey, TValue>> data(list.begin(), list.end());
+        std::sort(data.begin(), data.end());
+        return ImmutableMap(std::move(data));
+    }
+
+    template <typename TKey2,
+              typename = typename std::enable_if<is_comparable<TKey, TKey2>::value>::type>
+    const_iterator find(const TKey2& key) const {
+        auto cmp = [](const std::pair<TKey, TValue>& candidate, const TKey2& target) -> bool {
+            return candidate.first < target;
+        };
+
+        const_iterator endIter = end();
+        auto iter = std::lower_bound(mData.begin(), endIter, key, cmp);
+        if (iter == endIter || iter->first == key) {
+            return iter;
+        }
+        return endIter;
+    }
+
+    const_iterator begin() const {
+        return mData.begin();
+    }
+
+    const_iterator end() const {
+        return mData.end();
+    }
+};
+
+} // namespace aapt
+
+#endif /* AAPT_UTIL_IMMUTABLEMAP_H */
diff --git a/tools/aapt2/util/TypeTraits.h b/tools/aapt2/util/TypeTraits.h
new file mode 100644
index 0000000..76c13d6
--- /dev/null
+++ b/tools/aapt2/util/TypeTraits.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AAPT_UTIL_TYPETRAITS_H
+#define AAPT_UTIL_TYPETRAITS_H
+
+#include <type_traits>
+
+namespace aapt {
+
+#define DEFINE_HAS_BINARY_OP_TRAIT(name, op) \
+    template <typename T, typename U> \
+    struct name { \
+        template <typename V, typename W> \
+        static constexpr decltype(std::declval<V>() op std::declval<W>(), bool()) test(int) { \
+        return true; \
+    } \
+    template <typename V, typename W> \
+    static constexpr bool test(...) { \
+        return false; \
+    } \
+    static constexpr bool value = test<T, U>(int()); \
+}
+
+DEFINE_HAS_BINARY_OP_TRAIT(has_eq_op, ==);
+DEFINE_HAS_BINARY_OP_TRAIT(has_lt_op, <);
+
+/**
+ * Type trait that checks if two types can be equated (==) and compared (<).
+ */
+template <typename T, typename U>
+struct is_comparable {
+    static constexpr bool value = has_eq_op<T, U>::value && has_lt_op<T, U>::value;
+};
+
+} // namespace aapt
+
+#endif /* AAPT_UTIL_TYPETRAITS_H */
diff --git a/tools/layoutlib/bridge/src/android/os/ServiceManager.java b/tools/layoutlib/bridge/src/android/os/ServiceManager.java
index 6a68ee2..549074d 100644
--- a/tools/layoutlib/bridge/src/android/os/ServiceManager.java
+++ b/tools/layoutlib/bridge/src/android/os/ServiceManager.java
@@ -51,8 +51,10 @@
 
     /**
      * Return a list of all currently running services.
+     * @return an array of all currently running services, or <code>null</code> in
+     * case of an exception
      */
-    public static String[] listServices() throws RemoteException {
+    public static String[] listServices() {
         // actual implementation returns null sometimes, so it's ok
         // to return null instead of an empty list.
         return null;
diff --git a/tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java b/tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java
index 40437fa..01ee18b 100644
--- a/tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java
+++ b/tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java
@@ -76,7 +76,7 @@
     @Override
     public void addAppToken(int arg0, IApplicationToken arg1, int arg2, int arg3, int arg4,
             boolean arg5, boolean arg6, int arg7, int arg8, boolean arg9, boolean arg10,
-            Rect arg11, Configuration arg12, boolean arg13) throws RemoteException {
+            Rect arg11, Configuration arg12, boolean arg13, boolean arg14) throws RemoteException {
         // TODO Auto-generated method stub
     }
 
@@ -543,6 +543,11 @@
     }
 
     @Override
-    public void registerDockDividerVisibilityListener(IDockDividerVisibilityListener listener) {
+    public void registerDockedStackListener(IDockedStackListener listener) throws RemoteException {
+    }
+
+    @Override
+    public void setResizeDimLayer(boolean visible, int targetStackId, float alpha)
+            throws RemoteException {
     }
 }
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
index 683c4aa..c8e3d03 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -183,7 +183,7 @@
      */
     private static LayoutLog sCurrentLog = sDefaultLog;
 
-    private static final int LAST_SUPPORTED_FEATURE = Features.CHOREOGRAPHER;
+    private static final int LAST_SUPPORTED_FEATURE = Features.THEME_PREVIEW_NAVIGATION_BAR;
 
     @Override
     public int getApiLevel() {
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePackageManager.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePackageManager.java
index a2fad13..4625de2 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePackageManager.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePackageManager.java
@@ -34,7 +34,6 @@
 import android.content.pm.InstrumentationInfo;
 import android.content.pm.IntentFilterVerificationInfo;
 import android.content.pm.KeySet;
-import android.content.pm.ManifestDigest;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageInstaller;
 import android.content.pm.PackageItemInfo;
@@ -98,7 +97,22 @@
     }
 
     @Override
-    public int getPackageUid(String packageName, int userHandle) throws NameNotFoundException {
+    public int[] getPackageGids(String packageName, int flags) throws NameNotFoundException {
+        return new int[0];
+    }
+
+    @Override
+    public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
+        return 0;
+    }
+
+    @Override
+    public int getPackageUidAsUser(String packageName, int userHandle) throws NameNotFoundException {
+        return 0;
+    }
+
+    @Override
+    public int getPackageUidAsUser(String packageName, int flags, int userHandle) throws NameNotFoundException {
         return 0;
     }
 
@@ -165,7 +179,7 @@
     }
 
     @Override
-    public List<PackageInfo> getInstalledPackages(int flags, int userId) {
+    public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) {
         return null;
     }
 
@@ -329,7 +343,7 @@
     }
 
     @Override
-    public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags, int userId) {
+    public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) {
         return null;
     }
 
@@ -522,7 +536,7 @@
     @Override
     public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer,
             int flags, String installerPackageName, Uri verificationURI,
-            ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {
+            ContainerEncryptionParams encryptionParams) {
     }
 
     @Override
@@ -544,7 +558,7 @@
     @Override
     public void installPackageWithVerification(Uri packageURI, PackageInstallObserver observer,
             int flags, String installerPackageName, Uri verificationURI,
-            ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {
+            ContainerEncryptionParams encryptionParams) {
     }
 
     @Override
@@ -579,12 +593,12 @@
     }
 
     @Override
-    public int getIntentVerificationStatus(String packageName, int userId) {
+    public int getIntentVerificationStatusAsUser(String packageName, int userId) {
         return 0;
     }
 
     @Override
-    public boolean updateIntentVerificationStatus(String packageName, int status, int userId) {
+    public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) {
         return false;
     }
 
@@ -599,12 +613,12 @@
     }
 
     @Override
-    public String getDefaultBrowserPackageName(int userId) {
+    public String getDefaultBrowserPackageNameAsUser(int userId) {
         return null;
     }
 
     @Override
-    public boolean setDefaultBrowserPackageName(String packageName, int userId) {
+    public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) {
         return false;
     }
 
@@ -644,7 +658,7 @@
     }
 
     @Override
-    public void getPackageSizeInfo(String packageName, int userHandle,
+    public void getPackageSizeInfoAsUser(String packageName, int userHandle,
             IPackageStatsObserver observer) {
     }
 
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java
index 9c89bfe..dfbc69b 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java
@@ -19,9 +19,6 @@
 import com.android.layoutlib.bridge.android.BridgeContext;
 import com.android.resources.Density;
 
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.util.AttributeSet;
 import android.util.DisplayMetrics;
 import android.view.View;
 import android.widget.LinearLayout;
@@ -41,29 +38,18 @@
     private static final int WIDTH_DEFAULT = 36;
     private static final int WIDTH_SW360 = 40;
     private static final int WIDTH_SW600 = 48;
-    private static final String LAYOUT_XML = "/bars/navigation_bar.xml";
+    protected static final String LAYOUT_XML = "/bars/navigation_bar.xml";
     private static final String LAYOUT_600DP_XML = "/bars/navigation_bar600dp.xml";
 
-
-    /**
-     * Constructor to be used when creating the {@link NavigationBar} as a regular control.
-     * This is currently used by the theme editor.
-     */
-    @SuppressWarnings("unused")
-    public NavigationBar(Context context, AttributeSet attrs) {
-        this((BridgeContext) context,
-                Density.getEnum(((BridgeContext) context).getMetrics().densityDpi),
-                LinearLayout.HORIZONTAL, // In this mode, it doesn't need to be render vertically
-                ((BridgeContext) context).getConfiguration().getLayoutDirection() ==
-                        View.LAYOUT_DIRECTION_RTL,
-                (context.getApplicationInfo().flags & ApplicationInfo.FLAG_SUPPORTS_RTL) != 0,
-                0);
+    public NavigationBar(BridgeContext context, Density density, int orientation, boolean isRtl,
+      boolean rtlEnabled, int simulatedPlatformVersion) {
+        this(context, density, orientation, isRtl, rtlEnabled, simulatedPlatformVersion,
+          getShortestWidth(context)>= 600 ? LAYOUT_600DP_XML : LAYOUT_XML);
     }
 
-    public NavigationBar(BridgeContext context, Density density, int orientation, boolean isRtl,
-            boolean rtlEnabled, int simulatedPlatformVersion) {
-        super(context, orientation, getShortestWidth(context)>= 600 ? LAYOUT_600DP_XML : LAYOUT_XML,
-                "navigation_bar.xml", simulatedPlatformVersion);
+    protected NavigationBar(BridgeContext context, Density density, int orientation, boolean isRtl,
+      boolean rtlEnabled, int simulatedPlatformVersion, String layoutPath) {
+        super(context, orientation, layoutPath, "navigation_bar.xml", simulatedPlatformVersion);
 
         int color = getBarColor(ATTR_COLOR, ATTR_TRANSLUCENT);
         setBackgroundColor(color == 0 ? 0xFF000000 : color);
@@ -117,7 +103,7 @@
         view.setLayoutParams(layoutParams);
     }
 
-    private static int getSidePadding(float sw) {
+    protected int getSidePadding(float sw) {
         if (sw >= 400) {
             return PADDING_WIDTH_SW400;
         }
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ThemePreviewNavigationBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ThemePreviewNavigationBar.java
new file mode 100644
index 0000000..0435280
--- /dev/null
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ThemePreviewNavigationBar.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.layoutlib.bridge.bars;
+
+import com.android.layoutlib.bridge.android.BridgeContext;
+import com.android.resources.Density;
+
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.LinearLayout;
+
+/**
+ * Navigation Bar for the Theme Editor preview.
+ *
+ * For small bars, it is identical to {@link NavigationBar}.
+ * But wide bars from {@link NavigationBar} are too wide for the Theme Editor preview.
+ * To solve that problem, {@link ThemePreviewNavigationBar} use the layout for small bars,
+ * and have no padding on the sides. That way, they have a similar look as the true ones,
+ * and they fit in the Theme Editor preview.
+ */
+public class ThemePreviewNavigationBar extends NavigationBar {
+    private static final int PADDING_WIDTH_SW600 = 0;
+
+    @SuppressWarnings("unused")
+    public ThemePreviewNavigationBar(Context context, AttributeSet attrs) {
+        super((BridgeContext) context,
+                Density.getEnum(((BridgeContext) context).getMetrics().densityDpi),
+                LinearLayout.HORIZONTAL, // In this mode, it doesn't need to be render vertically
+                ((BridgeContext) context).getConfiguration().getLayoutDirection() ==
+                        View.LAYOUT_DIRECTION_RTL,
+                (context.getApplicationInfo().flags & ApplicationInfo.FLAG_SUPPORTS_RTL) != 0,
+                0, LAYOUT_XML);
+    }
+
+    @Override
+    protected int getSidePadding(float sw) {
+        if (sw >= 600) {
+            return PADDING_WIDTH_SW600;
+        }
+        return super.getSidePadding(sw);
+    }
+}